-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathselector.js
More file actions
147 lines (137 loc) · 4.22 KB
/
Copy pathselector.js
File metadata and controls
147 lines (137 loc) · 4.22 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Generated automatically by nearley, version 2.20.1
// http://github.com/Hardmath123/nearley
// *******************************************************
// Add the following code whenever this file is regenerated
// to export the grammer in a type-safe way without using
// global variables.
// *******************************************************
import moo from 'moo';
export let grammar;
(function () {
function id(x) {
return x[0];
}
let lexer = moo.states({
main: {
strstart: {match: '"', push: 'lit'},
space: {match: /\s+/, lineBreaks: true},
ident: /(?:[a-zA-Z_:][a-zA-Z0-9_:\-.]*)/,
matcherType: ['=', '!=', '=~', '!~'],
'{': '{',
'}': '}',
',': ',',
},
lit: {
strend: {match: '"', pop: 1},
constant: {match: /(?:[^"])+/, lineBreaks: true},
},
});
function extractMatchers(d) {
let matchers = [d[2]];
for (let i in d[3]) {
matchers.push(d[3][i][3]);
}
return matchers;
}
grammar = {
Lexer: lexer,
ParserRules: [
{
name: 'profileSelector',
symbols: ['_', 'profileName', '_'],
postprocess: function (d) {
return {profileName: d[1], matchers: []};
},
},
{
name: 'profileSelector',
symbols: ['_', 'ident', '_', 'matchers', '_'],
postprocess: function (d) {
return {profileName: d[1], matchers: d[3]};
},
},
{
name: 'profileSelector',
symbols: ['_', 'matchers', '_'],
postprocess: function (d) {
return {profileName: {}, matchers: d[1]};
},
},
{
name: 'matchers',
symbols: [{literal: '{'}, '_', {literal: '}'}],
postprocess: function (d) {
return [];
},
},
{name: 'matchers$ebnf$1', symbols: []},
{name: 'matchers$ebnf$1$subexpression$1', symbols: ['_', {literal: ','}, '_', 'matcher']},
{
name: 'matchers$ebnf$1',
symbols: ['matchers$ebnf$1', 'matchers$ebnf$1$subexpression$1'],
postprocess: function arrpush(d) {
return d[0].concat([d[1]]);
},
},
{
name: 'matchers',
symbols: [{literal: '{'}, '_', 'matcher', 'matchers$ebnf$1', '_', {literal: '}'}],
postprocess: extractMatchers,
},
{
name: 'matcher',
symbols: ['labelName', '_', 'matcherType', '_', 'labelValue'],
postprocess: function (d) {
return {key: d[0], matcherType: d[2], value: d[4]};
},
},
{
name: 'string',
symbols: ['strstart', 'constant', 'strend'],
postprocess: function (d) {
return d[1];
},
},
{
name: 'string',
symbols: ['strstart', 'strend'],
postprocess: function (d) {
return {type: 'constant', value: ''};
},
},
{name: 'profileName', symbols: ['ident'], postprocess: id},
{name: 'labelName', symbols: ['ident'], postprocess: id},
{name: 'labelValue', symbols: ['string'], postprocess: id},
{
name: 'strstart',
symbols: [lexer.has('strstart') ? {type: 'strstart'} : strstart],
postprocess: id,
},
{
name: 'constant',
symbols: [lexer.has('constant') ? {type: 'constant'} : constant],
postprocess: id,
},
{name: 'strend', symbols: [lexer.has('strend') ? {type: 'strend'} : strend], postprocess: id},
{name: 'matcherType', symbols: [{literal: '='}], postprocess: id},
{name: 'matcherType', symbols: [{literal: '!='}], postprocess: id},
{name: 'matcherType', symbols: [{literal: '=~'}], postprocess: id},
{name: 'matcherType', symbols: [{literal: '!~'}], postprocess: id},
{name: 'ident', symbols: [lexer.has('ident') ? {type: 'ident'} : ident], postprocess: id},
{name: '_', symbols: []},
{
name: '_',
symbols: [lexer.has('space') ? {type: 'space'} : space],
postprocess: function (d) {
return null;
},
},
],
ParserStart: 'profileSelector',
};
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = grammar;
} else if (typeof window !== 'undefined') {
window.grammar = grammar;
}
})();