Repository navigation
Expand file tree
/
Copy pathParser.hs
More file actions
54 lines (45 loc) · 2.2 KB
/
Copy pathParser.hs
File metadata and controls
54 lines (45 loc) · 2.2 KB
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
module Parser where
import Text.Parsec
import qualified Text.Parsec.Token as T
import Text.Parsec.Language (emptyDef)
import Text.Parsec.Expr
import AST
javadef = emptyDef{T.commentStart = "",
T.commentEnd = "",
T.commentLine = "//",
T.identStart = letter,
T.identLetter = letter <|> alphaNum <|> char '_',
T.reservedNames = ["abstract","boolean",
"break", "byte",
"case", "catch",
"char", "class",
"const", "continue",
"debugger", "default",
"delete", "do", "double",
"else", "enum", "export",
"extends", "false", "final",
"finally", "float", "for",
"function", "goto",
"if", "implements", "import",
"in", "instanceof", "int",
"interface", "long", "native",
"new", "null", "package",
"private", "protected", "public",
"return", "short", "static",
"super", "switch", "synchronized",
"this", "throw", "throws", "transient",
"true", "try", "typeof", "var",
"volatile", "void", "while", "with"]}
javaTokenParser = T.makeTokenParser javadef
name = T.identifier javaTokenParser
semiSep = T.semiSep javaTokenParser
commaSep1 = T.commaSep1 javaTokenParser
statements = semiSep statement
statement = varStatement
varStatement = commaSep1 aux
where aux = do
v <- name
r <- option Nothing $ expr >>= return . Just
return (v,r)
-- need to use an expression parser here, built from the parsec machinery
expr = undefined