occam-custom-grammars 5.0.1226 → 5.0.1228
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/example.js +706 -516
- package/lib/constants.js +9 -1
- package/lib/customGrammar/combined.js +15 -17
- package/lib/customGrammar/default.js +9 -9
- package/lib/customGrammar.js +55 -47
- package/lib/example/customGrammar/userDefined1.js +4 -4
- package/lib/example/customGrammar/userDefined2.js +4 -4
- package/lib/example/grammarNames.js +3 -3
- package/lib/example/select/{patternName.js → vocabularyName.js} +23 -23
- package/lib/example/{input/pattern.js → textarea/vocabulary.js} +23 -23
- package/lib/example/view.js +11 -11
- package/lib/index.js +5 -5
- package/lib/utilities/bnf.js +18 -0
- package/lib/utilities/query.js +36 -0
- package/lib/utilities/vocabulary.js +69 -0
- package/lib/vocabularyNames.js +29 -0
- package/package.json +4 -3
- package/src/constants.js +2 -0
- package/src/customGrammar/combined.js +18 -22
- package/src/customGrammar/default.js +5 -4
- package/src/customGrammar.js +48 -41
- package/src/example/customGrammar/userDefined1.js +6 -6
- package/src/example/customGrammar/userDefined2.js +6 -6
- package/src/example/grammarNames.js +1 -1
- package/src/example/select/vocabularyName.js +52 -0
- package/src/example/textarea/vocabulary.js +33 -0
- package/src/example/view.js +14 -14
- package/src/index.js +1 -1
- package/src/utilities/bnf.js +12 -0
- package/src/utilities/query.js +25 -0
- package/src/utilities/vocabulary.js +91 -0
- package/src/vocabularyNames.js +9 -0
- package/lib/patternNames.js +0 -29
- package/src/example/input/pattern.js +0 -33
- package/src/example/select/patternName.js +0 -52
- package/src/patternNames.js +0 -9
package/src/customGrammar.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { EMPTY_STRING } from "./constants";
|
|
4
|
+
import { DEFAULT_CUSTOM_GRAMMAR_NAME } from "./grammarNames";
|
|
4
5
|
import { TERM_RULE_NAME, STATEMENT_RULE_NAME } from "./ruleNames";
|
|
5
|
-
import {
|
|
6
|
+
import { TYPE_VOCABULARY_NAME, SYMBOL_VOCABULARY_NAME } from "./vocabularyNames";
|
|
6
7
|
|
|
7
8
|
export default class CustomGrammar {
|
|
8
|
-
constructor(name, termBNF, statementBNF,
|
|
9
|
+
constructor(name, termBNF, statementBNF, typeVocabulary, symbolVocabulary) {
|
|
9
10
|
this.name = name;
|
|
10
11
|
this.termBNF = termBNF;
|
|
11
12
|
this.statementBNF = statementBNF;
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
13
|
+
this.typeVocabulary = typeVocabulary;
|
|
14
|
+
this.symbolVocabulary = symbolVocabulary;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
getName() {
|
|
@@ -25,12 +26,12 @@ export default class CustomGrammar {
|
|
|
25
26
|
return this.statementBNF;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
return this.
|
|
29
|
+
getTypeVocabulary() {
|
|
30
|
+
return this.typeVocabulary;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
return this.
|
|
33
|
+
getSymbolVocabulary() {
|
|
34
|
+
return this.symbolVocabulary;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
getBNF(ruleName = null) {
|
|
@@ -66,24 +67,30 @@ ${bnf}`;
|
|
|
66
67
|
return bnf;
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
let
|
|
70
|
+
getVocabulary(vocabularyName) {
|
|
71
|
+
let vocabulary;
|
|
71
72
|
|
|
72
|
-
switch (
|
|
73
|
-
case
|
|
74
|
-
case
|
|
73
|
+
switch (vocabularyName) {
|
|
74
|
+
case TYPE_VOCABULARY_NAME: vocabulary = this.typeVocabulary; break;
|
|
75
|
+
case SYMBOL_VOCABULARY_NAME: vocabulary = this.symbolVocabulary; break;
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
return
|
|
78
|
+
return vocabulary;
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
this.
|
|
83
|
-
this.
|
|
81
|
+
getVocabularies() {
|
|
82
|
+
const vocabularies = [
|
|
83
|
+
this.typeVocabulary,
|
|
84
|
+
this.symbolVocabulary
|
|
84
85
|
];
|
|
85
86
|
|
|
86
|
-
return
|
|
87
|
+
return vocabularies;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
isDefaultCustomGrammar() {
|
|
91
|
+
const defaultCustomGrammar = (this.name === DEFAULT_CUSTOM_GRAMMAR_NAME);
|
|
92
|
+
|
|
93
|
+
return defaultCustomGrammar;
|
|
87
94
|
}
|
|
88
95
|
|
|
89
96
|
setName(name) {
|
|
@@ -104,15 +111,15 @@ ${bnf}`;
|
|
|
104
111
|
}
|
|
105
112
|
}
|
|
106
113
|
|
|
107
|
-
|
|
108
|
-
switch (
|
|
109
|
-
case
|
|
110
|
-
this.
|
|
114
|
+
setVocabulary(vocabularyName, vocabulary) {
|
|
115
|
+
switch (vocabularyName) {
|
|
116
|
+
case TYPE_VOCABULARY_NAME:
|
|
117
|
+
this.typeVocabulary = vocabulary;
|
|
111
118
|
|
|
112
119
|
break;
|
|
113
120
|
|
|
114
|
-
case
|
|
115
|
-
this.
|
|
121
|
+
case SYMBOL_VOCABULARY_NAME:
|
|
122
|
+
this.symbolVocabulary = vocabulary;
|
|
116
123
|
|
|
117
124
|
break;
|
|
118
125
|
}
|
|
@@ -124,38 +131,38 @@ ${bnf}`;
|
|
|
124
131
|
this.setBNF(ruleName, bnf);
|
|
125
132
|
}
|
|
126
133
|
|
|
127
|
-
|
|
128
|
-
const
|
|
134
|
+
resetVocabulary(vocabularyName) {
|
|
135
|
+
const vocabulary = EMPTY_STRING;
|
|
129
136
|
|
|
130
|
-
this.
|
|
137
|
+
this.setVocabulary(vocabularyName, vocabulary);
|
|
131
138
|
}
|
|
132
139
|
|
|
133
|
-
update(ruleName, bnf,
|
|
140
|
+
update(ruleName, bnf, vocabularyName, vocabulary) {
|
|
134
141
|
this.setBNF(ruleName, bnf);
|
|
135
142
|
|
|
136
|
-
this.
|
|
143
|
+
this.setVocabulary(vocabularyName, vocabulary);
|
|
137
144
|
}
|
|
138
145
|
|
|
139
146
|
toJSON() {
|
|
140
147
|
const name = this.name,
|
|
141
148
|
termBNF = this.termBNF,
|
|
142
149
|
statementBNF = this.statementBNF,
|
|
143
|
-
|
|
144
|
-
|
|
150
|
+
typeVocabulary = this.typeVocabulary,
|
|
151
|
+
symbolVocabulary = this.symbolVocabulary,
|
|
145
152
|
json = {
|
|
146
153
|
name,
|
|
147
154
|
termBNF,
|
|
148
155
|
statementBNF,
|
|
149
|
-
|
|
150
|
-
|
|
156
|
+
typeVocabulary,
|
|
157
|
+
symbolVocabulary
|
|
151
158
|
};
|
|
152
159
|
|
|
153
160
|
return json;
|
|
154
161
|
}
|
|
155
162
|
|
|
156
163
|
static fromJSON(json) {
|
|
157
|
-
const { name, termBNF, statementBNF,
|
|
158
|
-
customGrammar = new CustomGrammar(name, termBNF, statementBNF,
|
|
164
|
+
const { name, termBNF, statementBNF, typeVocabulary, symbolVocabulary } = json,
|
|
165
|
+
customGrammar = new CustomGrammar(name, termBNF, statementBNF, typeVocabulary, symbolVocabulary);
|
|
159
166
|
|
|
160
167
|
return customGrammar;
|
|
161
168
|
}
|
|
@@ -163,15 +170,15 @@ ${bnf}`;
|
|
|
163
170
|
static fromName(name) {
|
|
164
171
|
const termBNF = EMPTY_STRING,
|
|
165
172
|
statementBNF = EMPTY_STRING,
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
customGrammar = new CustomGrammar(name, termBNF, statementBNF,
|
|
173
|
+
typeVocabulary = EMPTY_STRING,
|
|
174
|
+
symbolVocabulary = EMPTY_STRING,
|
|
175
|
+
customGrammar = new CustomGrammar(name, termBNF, statementBNF, typeVocabulary, symbolVocabulary);
|
|
169
176
|
|
|
170
177
|
return customGrammar;
|
|
171
178
|
}
|
|
172
179
|
|
|
173
|
-
static
|
|
174
|
-
const customGrammar = new CustomGrammar(name, termBNF, statementBNF,
|
|
180
|
+
static fromNameTermBNFStatementBNFTypeVocabularyAndSymbolVocabulary(name, termBNF, statementBNF, typeVocabulary, symbolVocabulary) {
|
|
181
|
+
const customGrammar = new CustomGrammar(name, termBNF, statementBNF, typeVocabulary, symbolVocabulary);
|
|
175
182
|
|
|
176
183
|
return customGrammar;
|
|
177
184
|
}
|
|
@@ -5,16 +5,16 @@ import { CustomGrammar } from "../../index"; ///
|
|
|
5
5
|
import { USER_DEFINED_CUSTOM_GRAMMAR_NAME_1 } from "../grammarNames";
|
|
6
6
|
|
|
7
7
|
const name = USER_DEFINED_CUSTOM_GRAMMAR_NAME_1,
|
|
8
|
-
termBNF =
|
|
9
|
-
statementBNF =
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
termBNF = "",
|
|
9
|
+
statementBNF = "",
|
|
10
|
+
typeVocabulary = "",
|
|
11
|
+
symbolVocabulary = "",
|
|
12
12
|
json = {
|
|
13
13
|
name,
|
|
14
14
|
termBNF,
|
|
15
15
|
statementBNF,
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
typeVocabulary,
|
|
17
|
+
symbolVocabulary
|
|
18
18
|
},
|
|
19
19
|
userDefinedCustomGrammar1 = CustomGrammar.fromJSON(json);
|
|
20
20
|
|
|
@@ -5,16 +5,16 @@ import { CustomGrammar } from "../../index"; ///
|
|
|
5
5
|
import { USER_DEFINED_CUSTOM_GRAMMAR_NAME_2 } from "../grammarNames";
|
|
6
6
|
|
|
7
7
|
const name = USER_DEFINED_CUSTOM_GRAMMAR_NAME_2,
|
|
8
|
-
termBNF =
|
|
9
|
-
statementBNF =
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
termBNF = "",
|
|
9
|
+
statementBNF = "",
|
|
10
|
+
typeVocabulary = "",
|
|
11
|
+
symbolVocabulary = "",
|
|
12
12
|
json = {
|
|
13
13
|
name,
|
|
14
14
|
termBNF,
|
|
15
15
|
statementBNF,
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
typeVocabulary,
|
|
17
|
+
symbolVocabulary
|
|
18
18
|
},
|
|
19
19
|
userDefinedCustomGrammar2 = CustomGrammar.fromJSON(json);
|
|
20
20
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
export { DEFAULT_CUSTOM_GRAMMAR_NAME } from "../
|
|
3
|
+
export { DEFAULT_CUSTOM_GRAMMAR_NAME } from "../index"; ///
|
|
4
4
|
|
|
5
5
|
export const USER_DEFINED_CUSTOM_GRAMMAR_NAME_1 = "User defined 1";
|
|
6
6
|
export const USER_DEFINED_CUSTOM_GRAMMAR_NAME_2 = "User defined 2";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Select from "../select";
|
|
4
|
+
|
|
5
|
+
import { TYPE_VOCABULARY_NAME, SYMBOL_VOCABULARY_NAME } from "../../vocabularyNames";
|
|
6
|
+
|
|
7
|
+
export default class VocabularyNameSelect extends Select {
|
|
8
|
+
getVocabularyName() {
|
|
9
|
+
const value = this.getValue(),
|
|
10
|
+
vocabularyName = value; ///
|
|
11
|
+
|
|
12
|
+
return vocabularyName;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
childElements() {
|
|
16
|
+
const vocabularyNames = [
|
|
17
|
+
TYPE_VOCABULARY_NAME,
|
|
18
|
+
SYMBOL_VOCABULARY_NAME
|
|
19
|
+
],
|
|
20
|
+
options = vocabularyNames.map((vocabularyName, index) => {
|
|
21
|
+
const value = vocabularyName,
|
|
22
|
+
selected = (index === 0);
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
|
|
26
|
+
<option value={value} selected={selected} >
|
|
27
|
+
{vocabularyName}
|
|
28
|
+
</option>
|
|
29
|
+
|
|
30
|
+
);
|
|
31
|
+
}),
|
|
32
|
+
childElements = [
|
|
33
|
+
...options
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
return childElements;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
parentContext() {
|
|
41
|
+
const getVocabularyName = this.getVocabularyName.bind(this); ///
|
|
42
|
+
|
|
43
|
+
return ({
|
|
44
|
+
getVocabularyName
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static defaultProperties = {
|
|
49
|
+
className: "rule-name",
|
|
50
|
+
spellCheck: "false"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Textarea from "../textarea";
|
|
4
|
+
|
|
5
|
+
export default class VocabularyTextarea extends Textarea {
|
|
6
|
+
getVocabulary() {
|
|
7
|
+
const value = this.getValue(),
|
|
8
|
+
vocabulary = value; ///
|
|
9
|
+
|
|
10
|
+
return vocabulary;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
setVocabulary(vocabulary) {
|
|
14
|
+
const value = vocabulary; ///
|
|
15
|
+
|
|
16
|
+
this.setValue(value);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
parentContext() {
|
|
20
|
+
const getVocabulary = this.getVocabulary.bind(this),
|
|
21
|
+
setVocabulary = this.setVocabulary.bind(this);
|
|
22
|
+
|
|
23
|
+
return ({
|
|
24
|
+
getVocabulary,
|
|
25
|
+
setVocabulary
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static defaultProperties = {
|
|
30
|
+
className: "vocabulary",
|
|
31
|
+
spellCheck: "false"
|
|
32
|
+
};
|
|
33
|
+
}
|
package/src/example/view.js
CHANGED
|
@@ -11,13 +11,13 @@ import SubHeading from "./subHeading";
|
|
|
11
11
|
import NameSelect from "./select/name";
|
|
12
12
|
import SizeableDiv from "./div/sizeable";
|
|
13
13
|
import BNFTextarea from "./textarea/bnf";
|
|
14
|
-
import PatternInput from "./input/pattern";
|
|
15
14
|
import RuleNameSelect from "./select/ruleName";
|
|
16
15
|
import ContentTextarea from "./textarea/content";
|
|
17
|
-
import PatternNameSelect from "./select/patternName";
|
|
18
16
|
import ParseTreeTextarea from "./textarea/parseTree";
|
|
19
17
|
import StartRuleNameInput from "./input/startRuleName";
|
|
20
18
|
import NominalBNFTextarea from "./textarea/nominalBNF";
|
|
19
|
+
import VocabularyTextarea from "./textarea/vocabulary";
|
|
20
|
+
import VocabularyNameSelect from "./select/vocabularyName";
|
|
21
21
|
import userDefinedCustomGrammar1 from "./customGrammar/userDefined1";
|
|
22
22
|
import userDefinedCustomGrammar2 from "./customGrammar/userDefined2";
|
|
23
23
|
|
|
@@ -31,22 +31,22 @@ const { rulesAsString } = rulesUtilities,
|
|
|
31
31
|
class View extends Element {
|
|
32
32
|
keyUpHandler = (event, element) => {
|
|
33
33
|
try {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
pattern = this.getPattern(),
|
|
34
|
+
const bnf = this.getBNF(),
|
|
35
|
+
name = this.getName(),
|
|
37
36
|
ruleName = this.getRuleName(),
|
|
38
|
-
|
|
37
|
+
vocabulary = this.getVocabulary(),
|
|
38
|
+
vocabularyName = this.getVocabularyName();
|
|
39
39
|
|
|
40
40
|
if (name === USER_DEFINED_CUSTOM_GRAMMAR_NAME_1) {
|
|
41
41
|
userDefinedCustomGrammar1.setBNF(ruleName, bnf);
|
|
42
42
|
|
|
43
|
-
userDefinedCustomGrammar1.
|
|
43
|
+
userDefinedCustomGrammar1.setVocabulary(vocabularyName, vocabulary);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
if (name === USER_DEFINED_CUSTOM_GRAMMAR_NAME_2) {
|
|
47
47
|
userDefinedCustomGrammar2.setBNF(ruleName, bnf);
|
|
48
48
|
|
|
49
|
-
userDefinedCustomGrammar2.
|
|
49
|
+
userDefinedCustomGrammar2.setVocabulary(vocabularyName, vocabulary);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
const customGrammars = [
|
|
@@ -92,7 +92,7 @@ class View extends Element {
|
|
|
92
92
|
|
|
93
93
|
const name = this.getName(),
|
|
94
94
|
ruleName = this.getRuleName(),
|
|
95
|
-
|
|
95
|
+
vocabularyName = this.getVocabularyName();
|
|
96
96
|
|
|
97
97
|
switch (name) {
|
|
98
98
|
case DEFAULT_CUSTOM_GRAMMAR_NAME:
|
|
@@ -112,11 +112,11 @@ class View extends Element {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
const bnf = customGrammar.getBNF(ruleName),
|
|
115
|
-
|
|
115
|
+
vocabulary = customGrammar.getVocabulary(vocabularyName);
|
|
116
116
|
|
|
117
117
|
this.setBNF(bnf);
|
|
118
118
|
|
|
119
|
-
this.
|
|
119
|
+
this.setVocabulary(vocabulary);
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
childElements() {
|
|
@@ -138,10 +138,10 @@ class View extends Element {
|
|
|
138
138
|
<RuleNameSelect onChange={changeHandler} />
|
|
139
139
|
<BNFTextarea onKeyUp={keyUpHandler} />
|
|
140
140
|
<SubHeading>
|
|
141
|
-
|
|
141
|
+
Vocabulary
|
|
142
142
|
</SubHeading>
|
|
143
|
-
<
|
|
144
|
-
<
|
|
143
|
+
<VocabularyNameSelect onChange={changeHandler} />
|
|
144
|
+
<VocabularyTextarea onKeyUp={keyUpHandler} />
|
|
145
145
|
<SubHeading>
|
|
146
146
|
Start rule
|
|
147
147
|
</SubHeading>
|
package/src/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
export { DEFAULT_CUSTOM_GRAMMAR_NAME } from "./grammarNames";
|
|
4
4
|
|
|
5
5
|
export { default as ruleNames } from "./ruleNames";
|
|
6
|
-
export { default as
|
|
6
|
+
export { default as vocabularyNames } from "./vocabularyNames";
|
|
7
7
|
|
|
8
8
|
export { default as CustomGrammar } from "./customGrammar";
|
|
9
9
|
export { default as lexersUtilities } from "./utilities/lexers";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Query } from "occam-query";
|
|
4
|
+
|
|
5
|
+
export function nodeQuery(expressionString) {
|
|
6
|
+
const query = Query.fromExpressionString(expressionString);
|
|
7
|
+
|
|
8
|
+
return function(node) {
|
|
9
|
+
const nodes = query.execute(node);
|
|
10
|
+
|
|
11
|
+
node = nodes.shift() || null; ///
|
|
12
|
+
|
|
13
|
+
return node;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function nodesQuery(expressionString) {
|
|
18
|
+
const query = Query.fromExpressionString(expressionString);
|
|
19
|
+
|
|
20
|
+
return function(node) {
|
|
21
|
+
const nodes = query.execute(node);
|
|
22
|
+
|
|
23
|
+
return nodes;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { CommonLexer } from "occam-lexers";
|
|
4
|
+
import { NominalLexer } from "occam-grammars";
|
|
5
|
+
import { arrayUtilities } from "necessary";
|
|
6
|
+
import { CustomGrammarVocabularyLexer, CustomGrammarVocabularyParser } from "occam-grammars";
|
|
7
|
+
|
|
8
|
+
import { nodesQuery } from "../utilities/query";
|
|
9
|
+
import { EMPTY_STRING, UNASSIGNED_TYPE, UNDERSCORE_CHARACTER } from "../constants";
|
|
10
|
+
|
|
11
|
+
const errorNodesQuery = nodesQuery("//error"),
|
|
12
|
+
expressionNodesQuery = nodesQuery("//expression")
|
|
13
|
+
|
|
14
|
+
const nominalLexer = CommonLexer.fromNothing(NominalLexer),
|
|
15
|
+
customGrammarVocabularyLexer = CustomGrammarVocabularyLexer.fromNothing(),
|
|
16
|
+
customGrammarVocabularyParser = CustomGrammarVocabularyParser.fromNothing();
|
|
17
|
+
|
|
18
|
+
const { first, second } = arrayUtilities;
|
|
19
|
+
|
|
20
|
+
export function validateVocabulary(vocabulary) {
|
|
21
|
+
if ((vocabulary === null) || (vocabulary === EMPTY_STRING)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const content = vocabulary, ///
|
|
26
|
+
tokens = customGrammarVocabularyLexer.tokenise(content),
|
|
27
|
+
node = customGrammarVocabularyParser.parse(tokens);
|
|
28
|
+
|
|
29
|
+
if (node === null) {
|
|
30
|
+
throw new Error("The vocabulary cannot be parsed.");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const errorNodes = errorNodesQuery(node),
|
|
34
|
+
errorNodesLength = errorNodes.length;
|
|
35
|
+
|
|
36
|
+
if (errorNodesLength > 0) {
|
|
37
|
+
throw new Error("The vocabulary contains errors.");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const expressionNodes = expressionNodesQuery(node);
|
|
41
|
+
|
|
42
|
+
expressionNodes.forEach((expressionNode) => {
|
|
43
|
+
const content = contentFromExpressionNode(expressionNode),
|
|
44
|
+
tokens = nominalLexer.tokenise(content),
|
|
45
|
+
tokensLength = tokens.length;
|
|
46
|
+
|
|
47
|
+
if (tokensLength > 1) {
|
|
48
|
+
throw new Error(`Tokenising '${content}' results in more than one token.`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const firstToken = first(tokens),
|
|
52
|
+
token = firstToken,
|
|
53
|
+
type = token.getType();
|
|
54
|
+
|
|
55
|
+
if (type !== UNASSIGNED_TYPE) {
|
|
56
|
+
throw new Error(`The '${type}' type of the '${content}' token is not 'unassigned'.`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (content === UNDERSCORE_CHARACTER) {
|
|
60
|
+
throw new Error(`The '${content}' token cannot be an underscore.`);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function expressionsFromVocabulary(vocabulary, expressions) {
|
|
66
|
+
if ((vocabulary === null) || (vocabulary === EMPTY_STRING)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const content = vocabulary, ///
|
|
71
|
+
tokens = customGrammarVocabularyLexer.tokenise(content),
|
|
72
|
+
node = customGrammarVocabularyParser.parse(tokens),
|
|
73
|
+
expressionNodes = expressionNodesQuery(node);
|
|
74
|
+
|
|
75
|
+
expressionNodes.forEach((expressionNode) => {
|
|
76
|
+
const content = contentFromExpressionNode(expressionNode),
|
|
77
|
+
expression = content; ///
|
|
78
|
+
|
|
79
|
+
expressions.push(expression);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function contentFromExpressionNode(expressionNode) {
|
|
84
|
+
const nonTerminalNode = expressionNode, ///
|
|
85
|
+
childNodes = nonTerminalNode.getChildNodes(),
|
|
86
|
+
secondChildNode = second(childNodes),
|
|
87
|
+
unassignedTerminalNode = secondChildNode, ///
|
|
88
|
+
content = unassignedTerminalNode.getContent();
|
|
89
|
+
|
|
90
|
+
return content;
|
|
91
|
+
}
|
package/lib/patternNames.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
get SYMBOL_PATTERN_NAME () {
|
|
13
|
-
return SYMBOL_PATTERN_NAME;
|
|
14
|
-
},
|
|
15
|
-
get TYPE_PATTERN_NAME () {
|
|
16
|
-
return TYPE_PATTERN_NAME;
|
|
17
|
-
},
|
|
18
|
-
get default () {
|
|
19
|
-
return _default;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
var TYPE_PATTERN_NAME = "type";
|
|
23
|
-
var SYMBOL_PATTERN_NAME = "symbol";
|
|
24
|
-
var _default = {
|
|
25
|
-
TYPE_PATTERN_NAME: TYPE_PATTERN_NAME,
|
|
26
|
-
SYMBOL_PATTERN_NAME: SYMBOL_PATTERN_NAME
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9wYXR0ZXJuTmFtZXMuanMiXSwic291cmNlc0NvbnRlbnQiOlsiXCJ1c2Ugc3RyaWN0XCI7XG5cbmV4cG9ydCBjb25zdCBUWVBFX1BBVFRFUk5fTkFNRSA9IFwidHlwZVwiO1xuZXhwb3J0IGNvbnN0IFNZTUJPTF9QQVRURVJOX05BTUUgPSBcInN5bWJvbFwiO1xuXG5leHBvcnQgZGVmYXVsdCB7XG4gIFRZUEVfUEFUVEVSTl9OQU1FLFxuICBTWU1CT0xfUEFUVEVSTl9OQU1FXG59O1xuIl0sIm5hbWVzIjpbIlNZTUJPTF9QQVRURVJOX05BTUUiLCJUWVBFX1BBVFRFUk5fTkFNRSJdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7Ozs7Ozs7O1FBR2FBO2VBQUFBOztRQURBQztlQUFBQTs7UUFHYjtlQUFBOzs7QUFITyxJQUFNQSxvQkFBb0I7QUFDMUIsSUFBTUQsc0JBQXNCO0lBRW5DLFdBQWU7SUFDYkMsbUJBQUFBO0lBQ0FELHFCQUFBQTtBQUNGIn0=
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import Input from "../input";
|
|
4
|
-
|
|
5
|
-
export default class PatternInput extends Input {
|
|
6
|
-
getPattern() {
|
|
7
|
-
const value = this.getValue(),
|
|
8
|
-
pattern = value; ///
|
|
9
|
-
|
|
10
|
-
return pattern;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
setPattern(pattern) {
|
|
14
|
-
const value = pattern; ///
|
|
15
|
-
|
|
16
|
-
this.setValue(value);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
parentContext() {
|
|
20
|
-
const getPattern = this.getPattern.bind(this),
|
|
21
|
-
setPattern = this.setPattern.bind(this);
|
|
22
|
-
|
|
23
|
-
return ({
|
|
24
|
-
getPattern,
|
|
25
|
-
setPattern
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
static defaultProperties = {
|
|
30
|
-
className: "pattern",
|
|
31
|
-
spellCheck: "false"
|
|
32
|
-
};
|
|
33
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import Select from "../select";
|
|
4
|
-
|
|
5
|
-
import { TYPE_PATTERN_NAME, SYMBOL_PATTERN_NAME } from "../../patternNames";
|
|
6
|
-
|
|
7
|
-
export default class PatternNameSelect extends Select {
|
|
8
|
-
getPatternName() {
|
|
9
|
-
const value = this.getValue(),
|
|
10
|
-
patternName = value; ///
|
|
11
|
-
|
|
12
|
-
return patternName;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
childElements() {
|
|
16
|
-
const patternNames = [
|
|
17
|
-
TYPE_PATTERN_NAME,
|
|
18
|
-
SYMBOL_PATTERN_NAME
|
|
19
|
-
],
|
|
20
|
-
options = patternNames.map((patternName, index) => {
|
|
21
|
-
const value = patternName,
|
|
22
|
-
selected = (index === 0);
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
|
|
26
|
-
<option value={value} selected={selected} >
|
|
27
|
-
{patternName}
|
|
28
|
-
</option>
|
|
29
|
-
|
|
30
|
-
);
|
|
31
|
-
}),
|
|
32
|
-
childElements = [
|
|
33
|
-
...options
|
|
34
|
-
];
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return childElements;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
parentContext() {
|
|
41
|
-
const getPatternName = this.getPatternName.bind(this); ///
|
|
42
|
-
|
|
43
|
-
return ({
|
|
44
|
-
getPatternName
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
static defaultProperties = {
|
|
49
|
-
className: "rule-name",
|
|
50
|
-
spellCheck: "false"
|
|
51
|
-
}
|
|
52
|
-
}
|