-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgrammar.ne
65 lines (51 loc) · 1.99 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
62
63
64
65
@builtin "whitespace.ne"
@builtin "string.ne"
instruction ->
entity {% ([a]) => ({ type: 'insert', left: a }) %}
| entity __ entity __ entity {% ([a,,b,,c]) => ({ type: 'connect', left: a, relationship: b, right: c }) %}
entity ->
entity_name {% ([d]) => ({ name: d }) %}
| entity_name _ ":" _ entity_id {% ([a,,,,b]) => ({ name: a, mergeOn: 'id', id: b }) %}
| entity_name _ ":" _ field_name "=" entity_id {% ([a,,,,b,,c]) => ({ name: a, mergeOn: b, id: c }) %}
| entity_name _ properties {% ([a,,b]) => ({ name: a, properties: b }) %}
| entity_name _ ":" _ entity_id _ properties {% ([a,,,,b,,c]) => ({ name: a, mergeOn: 'id', id: b, properties: c }) %}
| entity_name _ ":" _ field_name "=" entity_id _ properties {% ([a,,,,b,,c,,d]) => ({ name: a, mergeOn: b, id: c, properties: d }) %}
field_name ->
sqstring {% id %}
| dqstring {% id %}
| alnum_word {% id %}
entity_id ->
sqstring {% id %}
| dqstring {% id %}
| alnum_word {% id %}
entity_name ->
sqstring {% id %}
| dqstring {% id %}
| alnum_word {% id %}
properties ->
"(" _ property_list _ ")" {% ([,,p]) => p.reduce((a, cv) => { a[cv[0]] = [cv[1], cv[2], cv[3]]; return a; }, {}) %}
property_list ->
property
| property _ "," _ property_list {% ([a,,,,b]) => [a].concat(b) %}
property ->
property_name _ ":" _ property_value {% ([a,,,,b]) => [a, '=', b] %}
| property_name _ property_operator _ property_value {% ([a,,b,,c]) => [a, b, c, 0] %}
| property_name _ "(" _ property_default _ ")" _ property_operator _ property_value {% ([a,,,,b,,,,c,,d]) => [a, c, d, b] %}
property_operator ->
[-+/*] "=" {% v => v.join('') %}
property_name ->
alnum_word {% id %}
| dqstring {% id %}
| sqstring {% id %}
property_value ->
alnum_word {% id %}
| dqstring {% id %}
| sqstring {% id %}
property_default ->
alnum_word {% id %}
| dqstring {% id %}
| sqstring {% id %}
word ->
[^ \t]:+ {% function(d) {return d[0].join(""); } %}
alnum_word ->
[-_A-Za-z0-9.,]:+ {% function(d) {return d[0].join(""); } %}