-
Notifications
You must be signed in to change notification settings - Fork 0
/
woving.js
76 lines (74 loc) · 2.96 KB
/
woving.js
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
// Generated automatically by nearley, version 2.20.1
// http://github.com/Hardmath123/nearley
(function () {
function id(x) { return x[0]; }
const ast = (type, op, l, r, v) => {
return {
type: type,
op: op,
left: l,
right: r,
}
}
const numberAst = (number) => {
return {
type: 'number',
op: null,
left: number,
right: null,
}
}
var grammar = {
Lexer: undefined,
ParserRules: [
{"name": "expression", "symbols": ["expression", "join", "expression"], "postprocess":
data => ast('join', null, data[0], data[2])
},
{"name": "expression", "symbols": ["postfix"], "postprocess": id},
{"name": "join", "symbols": [{"literal":" "}]},
{"name": "join", "symbols": [{"literal":"+"}]},
{"name": "postfix$subexpression$1", "symbols": [{"literal":"!"}]},
{"name": "postfix$subexpression$1", "symbols": [{"literal":"|"}]},
{"name": "postfix", "symbols": ["postfix", "postfix$subexpression$1"], "postprocess":
data => ast('postfix', data[1][0], data[0], null)
},
{"name": "postfix", "symbols": ["binary"], "postprocess": id},
{"name": "binary", "symbols": ["binary", {"literal":":"}, "seq"], "postprocess":
data => ast('binary', data[1], data[0], data[2])
},
{"name": "binary", "symbols": ["seq"], "postprocess": id},
{"name": "seq$subexpression$1", "symbols": [{"literal":"1"}]},
{"name": "seq$subexpression$1", "symbols": [{"literal":"2"}]},
{"name": "seq$subexpression$1", "symbols": [{"literal":"3"}]},
{"name": "seq$subexpression$1", "symbols": [{"literal":"4"}]},
{"name": "seq", "symbols": ["seq$subexpression$1"], "postprocess":
data => Number(data[0])
},
{"name": "seq$subexpression$2", "symbols": [{"literal":"1"}]},
{"name": "seq$subexpression$2", "symbols": [{"literal":"2"}]},
{"name": "seq$subexpression$2", "symbols": [{"literal":"3"}]},
{"name": "seq$subexpression$2", "symbols": [{"literal":"4"}]},
{"name": "seq", "symbols": ["seq$subexpression$2", "seq"], "postprocess":
data => ast('join', null, numberAst(data[0]), data[1], null)
},
{"name": "seq", "symbols": ["groups", "seq"], "postprocess":
data => ast('join', null, data[0], data[1])
},
{"name": "seq", "symbols": ["groups"], "postprocess": id},
{"name": "groups", "symbols": ["step_array"], "postprocess": id},
{"name": "groups", "symbols": ["group"], "postprocess": id},
{"name": "step_array", "symbols": [{"literal":"/"}, "expression", {"literal":"/"}], "postprocess":
data => ast('step_array', null, data[1], null)
},
{"name": "group", "symbols": [{"literal":"["}, "expression", {"literal":"]"}], "postprocess":
data => data[1]
}
]
, ParserStart: "expression"
}
if (typeof module !== 'undefined'&& typeof module.exports !== 'undefined') {
module.exports = grammar;
} else {
window.grammar = grammar;
}
})();