forked from kmonad/kmonad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParsing.hs
57 lines (40 loc) · 1.27 KB
/
Parsing.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
-- | A collection of general parsing definitions
module KMonad.Parsing
( Parser
, ParserT
, ParseError(..)
, sc
, hsc
, lex
, hlex
, module Text.Megaparsec
, module Text.Megaparsec.Char
)
where
import KMonad.Prelude
import Text.Megaparsec hiding (ParseError)
import Text.Megaparsec.Char
import qualified Text.Megaparsec.Char.Lexer as X
--------------------------------------------------------------------------------
-- | Parsec type specified down to Void Text
type Parser a = Parsec Void Text a
type ParserT m a = ParsecT Void Text m a
-- | Parsec parse errors under Void Text with an Exception instance
newtype ParseError = ParseError { _parseError :: ParseErrorBundle Text Void}
deriving Eq
instance Show ParseError where
show (ParseError e) = "Parse error at " <> errorBundlePretty e
instance Exception ParseError
--------------------------------------------------------------------------------
-- | Horizontal space consumption
hsc :: Parser ()
hsc = X.space space1 empty empty
-- | Horizontal space lexeme
hlex :: Parser a -> Parser a
hlex = X.lexeme hsc
-- | Full space consumption
sc :: Parser ()
sc = X.space space1 (X.skipLineComment ";;") (X.skipBlockComment "#|" "|#")
-- | Full space lexeme
lex :: Parser a -> Parser a
lex = X.lexeme sc