occam-custom-grammars 5.0.1227 → 5.0.1229

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.
Files changed (42) hide show
  1. package/example.js +904 -515
  2. package/lib/constants.js +17 -1
  3. package/lib/customGrammar/combined.js +37 -22
  4. package/lib/customGrammar/default.js +9 -9
  5. package/lib/customGrammar.js +56 -65
  6. package/lib/example/customGrammar/userDefined1.js +4 -4
  7. package/lib/example/customGrammar/userDefined2.js +4 -4
  8. package/lib/example/grammarNames.js +3 -3
  9. package/lib/example/select/{patternName.js → vocabularyName.js} +23 -23
  10. package/lib/example/{input/pattern.js → textarea/vocabulary.js} +23 -23
  11. package/lib/example/view.js +13 -13
  12. package/lib/index.js +5 -5
  13. package/lib/typesMap.js +45 -0
  14. package/lib/utilities/bnf.js +66 -0
  15. package/lib/utilities/grammar.js +31 -0
  16. package/lib/utilities/nominal.js +25 -0
  17. package/lib/utilities/query.js +36 -0
  18. package/lib/utilities/vocabulary.js +61 -0
  19. package/lib/vocabularyNames.js +29 -0
  20. package/package.json +4 -3
  21. package/src/constants.js +4 -0
  22. package/src/customGrammar/combined.js +46 -25
  23. package/src/customGrammar/default.js +5 -4
  24. package/src/customGrammar.js +49 -64
  25. package/src/example/customGrammar/userDefined1.js +10 -6
  26. package/src/example/customGrammar/userDefined2.js +6 -6
  27. package/src/example/grammarNames.js +1 -1
  28. package/src/example/select/vocabularyName.js +52 -0
  29. package/src/example/textarea/vocabulary.js +33 -0
  30. package/src/example/view.js +16 -16
  31. package/src/index.js +1 -1
  32. package/src/typesMap.js +50 -0
  33. package/src/utilities/bnf.js +88 -0
  34. package/src/utilities/grammar.js +12 -0
  35. package/src/utilities/nominal.js +9 -0
  36. package/src/utilities/query.js +25 -0
  37. package/src/utilities/vocabulary.js +74 -0
  38. package/src/vocabularyNames.js +9 -0
  39. package/lib/patternNames.js +0 -29
  40. package/src/example/input/pattern.js +0 -33
  41. package/src/example/select/patternName.js +0 -52
  42. package/src/patternNames.js +0 -9
@@ -0,0 +1,61 @@
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 expressionsFromVocabulary () {
13
+ return expressionsFromVocabulary;
14
+ },
15
+ get validateVocabulary () {
16
+ return validateVocabulary;
17
+ }
18
+ });
19
+ var _necessary = require("necessary");
20
+ var _query = require("../utilities/query");
21
+ var _nominal = require("../utilities/nominal");
22
+ var _constants = require("../constants");
23
+ var _grammar = require("../utilities/grammar");
24
+ var first = _necessary.arrayUtilities.first, second = _necessary.arrayUtilities.second;
25
+ var expressionNodesQuery = (0, _query.nodesQuery)("//expression");
26
+ function validateVocabulary(vocabulary) {
27
+ if (vocabulary === null || vocabulary === _constants.EMPTY_STRING) {
28
+ return;
29
+ }
30
+ var content = vocabulary, tokens = _grammar.customGrammarVocabularyLexer.tokenise(content), node = _grammar.customGrammarVocabularyParser.parse(tokens);
31
+ var expressionNodes = expressionNodesQuery(node);
32
+ expressionNodes.forEach(function(expressionNode) {
33
+ var content = contentFromExpressionNode(expressionNode), tokens = _nominal.nominalLexer.tokenise(content), tokensLength = tokens.length;
34
+ if (tokensLength > 1) {
35
+ throw new Error("Tokenising the '".concat(content, "' content results in more than one token."));
36
+ }
37
+ var firstToken = first(tokens), token = firstToken, type = token.getType();
38
+ if (type !== _constants.UNASSIGNED_TYPE) {
39
+ throw new Error("The '".concat(type, "' type of the '").concat(content, "' token is not 'unassigned'."));
40
+ }
41
+ if (content === _constants.UNDERSCORE_CHARACTER) {
42
+ throw new Error("The '".concat(content, "' token cannot be an underscore."));
43
+ }
44
+ });
45
+ }
46
+ function expressionsFromVocabulary(vocabulary, expressions) {
47
+ if (vocabulary === null || vocabulary === _constants.EMPTY_STRING) {
48
+ return;
49
+ }
50
+ var content = vocabulary, tokens = _grammar.customGrammarVocabularyLexer.tokenise(content), node = _grammar.customGrammarVocabularyParser.parse(tokens), expressionNodes = expressionNodesQuery(node);
51
+ expressionNodes.forEach(function(expressionNode) {
52
+ var content = contentFromExpressionNode(expressionNode), expression = content; ///
53
+ expressions.push(expression);
54
+ });
55
+ }
56
+ function contentFromExpressionNode(expressionNode) {
57
+ var nonTerminalNode = expressionNode, childNodes = nonTerminalNode.getChildNodes(), secondChildNode = second(childNodes), unassignedTerminalNode = secondChildNode, content = unassignedTerminalNode.getContent();
58
+ return content;
59
+ }
60
+
61
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlsaXRpZXMvdm9jYWJ1bGFyeS5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyJcInVzZSBzdHJpY3RcIjtcblxuaW1wb3J0IHsgYXJyYXlVdGlsaXRpZXMgfSBmcm9tIFwibmVjZXNzYXJ5XCI7XG5cbmltcG9ydCB7IG5vZGVzUXVlcnkgfSBmcm9tIFwiLi4vdXRpbGl0aWVzL3F1ZXJ5XCI7XG5pbXBvcnQgeyBub21pbmFsTGV4ZXIgfSBmcm9tIFwiLi4vdXRpbGl0aWVzL25vbWluYWxcIjtcbmltcG9ydCB7IEVNUFRZX1NUUklORywgVU5BU1NJR05FRF9UWVBFLCBVTkRFUlNDT1JFX0NIQVJBQ1RFUiB9IGZyb20gXCIuLi9jb25zdGFudHNcIjtcbmltcG9ydCB7IGN1c3RvbUdyYW1tYXJWb2NhYnVsYXJ5TGV4ZXIsIGN1c3RvbUdyYW1tYXJWb2NhYnVsYXJ5UGFyc2VyIH0gZnJvbSBcIi4uL3V0aWxpdGllcy9ncmFtbWFyXCJcblxuY29uc3QgeyBmaXJzdCwgc2Vjb25kIH0gPSBhcnJheVV0aWxpdGllcztcblxuY29uc3QgZXhwcmVzc2lvbk5vZGVzUXVlcnkgPSBub2Rlc1F1ZXJ5KFwi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ixJQUFJRCxTQUFTRSwwQkFBZSxFQUFFO1lBQzVCLE1BQU0sSUFBSUwsTUFBTSxBQUFDLFFBQTZCZCxPQUF0QmlCLE1BQUssbUJBQXlCLE9BQVJqQixTQUFRO1FBQ3hEO1FBRUEsSUFBSUEsWUFBWW9CLCtCQUFvQixFQUFFO1lBQ3BDLE1BQU0sSUFBSU4sTUFBTSxBQUFDLFFBQWUsT0FBUmQsU0FBUTtRQUNsQztJQUNGO0FBQ0Y7QUFFTyxTQUFTVCwwQkFBMEJPLFVBQVUsRUFBRXVCLFdBQVc7SUFDL0QsSUFBSSxBQUFDdkIsZUFBZSxRQUFVQSxlQUFlQyx1QkFBWSxFQUFHO1FBQzFEO0lBQ0Y7SUFFQSxJQUFNQyxVQUFVRixZQUNWRyxTQUFTQyxxQ0FBNEIsQ0FBQ0MsUUFBUSxDQUFDSCxVQUMvQ0ksT0FBT0Msc0NBQTZCLENBQUNDLEtBQUssQ0FBQ0wsU0FDM0NNLGtCQUFrQlgscUJBQXFCUTtJQUU3Q0csZ0JBQWdCQyxPQUFPLENBQUMsU0FBQ0M7UUFDdkIsSUFBTVQsVUFBVVUsMEJBQTBCRCxpQkFDcENhLGFBQWF0QixTQUFTLEdBQUc7UUFFL0JxQixZQUFZRSxJQUFJLENBQUNEO0lBQ25CO0FBQ0Y7QUFFQSxTQUFTWiwwQkFBMEJELGNBQWM7SUFDL0MsSUFBTWUsa0JBQWtCZixnQkFDbEJnQixhQUFhRCxnQkFBZ0JFLGFBQWEsSUFDMUNDLGtCQUFrQmhDLE9BQU84QixhQUN6QkcseUJBQXlCRCxpQkFDekIzQixVQUFVNEIsdUJBQXVCQyxVQUFVO0lBRWpELE9BQU83QjtBQUNUIn0=
@@ -0,0 +1,29 @@
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_VOCABULARY_NAME () {
13
+ return SYMBOL_VOCABULARY_NAME;
14
+ },
15
+ get TYPE_VOCABULARY_NAME () {
16
+ return TYPE_VOCABULARY_NAME;
17
+ },
18
+ get default () {
19
+ return _default;
20
+ }
21
+ });
22
+ var TYPE_VOCABULARY_NAME = "type";
23
+ var SYMBOL_VOCABULARY_NAME = "symbol";
24
+ var _default = {
25
+ TYPE_VOCABULARY_NAME: TYPE_VOCABULARY_NAME,
26
+ SYMBOL_VOCABULARY_NAME: SYMBOL_VOCABULARY_NAME
27
+ };
28
+
29
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy92b2NhYnVsYXJ5TmFtZXMuanMiXSwic291cmNlc0NvbnRlbnQiOlsiXCJ1c2Ugc3RyaWN0XCI7XG5cbmV4cG9ydCBjb25zdCBUWVBFX1ZPQ0FCVUxBUllfTkFNRSA9IFwidHlwZVwiO1xuZXhwb3J0IGNvbnN0IFNZTUJPTF9WT0NBQlVMQVJZX05BTUUgPSBcInN5bWJvbFwiO1xuXG5leHBvcnQgZGVmYXVsdCB7XG4gIFRZUEVfVk9DQUJVTEFSWV9OQU1FLFxuICBTWU1CT0xfVk9DQUJVTEFSWV9OQU1FXG59O1xuIl0sIm5hbWVzIjpbIlNZTUJPTF9WT0NBQlVMQVJZX05BTUUiLCJUWVBFX1ZPQ0FCVUxBUllfTkFNRSJdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7Ozs7Ozs7O1FBR2FBO2VBQUFBOztRQURBQztlQUFBQTs7UUFHYjtlQUFBOzs7QUFITyxJQUFNQSx1QkFBdUI7QUFDN0IsSUFBTUQseUJBQXlCO0lBRXRDLFdBQWU7SUFDYkMsc0JBQUFBO0lBQ0FELHdCQUFBQTtBQUNGIn0=
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "occam-custom-grammars",
3
3
  "author": "James Smith",
4
- "version": "5.0.1227",
4
+ "version": "5.0.1229",
5
5
  "license": "MIT, Anti-996",
6
6
  "homepage": "https://github.com/djalbat/occam-custom-grammars",
7
7
  "description": "Occam's custom grammars.",
@@ -12,9 +12,10 @@
12
12
  "dependencies": {
13
13
  "necessary": "^14.3.2",
14
14
  "occam-grammar-utilities": "^8.0.345",
15
- "occam-grammars": "^1.3.309",
15
+ "occam-grammars": "^1.3.311",
16
16
  "occam-lexers": "^23.1.1",
17
- "occam-parsers": "^23.1.1"
17
+ "occam-parsers": "^23.1.3",
18
+ "occam-query": "^4.1.109"
18
19
  },
19
20
  "devDependencies": {
20
21
  "@swc/core": "^1.5.6",
package/src/constants.js CHANGED
@@ -2,3 +2,7 @@
2
2
 
3
3
  export const EMPTY_STRING = "";
4
4
  export const VERTICAL_BAR = "|";
5
+ export const UNASSIGNED_TYPE = "unassigned";
6
+ export const STUFF_RULE_NAME = "stuff";
7
+ export const NONSENSE_RULE_NAME = "nonsense";
8
+ export const UNDERSCORE_CHARACTER = "_";
@@ -6,8 +6,11 @@ import { eliminateLeftRecursion } from "occam-grammar-utilities";
6
6
 
7
7
  import defaultCustomGrammar from "../customGrammar/default";
8
8
 
9
+ import { validateBNF } from "../utilities/bnf";
9
10
  import { EMPTY_STRING, VERTICAL_BAR } from "../constants";
10
- import { TYPE_PATTERN_NAME, SYMBOL_PATTERN_NAME } from "../patternNames";
11
+ import { TERM_RULE_NAME, STATEMENT_RULE_NAME } from "../ruleNames";
12
+ import { validateVocabulary, expressionsFromVocabulary } from "../utilities/vocabulary";
13
+ import { TYPE_VOCABULARY_NAME, SYMBOL_VOCABULARY_NAME } from "../vocabularyNames";
11
14
 
12
15
  const { rulesFromBNF } = parserUtilities,
13
16
  { unshift, backwardsForEach } = arrayUtilities;
@@ -44,7 +47,7 @@ export default class CombinedCustomGrammar {
44
47
  customGrammars = [ defaultCustomGrammar, ...customGrammars ]; ///
45
48
  }
46
49
 
47
- const rules = rulesFromCustomGrammarsAndDefaultBNF(customGrammars),
50
+ const rules = rulesFromCustomGrammars(customGrammars),
48
51
  entries = entriesFromCustomGrammars(customGrammars),
49
52
  combinedCustomGrammar = new CombinedCustomGrammar(rules, entries);
50
53
 
@@ -56,7 +59,7 @@ export default class CombinedCustomGrammar {
56
59
  customGrammars = [ defaultCustomGrammar, ...customGrammars ]; ///
57
60
  }
58
61
 
59
- const rules = rulesFromCustomGrammarsAndDefaultBNF(customGrammars),
62
+ const rules = rulesFromCustomGrammars(customGrammars),
60
63
  entries = entriesFromCustomGrammars(customGrammars),
61
64
  combinedCustomGrammar = new CombinedCustomGrammar(rules, entries);
62
65
 
@@ -64,9 +67,13 @@ export default class CombinedCustomGrammar {
64
67
  }
65
68
  }
66
69
 
67
- function rulesFromCustomGrammarsAndDefaultBNF(customGrammars) {
68
- const bnfs = customGrammars.map((customGrammar) => {
69
- const bnf = customGrammar.getBNF();
70
+ function rulesFromCustomGrammars(customGrammars) {
71
+ const ruleNames = [
72
+ TERM_RULE_NAME,
73
+ STATEMENT_RULE_NAME,
74
+ ],
75
+ bnfs = ruleNames.map((ruleName) => {
76
+ const bnf = bnfFromCustomGrammars(customGrammars, ruleName);
70
77
 
71
78
  return bnf;
72
79
  }),
@@ -79,12 +86,12 @@ function rulesFromCustomGrammarsAndDefaultBNF(customGrammars) {
79
86
  }
80
87
 
81
88
  function entriesFromCustomGrammars(customGrammars) {
82
- const patternNames = [
83
- TYPE_PATTERN_NAME,
84
- SYMBOL_PATTERN_NAME
89
+ const vocabularyNames = [
90
+ TYPE_VOCABULARY_NAME,
91
+ SYMBOL_VOCABULARY_NAME
85
92
  ],
86
- entries = patternNames.map((patternName) => {
87
- const entry = entryFromCustomGrammars(customGrammars, patternName);
93
+ entries = vocabularyNames.map((vocabularyName) => {
94
+ const entry = entryFromCustomGrammars(customGrammars, vocabularyName);
88
95
 
89
96
  return entry;
90
97
  });
@@ -92,28 +99,42 @@ function entriesFromCustomGrammars(customGrammars) {
92
99
  return entries;
93
100
  }
94
101
 
95
- function entryFromCustomGrammars(customGrammars, patternName) {
96
- const patterns = [];
102
+ function bnfFromCustomGrammars(customGrammars, ruleName) {
103
+ const bnfs = [];
97
104
 
98
105
  backwardsForEach(customGrammars, (customGrammar) => {
99
- const pattern = customGrammar.getPattern(patternName);
106
+ const bnf = customGrammar.getBNF(ruleName),
107
+ customGrammarDefaultCustomGrammar = customGrammar.isDefaultCustomGrammar();
108
+
109
+ if (!customGrammarDefaultCustomGrammar) {
110
+ validateBNF(bnf, ruleName);
111
+ }
112
+
113
+ bnfs.push(bnf);
114
+ });
100
115
 
101
- if ((pattern !== null) && (pattern !== EMPTY_STRING)) {
102
- const subPatterns = pattern.split(VERTICAL_BAR);
116
+ const bnf = bnfs.join(EMPTY_STRING);
103
117
 
104
- subPatterns.forEach((subPattern) => {
105
- const pattern = (patternName === TYPE_PATTERN_NAME) ?
106
- `${subPattern}(?!\\w)` :
107
- subPattern; ///
118
+ return bnf;
119
+ }
120
+
121
+ function entryFromCustomGrammars(customGrammars, vocabularyName) {
122
+ const expressions = [];
108
123
 
109
- patterns.push(pattern);
110
- });
124
+ backwardsForEach(customGrammars, (customGrammar) => {
125
+ const vocabulary = customGrammar.getVocabulary(vocabularyName),
126
+ customGrammarDefaultCustomGrammar = customGrammar.isDefaultCustomGrammar();
127
+
128
+ if (!customGrammarDefaultCustomGrammar) {
129
+ validateVocabulary(vocabulary);
111
130
  }
131
+
132
+ expressionsFromVocabulary(vocabulary, expressions);
112
133
  });
113
134
 
114
- const patternsString = patterns.join(VERTICAL_BAR),
115
- entryName = patternName, ///
116
- entryValue = `^(?:${patternsString})`,
135
+ const pattern = expressions.join(VERTICAL_BAR),
136
+ entryName = vocabularyName, ///
137
+ entryValue = `^(?:${pattern})`,
117
138
  entry = {
118
139
  [entryName]: entryValue
119
140
  };
@@ -62,17 +62,18 @@ statementSubstitution ::= "[" statement "for" statement "]";
62
62
 
63
63
  referenceSubstitution ::= "[" reference "for" reference "]";`;
64
64
 
65
- export const typePattern = "_";
65
+ export const typeVocabulary = `_
66
+ `;
66
67
 
67
- export const symbolPattern = "";
68
+ export const symbolVocabulary = "";
68
69
 
69
70
  const name = DEFAULT_CUSTOM_GRAMMAR_NAME,
70
71
  json = {
71
72
  name,
72
73
  termBNF,
73
74
  statementBNF,
74
- typePattern,
75
- symbolPattern
75
+ typeVocabulary,
76
+ symbolVocabulary
76
77
  };
77
78
 
78
79
  const defaultCustomGrammar = CustomGrammar.fromJSON(json);
@@ -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 { TYPE_PATTERN_NAME, SYMBOL_PATTERN_NAME } from "./patternNames";
6
+ import { TYPE_VOCABULARY_NAME, SYMBOL_VOCABULARY_NAME } from "./vocabularyNames";
6
7
 
7
8
  export default class CustomGrammar {
8
- constructor(name, termBNF, statementBNF, typePattern, symbolPattern) {
9
+ constructor(name, termBNF, statementBNF, typeVocabulary, symbolVocabulary) {
9
10
  this.name = name;
10
11
  this.termBNF = termBNF;
11
12
  this.statementBNF = statementBNF;
12
- this.typePattern = typePattern;
13
- this.symbolPattern = symbolPattern;
13
+ this.typeVocabulary = typeVocabulary;
14
+ this.symbolVocabulary = symbolVocabulary;
14
15
  }
15
16
 
16
17
  getName() {
@@ -25,65 +26,49 @@ export default class CustomGrammar {
25
26
  return this.statementBNF;
26
27
  }
27
28
 
28
- getTypePattern() {
29
- return this.typePattern;
29
+ getTypeVocabulary() {
30
+ return this.typeVocabulary;
30
31
  }
31
32
 
32
- getSymbolPattern() {
33
- return this.symbolPattern;
33
+ getSymbolVocabulary() {
34
+ return this.symbolVocabulary;
34
35
  }
35
36
 
36
- getBNF(ruleName = null) {
37
+ getBNF(ruleName) {
37
38
  let bnf;
38
39
 
39
40
  switch (ruleName) {
40
41
  case TERM_RULE_NAME: bnf = this.termBNF; break;
41
42
  case STATEMENT_RULE_NAME: bnf = this.statementBNF; break;
42
-
43
- default: {
44
- const ruleNames = [
45
- TERM_RULE_NAME,
46
- STATEMENT_RULE_NAME
47
- ],
48
- combinedBNF = ruleNames.reduce((combinedBNF, ruleName) => {
49
- const bnf = this.getBNF(ruleName);
50
-
51
- if (bnf !== EMPTY_STRING) {
52
- combinedBNF = `${combinedBNF}
53
-
54
- ${bnf}`;
55
- }
56
-
57
- return combinedBNF;
58
- }, EMPTY_STRING);
59
-
60
- bnf = combinedBNF; ///
61
-
62
- break;
63
- }
64
43
  }
65
44
 
66
45
  return bnf;
67
46
  }
68
47
 
69
- getPattern(patternName) {
70
- let pattern;
48
+ getVocabulary(vocabularyName) {
49
+ let vocabulary;
71
50
 
72
- switch (patternName) {
73
- case TYPE_PATTERN_NAME: pattern = this.typePattern; break;
74
- case SYMBOL_PATTERN_NAME: pattern = this.symbolPattern; break;
51
+ switch (vocabularyName) {
52
+ case TYPE_VOCABULARY_NAME: vocabulary = this.typeVocabulary; break;
53
+ case SYMBOL_VOCABULARY_NAME: vocabulary = this.symbolVocabulary; break;
75
54
  }
76
55
 
77
- return pattern;
56
+ return vocabulary;
78
57
  }
79
58
 
80
- getPatterns() {
81
- const patterns = [
82
- this.typePattern,
83
- this.symbolPattern
59
+ getVocabularies() {
60
+ const vocabularies = [
61
+ this.typeVocabulary,
62
+ this.symbolVocabulary
84
63
  ];
85
64
 
86
- return patterns;
65
+ return vocabularies;
66
+ }
67
+
68
+ isDefaultCustomGrammar() {
69
+ const defaultCustomGrammar = (this.name === DEFAULT_CUSTOM_GRAMMAR_NAME);
70
+
71
+ return defaultCustomGrammar;
87
72
  }
88
73
 
89
74
  setName(name) {
@@ -104,15 +89,15 @@ ${bnf}`;
104
89
  }
105
90
  }
106
91
 
107
- setPattern(patternName, pattern) {
108
- switch (patternName) {
109
- case TYPE_PATTERN_NAME:
110
- this.typePattern = pattern;
92
+ setVocabulary(vocabularyName, vocabulary) {
93
+ switch (vocabularyName) {
94
+ case TYPE_VOCABULARY_NAME:
95
+ this.typeVocabulary = vocabulary;
111
96
 
112
97
  break;
113
98
 
114
- case SYMBOL_PATTERN_NAME:
115
- this.symbolPattern = pattern;
99
+ case SYMBOL_VOCABULARY_NAME:
100
+ this.symbolVocabulary = vocabulary;
116
101
 
117
102
  break;
118
103
  }
@@ -124,38 +109,38 @@ ${bnf}`;
124
109
  this.setBNF(ruleName, bnf);
125
110
  }
126
111
 
127
- resetPattern(patternName) {
128
- const pattern = EMPTY_STRING;
112
+ resetVocabulary(vocabularyName) {
113
+ const vocabulary = EMPTY_STRING;
129
114
 
130
- this.setPattern(patternName, pattern);
115
+ this.setVocabulary(vocabularyName, vocabulary);
131
116
  }
132
117
 
133
- update(ruleName, bnf, patternName, pattern) {
118
+ update(ruleName, bnf, vocabularyName, vocabulary) {
134
119
  this.setBNF(ruleName, bnf);
135
120
 
136
- this.setPattern(patternName, pattern);
121
+ this.setVocabulary(vocabularyName, vocabulary);
137
122
  }
138
123
 
139
124
  toJSON() {
140
125
  const name = this.name,
141
126
  termBNF = this.termBNF,
142
127
  statementBNF = this.statementBNF,
143
- typePattern = this.typePattern,
144
- symbolPattern = this.symbolPattern,
128
+ typeVocabulary = this.typeVocabulary,
129
+ symbolVocabulary = this.symbolVocabulary,
145
130
  json = {
146
131
  name,
147
132
  termBNF,
148
133
  statementBNF,
149
- typePattern,
150
- symbolPattern
134
+ typeVocabulary,
135
+ symbolVocabulary
151
136
  };
152
137
 
153
138
  return json;
154
139
  }
155
140
 
156
141
  static fromJSON(json) {
157
- const { name, termBNF, statementBNF, typePattern, symbolPattern } = json,
158
- customGrammar = new CustomGrammar(name, termBNF, statementBNF, typePattern, symbolPattern);
142
+ const { name, termBNF, statementBNF, typeVocabulary, symbolVocabulary } = json,
143
+ customGrammar = new CustomGrammar(name, termBNF, statementBNF, typeVocabulary, symbolVocabulary);
159
144
 
160
145
  return customGrammar;
161
146
  }
@@ -163,15 +148,15 @@ ${bnf}`;
163
148
  static fromName(name) {
164
149
  const termBNF = EMPTY_STRING,
165
150
  statementBNF = EMPTY_STRING,
166
- typePattern = EMPTY_STRING,
167
- symbolPattern = EMPTY_STRING,
168
- customGrammar = new CustomGrammar(name, termBNF, statementBNF, typePattern, symbolPattern);
151
+ typeVocabulary = EMPTY_STRING,
152
+ symbolVocabulary = EMPTY_STRING,
153
+ customGrammar = new CustomGrammar(name, termBNF, statementBNF, typeVocabulary, symbolVocabulary);
169
154
 
170
155
  return customGrammar;
171
156
  }
172
157
 
173
- static fromNameTermBNFStatementBNFTypePatternAndSymbolPattern(name, termBNF, statementBNF, typePattern, symbolPattern) {
174
- const customGrammar = new CustomGrammar(name, termBNF, statementBNF, typePattern, symbolPattern);
158
+ static fromNameTermBNFStatementBNFTypeVocabularyAndSymbolVocabulary(name, termBNF, statementBNF, typeVocabulary, symbolVocabulary) {
159
+ const customGrammar = new CustomGrammar(name, termBNF, statementBNF, typeVocabulary, symbolVocabulary);
175
160
 
176
161
  return customGrammar;
177
162
  }
@@ -5,16 +5,20 @@ 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
- typePattern = "Group",
11
- symbolPattern = "",
8
+ termBNF = `
9
+
10
+ term ::= [type] "stuff" ;
11
+
12
+ `,
13
+ statementBNF = "",
14
+ typeVocabulary = "",
15
+ symbolVocabulary = "",
12
16
  json = {
13
17
  name,
14
18
  termBNF,
15
19
  statementBNF,
16
- typePattern,
17
- symbolPattern
20
+ typeVocabulary,
21
+ symbolVocabulary
18
22
  },
19
23
  userDefinedCustomGrammar1 = CustomGrammar.fromJSON(json);
20
24
 
@@ -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
- typePattern = "",
11
- symbolPattern = "",
8
+ termBNF = "",
9
+ statementBNF = "",
10
+ typeVocabulary = "",
11
+ symbolVocabulary = "",
12
12
  json = {
13
13
  name,
14
14
  termBNF,
15
15
  statementBNF,
16
- typePattern,
17
- symbolPattern
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 "../grammarNames";
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
+ }