-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.ne
50 lines (40 loc) · 1.07 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
@{%
require("array-flat-polyfill")
const {
postProcessAuthorX,
postProcessLeaf,
postProcessSingleLine,
postProcessNoBody
} = require("./post-processors");
const { makeLexer } = require("./lexer");
const lexer = makeLexer()
%}
@lexer lexer
authorx -> "<" invocation _ "{" _ (authorx _):+ %closeBracket {%
postProcessAuthorX
%}
authorx -> "<" invocation _ %leaf {%
postProcessLeaf
%}
authorx -> "<" invocation _ %singleLineText %newLine {%
postProcessSingleLine
%}
authorx -> "<" invocation _ %newLine {%
postProcessNoBody
%}
authorx -> text {% id %}
invocation -> %identifier argList:? {%
([identifier, argList]) => argList ? ({ identifier, argList }) : ({ identifier })
%}
argList -> "(" args terminalArg {%
([_, args, terminalArg]) => args.length > 0 ? args.concat([terminalArg]) : [terminalArg]
%}
args -> arg:* {% id %}
arg -> %argument "," %ws {% id %}
terminalArg -> %argument ")" {% id %}
_ -> %ws:* {%
([ws]) => ws.length > 0 ? ({ type: "whitespace", children: ws }) : null
%}
text -> (%words) {%
([[text]]) => ({...text, type: "text"})
%}