|
1 | 1 | @{%
|
2 |
| - const moo = require('moo') |
3 |
| - |
4 |
| - let lexer = moo.compile({ |
5 |
| - WS: /[ \t]+/, |
6 |
| - comment: /\/\/.*?$/, |
7 |
| - number: /0|[1-9][0-9]*/, |
8 |
| - string: { match: /"(?:\\["\\]|[^\n"\\])*"/, value: x => x.slice(1, -1) }, |
9 |
| - itemtype: ['Group', 'Number', 'Switch', 'Rollershutter', 'String', 'Dimmer', 'Contact', 'DateTime', 'Color', 'Player', 'Location', 'Call', 'Image'], |
10 |
| - identifier: /[A-Za-z0-9_-]+/, |
11 |
| - lparen: '(', |
12 |
| - rparen: ')', |
13 |
| - colon: ':', |
14 |
| - lbrace: '{', |
15 |
| - rbrace: '}', |
16 |
| - lbracket: '[', |
17 |
| - rbracket: ']', |
18 |
| - lt: '<', |
19 |
| - gt: '>', |
20 |
| - comma: ',', |
21 |
| - equals: '=', |
22 |
| - NL: { match: /\n/, lineBreaks: true }, |
23 |
| - }) |
| 2 | + const moo = require('moo') |
| 3 | + |
| 4 | + let lexer = moo.compile({ |
| 5 | + WS: /[ \t]+/, |
| 6 | + comment: /\/\/.*?$/, |
| 7 | + number: /0|[1-9][0-9]*/, |
| 8 | + string: { match: /"(?:\\["\\]|[^\n"\\])*"/, value: x => x.slice(1, -1) }, |
| 9 | + itemtype: ['Group ', 'Number ', 'Switch ', 'Rollershutter ', 'String ', 'Dimmer ', 'Contact ', 'DateTime ', 'Color ', 'Player ', 'Location ', 'Call ', 'Image '], |
| 10 | + membertype: [':Number', ':Switch', ':Rollershutter', ':Dimmer', ':Contact', ':DateTime'], |
| 11 | + identifier: /[A-Za-z0-9_-]+/, |
| 12 | + lparen: '(', |
| 13 | + rparen: ')', |
| 14 | + colon: ':', |
| 15 | + lbrace: '{', |
| 16 | + rbrace: '}', |
| 17 | + lbracket: '[', |
| 18 | + rbracket: ']', |
| 19 | + lt: '<', |
| 20 | + gt: '>', |
| 21 | + comma: ',', |
| 22 | + equals: '=', |
| 23 | + NL: { match: /\n/, lineBreaks: true }, |
| 24 | + }) |
24 | 25 | %}
|
25 | 26 |
|
26 | 27 | @lexer lexer
|
27 | 28 |
|
28 | 29 |
|
29 | 30 | Main -> _ Items _ {% (d) => d[1] %}
|
30 | 31 | Items -> Item {% (d) => [d[0]] %}
|
31 |
| - | Items _ Item {% (d) => d[0].concat([d[2]]) %} |
32 |
| - |
33 |
| -Item -> Type __ Name Label Icon Groups Tags Metadata |
| 32 | + | Items _ Item {% (d) => d[0].concat([d[2]]) %} |
| 33 | + |
| 34 | +Item -> Type _ Name Label Icon Groups Tags Metadata |
34 | 35 | {% function (d) {
|
35 |
| - return { |
36 |
| - type: d[0][0], |
37 |
| - groupType: d[0][1], |
38 |
| - function: d[0][2], |
39 |
| - name: d[2], |
40 |
| - label: d[3], |
41 |
| - category: d[4], |
42 |
| - groupNames: d[5], |
43 |
| - tags: d[6], |
44 |
| - metadata: d[7] // metadata (and bindings/links) are not part of the API model and should be processed separately |
45 |
| - } |
| 36 | + return { |
| 37 | + type: d[0][0], |
| 38 | + groupType: d[0][1], |
| 39 | + function: d[0][2], |
| 40 | + name: d[2], |
| 41 | + label: d[3], |
| 42 | + category: d[4], |
| 43 | + groupNames: d[5], |
| 44 | + tags: d[6], |
| 45 | + metadata: d[7] // metadata (and bindings/links) are not part of the API model and should be processed separately |
| 46 | + } |
46 | 47 | } %}
|
47 | 48 |
|
48 | 49 | # Type
|
49 | 50 | # basic
|
50 |
| -Type -> %itemtype {% (d) => [d[0].text] %} |
51 |
| - | "Number" ":" %identifier {% (d) => ['Number:' + d[2].text] %} |
52 |
| - | "Group" ":" %itemtype {% (d) => ['Group', d[2].text] %} |
53 |
| - | "Group" ":" %itemtype ":" %identifier AggArgs {% (d) => ['Group', d[2].text, {name: d[4].text, args: d[5]}] %} |
| 51 | +Type -> %itemtype {% (d) => [d[0].text] %} |
| 52 | + | "Number" ":" %identifier %WS {% (d) => ['Number:' + d[2].text] %} |
| 53 | + | "Group" %membertype {% (d) => ['Group', d[1].text.substring(1)] %} |
| 54 | + | "Group" %membertype ":" %identifier AggArgs {% (d) => ['Group', d[1].text.substring(1), {name: d[3].text, args: d[4]}] %} |
54 | 55 | # group function aggregation arguments
|
55 |
| -AggArgs -> null {% (d) => undefined %} |
56 |
| - | "(" %identifier ")" {% (d) => [d[1].text] %} |
57 |
| - | "(" %identifier _ "," _ %identifier ")" {% (d) => [d[1].text, d[5].text] %} |
| 56 | +AggArgs -> null {% (d) => undefined %} |
| 57 | + | "(" %identifier ")" {% (d) => [d[1].text] %} |
| 58 | + | "(" %identifier _ "," _ %identifier ")" {% (d) => [d[1].text, d[5].text] %} |
58 | 59 |
|
59 | 60 | # Name
|
60 |
| -Name -> %identifier {% (d) => d[0].text %} |
| 61 | +Name -> %identifier {% (d) => d[0].text %} |
61 | 62 |
|
62 | 63 | # Label
|
63 |
| -Label -> null {% (d) => undefined %} |
64 |
| - | __ %string {% (d) => d[1].value %} |
| 64 | +Label -> null {% (d) => undefined %} |
| 65 | + | __ %string {% (d) => d[1].value %} |
65 | 66 |
|
66 | 67 | # Icon (category)
|
67 |
| -Icon -> null {% (d) => undefined %} |
68 |
| - | __ "<" _ %identifier _ ">" {% (d) => d[3].text %} |
| 68 | +Icon -> null {% (d) => undefined %} |
| 69 | + | __ "<" _ %identifier _ ">" {% (d) => d[3].text %} |
69 | 70 |
|
70 | 71 | # Groups
|
71 |
| -Groups -> null {% (d) => undefined %} |
72 |
| - | __ "(" GroupList ")" {% (d) => d[2] %} |
73 |
| -GroupList -> _ GroupName _ {% (d) => [d[1]] %} |
74 |
| - | GroupList "," GroupList {% (d) => d[0].concat(d[2]) %} |
75 |
| -GroupName -> %identifier {% (d) => d[0].text %} |
| 72 | +Groups -> null {% (d) => undefined %} |
| 73 | + | __ "(" GroupList ")" {% (d) => d[2] %} |
| 74 | +GroupList -> _ GroupName _ {% (d) => [d[1]] %} |
| 75 | + | GroupList "," GroupList {% (d) => d[0].concat(d[2]) %} |
| 76 | +GroupName -> %identifier {% (d) => d[0].text %} |
76 | 77 |
|
77 | 78 | # Tags
|
78 |
| -Tags -> null {% (d) => undefined %} |
79 |
| - | __ "[" TagList "]" {% (d) => d[2] %} |
80 |
| -TagList -> _ Tag _ {% (d) => [d[1]] %} |
81 |
| - | TagList "," TagList {% (d) => d[0].concat(d[2]) %} |
82 |
| -Tag -> %identifier {% (d) => d[0].text %} |
83 |
| - | %string {% (d) => d[0].value %} |
| 79 | +Tags -> null {% (d) => undefined %} |
| 80 | + | __ "[" TagList "]" {% (d) => d[2] %} |
| 81 | +TagList -> _ Tag _ {% (d) => [d[1]] %} |
| 82 | + | TagList "," TagList {% (d) => d[0].concat(d[2]) %} |
| 83 | +Tag -> %identifier {% (d) => d[0].text %} |
| 84 | + | %string {% (d) => d[0].value %} |
84 | 85 |
|
85 | 86 | # Metadata (+ links, OH1 bindings...)
|
86 |
| -Metadata -> null {% (d) => undefined %} |
87 |
| - | __ "{" MetadataList "}" {% (d) => d[2] %} |
88 |
| -MetadataList -> _ MetadataEntry _ {% (d) => [d[1]] %} |
89 |
| - | MetadataList "," MetadataList {% (d) => d[0].concat(d[2]) %} |
90 |
| - |
91 |
| -MetadataEntry -> MetadataKey _ "=" _ MetadataValue {% (d) => { return { key: d[0], value: d[4] } } %} |
92 |
| -MetadataKey -> %identifier {% (d) => d[0].text %} |
93 |
| -MetadataValue -> %string {% (d) => d[0].value %} |
94 |
| - | %number {% (d) => parseInt(d[0].value) %} |
95 |
| - | %string _ MetadataConfig {% (d) => { return { value: d[0].value, config: d[2] } } %} |
96 |
| - |
97 |
| -MetadataConfig -> "[" MetadataConfigList "]" {% (d) => d[1] %} |
98 |
| -MetadataConfigList -> _ MetadataConfigItem _ {% (d) => [d[1]] %} |
99 |
| - | MetadataConfigList "," MetadataConfigList {% (d) => d[0].concat(d[2]) %} |
100 |
| -MetadataConfigItem -> MetadataConfigKey _ "=" _ MetadataConfigValue {% (d) => { return { key: d[0], value: d[4] } } %} |
101 |
| -MetadataConfigKey -> %identifier {% (d) => d[0].text %} |
102 |
| -MetadataConfigValue -> %string {% (d) => d[0].value %} |
103 |
| - | %number {% (d) => parseInt(d[0].value) %} |
| 87 | +Metadata -> null {% (d) => undefined %} |
| 88 | + | __ "{" MetadataList "}" {% (d) => d[2] %} |
| 89 | +MetadataList -> _ MetadataEntry _ {% (d) => [d[1]] %} |
| 90 | + | MetadataList "," MetadataList {% (d) => d[0].concat(d[2]) %} |
| 91 | + |
| 92 | +MetadataEntry -> MetadataKey _ "=" _ MetadataValue {% (d) => { return { key: d[0], value: d[4] } } %} |
| 93 | +MetadataKey -> %identifier {% (d) => d[0].text %} |
| 94 | +MetadataValue -> %string {% (d) => d[0].value %} |
| 95 | + | %number {% (d) => parseInt(d[0].value) %} |
| 96 | + | %string _ MetadataConfig {% (d) => { return { value: d[0].value, config: d[2] } } %} |
| 97 | + |
| 98 | +MetadataConfig -> "[" MetadataConfigList "]" {% (d) => d[1] %} |
| 99 | +MetadataConfigList -> _ MetadataConfigItem _ {% (d) => [d[1]] %} |
| 100 | + | MetadataConfigList "," MetadataConfigList {% (d) => d[0].concat(d[2]) %} |
| 101 | +MetadataConfigItem -> MetadataConfigKey _ "=" _ MetadataConfigValue {% (d) => { return { key: d[0], value: d[4] } } %} |
| 102 | +MetadataConfigKey -> %identifier {% (d) => d[0].text %} |
| 103 | +MetadataConfigValue -> %string {% (d) => d[0].value %} |
| 104 | + | %number {% (d) => parseInt(d[0].value) %} |
104 | 105 |
|
105 | 106 |
|
106 | 107 | _ -> null {% () => null %}
|
107 |
| - | _ %WS {% () => null %} |
108 |
| - | _ %NL {% () => null %} |
109 |
| - | _ %comment {% () => null %} |
110 |
| - |
111 |
| -__ -> %WS {% () => null %} |
112 |
| - | %NL {% () => null %} |
113 |
| - | %comment {% () => null %} |
114 |
| - | __ %WS {% () => null %} |
115 |
| - | __ %NL {% () => null %} |
116 |
| - | __ %comment {% () => null %} |
| 108 | + | _ %WS {% () => null %} |
| 109 | + | _ %NL {% () => null %} |
| 110 | + | _ %comment {% () => null %} |
| 111 | + |
| 112 | +__ -> %WS {% () => null %} |
| 113 | + | %NL {% () => null %} |
| 114 | + | %comment {% () => null %} |
| 115 | + | __ %WS {% () => null %} |
| 116 | + | __ %NL {% () => null %} |
| 117 | + | __ %comment {% () => null %} |
0 commit comments