-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.ne
61 lines (43 loc) · 1.14 KB
/
grammar.ne
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
@{%
const moo = require('moo')
let lexer = moo.compile({
space: {match: /\s+/, lineBreaks: true},
number: /-?(?:[0-9]|[1-9][0-9]+)(?:\.[0-9]+)?(?:[eE][-+]?[0-9]+)?\b/,
string: /"(?:\\["bfnrt\/\\]|\\u[a-fA-F0-9]{4}|[^"\\])*"/,
'{': '{',
'}': '}',
'[': '[',
']': ']',
',': ',',
':': ':',
true: 'true',
false: 'false',
null: 'null',
})
%}
@lexer lexer
acf -> "\"AppState\"" _ acfObject _ {% function(d){
return {
"AppState": d[2]
}
}%}
tabs -> "\t\t" {% function(d) { return null; } %}
acfObject -> "{" (_ acfPair):* _ "}" {% extractObject %}
acfPair -> key tabs string {% function(d) { return [d[0], d[2]]; } %}
| key _ acfObject {% function(d) { return [d[0], d[2]]; } %}
acfValue -> string {% id %} | acfObject
string -> %string {% function(d) { return JSON.parse(d[0].value) } %}
key -> string {% id %}
_ -> null | %space {% function(d) { return null; } %}
@{%
function extractPair(kv, output) {
if(kv[1]) { output[kv[1][0]] = kv[1][1]; }
}
function extractObject(d) {
let output = {};
for (let i of d[1]) {
extractPair(i, output);
}
return output;
}
%}