-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcfgparser.gmr
More file actions
78 lines (61 loc) · 3.82 KB
/
cfgparser.gmr
File metadata and controls
78 lines (61 loc) · 3.82 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
%precode {
import Grammar
import Data.Maybe
}
%operators "::" "|" "*" "+" "?"
%linecomments "#"
%blockcomments "#[" "]#"
%separateidentitycase
%parsermap { (languageDefsParser:) }
%token
left { TokenCustom "Directive" "left" }
right { TokenCustom "Directive" "right" }
nonAssoc { TokenCustom "Directive" "nonassoc" }
prec { TokenCustom "Directive" "prec" }
token { TokenCustom "Directive" "token" }
export { TokenCustom "Directive" "export" }
precode { TokenCustom "Directive" "precode" }
operators { TokenCustom "Directive" "operators" }
keywords { TokenCustom "Directive" "keywords" }
lineComments { TokenCustom "Directive" "linecomments" }
blockComments { TokenCustom "Directive" "blockcomments" }
separateIden { TokenCustom "Directive" "separateidentitycase" }
keepSpaces { TokenCustom "Directive" "keepwhitespaces" }
keepComments { TokenCustom "Directive" "keepcomments" }
parserMap { TokenCustom "Directive" "parsermap" }
empty { TokenCustom "Directive" "empty" }
codeBlock { TokenCustom "CodeBlock" $$ }
FullDef :: Export? PreCode? ScannerDef* Grammar { (v1, fromMaybe "" v2, v3, v4) }
Export :: export codeBlock { v2 }
PreCode :: precode codeBlock { v2 }
Grammar :: TokenDefs? PrecDef* Rule+ { Grammar (fromMaybe [] v1) v2 v3 }
ScannerDef :: operators stringLit+ { ("ops", v2) }
| keywords stringLit+ { ("kwds", v2) }
| lineComments stringLit { ("line", [v2]) }
| blockComments stringLit stringLit { ("block", [v2, v3]) }
| separateIden { ("sepiden", []) }
| keepSpaces { ("keepspace", []) }
| keepComments { ("keepcmts", []) }
| parserMap codeBlock { ("parser", [v2]) }
TokenDefs :: token TokenMapping+ { v2 }
TokenMapping :: identifier codeBlock { TokenDef v1 v2 }
| stringLit codeBlock { TokenDef v1 v2 }
PrecDef :: Prec Token+ { PrecLevel v1 v2 }
Token :: stringLit { v1 }
| identifier { v1 }
Prec :: left { LeftAssoc }
| right { RightAssoc }
| nonAssoc { NonAssoc }
Rule :: upperIdentifier '::' RuleDef+('|') { Rule v1 v3 }
RuleDef :: empty codeBlock { RuleProduction [] v2 Nothing }
| RuleToken+ codeBlock { RuleProduction v1 v2 Nothing }
| RuleToken+ prec stringLit codeBlock { RuleProduction v1 v4 $ Just v3 }
| RuleToken+ prec identifier codeBlock { RuleProduction v1 v4 $ Just v3 }
RuleToken :: RuleTokenType { RuleToken v1 RuleTokenModifierNormal }
| RuleTokenType '+' ModSeperator? { RuleToken v1 $ RuleTokenModifierSome v3 }
| RuleTokenType '*' ModSeperator? { RuleToken v1 $ RuleTokenModifierMany v3 }
| RuleTokenType '?' { RuleToken v1 RuleTokenModifierOptional }
ModSeperator :: "(" RuleTokenType ")" { v2 }
RuleTokenType :: upperIdentifier { RuleNonTerminal v1 }
| stringLit { RuleTerminal v1 }
| identifier { RuleTerminal v1 }