@bablr/language-en-bablr-vm-instruction 0.11.7 → 0.12.0

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 (2) hide show
  1. package/lib/grammar.js +73 -51
  2. package/package.json +10 -11
package/lib/grammar.js CHANGED
@@ -1,5 +1,4 @@
1
- import { re, spam as m } from '@bablr/boot';
2
- import { extendLanguage, eat, match, eatMatch, startSpan, endSpan } from '@bablr/helpers/grammar';
1
+ import { m, eat, match, eatMatch, startSpan, endSpan } from '@bablr/helpers/grammar';
3
2
  import Space from '@bablr/language-en-blank-space';
4
3
  import CSTML from '@bablr/language-en-cstml';
5
4
  import Spamex from '@bablr/language-en-spamex';
@@ -7,37 +6,38 @@ import Regex from '@bablr/language-en-regex-vm-pattern';
7
6
  import JSON from '@bablr/language-en-cstml-json';
8
7
  import { buildString } from '@bablr/helpers/builders';
9
8
  import { printSource } from '@bablr/agast-helpers/tree';
10
-
11
- export const canonicalURL = 'https://bablr.org/languages/core/en/bablr-vm-instruction';
12
-
13
- export const defaultMatcher = m`<Call />`;
9
+ import * as BSet from '@bablr/agast-helpers/b-set';
10
+ import { freezeRecord, freeze, freezeClass } from '@bablr/agast-helpers/object';
14
11
 
15
12
  export function* eatMatchTrivia() {
16
13
  let trivia = null;
17
- while (yield match(re`/[ \t\n]/`)) {
14
+ while (yield match(m`/[ \t\n]/`)) {
18
15
  trivia = yield eat(m`#: :Space: <_Blank />`);
19
16
  }
20
17
  return trivia;
21
18
  }
22
19
 
23
- const IJSON = extendLanguage(JSON, {
24
- canonicalURL: 'https://bablr.org/languages/core/en/bablr-vm-instruction-json',
25
- grammar: class IJSON extends JSON.grammar {
26
- *Expression(props) {
27
- if (yield match(re`/(?:m|re|t|i)['"\u0060]/`)) {
28
- yield eat(m`:..: <_Expression />`);
29
- } else {
30
- yield* super.Expression(props);
31
- }
20
+ class IJSON extends JSON.grammar {
21
+ static canonicalURL = 'https://bablr.org/languages/core/en/bablr-vm-instruction-json';
22
+
23
+ *Expression(props) {
24
+ if (yield match(m`/(?:m|re|t|i)['"\u0060]/`)) {
25
+ yield eat(m`:..: <_Expression />`);
26
+ } else {
27
+ yield* super.Expression(props);
32
28
  }
33
- },
34
- });
29
+ }
30
+ }
35
31
 
36
- export const dependencies = { Space, CSTML, Spamex, Regex, JSON, IJSON };
32
+ export default class BABLRVMInstruction {
33
+ static canonicalURL = 'https://bablr.org/languages/core/en/bablr-vm-instruction';
34
+ static dependencies = freeze({ Space, CSTML, Spamex, Regex, JSON, IJSON });
35
+ static defaultMatcher = m`<Call />`;
36
+ static fragmentProduction = null;
37
+ static context = freezeRecord({});
37
38
 
38
- export const grammar = class BABLRVMInstructionGrammar {
39
39
  constructor() {
40
- this.literals = new Set(['Keyword']);
40
+ this.literals = BSet.from('Keyword');
41
41
  }
42
42
 
43
43
  *Call() {
@@ -48,7 +48,7 @@ export const grammar = class BABLRVMInstructionGrammar {
48
48
  yield startSpan('Bare', ')');
49
49
  let sp = yield* eatMatchTrivia();
50
50
  let first = true;
51
- while ((first || sp) && (yield match(re`/./s`))) {
51
+ while ((first || sp) && (yield match(m`/./s`))) {
52
52
  yield eat(m`values[]$: <_Expression />`);
53
53
  yield* eatMatchTrivia();
54
54
  sp = yield eatMatch(m`#separatorTokens: <* ',' />`);
@@ -60,26 +60,56 @@ export const grammar = class BABLRVMInstructionGrammar {
60
60
  }
61
61
 
62
62
  *Expression() {
63
- if (yield eatMatch(m`:IJSON: <Array '[' />`)) {
64
- } else if (yield eatMatch(m`:IJSON: <Object '{' />`)) {
65
- } else if (yield eatMatch(m`:JSON: <Boolean /true|false/ />`)) {
66
- } else if (yield eatMatch(m`:JSON: <Null 'null' />`)) {
67
- } else if (yield eatMatch(m`:JSON: <Undefined 'undefined' />`)) {
68
- } else if (yield eatMatch(m`:JSON: <Number /[\d]/ />`)) {
69
- } else if (yield eatMatch(m`:JSON: <Infinity /[+-]?Infinity/ />`)) {
70
- } else if (yield eatMatch(m`<SpamexString /m["'\u0060]/ />`)) {
71
- } else if (yield eatMatch(m`<TagString /t["'\u0060]/ />`)) {
72
- } else if (yield eatMatch(m`<NodeString /n["'\u0060]/ />`)) {
73
- } else if (yield eatMatch(m`<RegexString /re["'\u0060]/ />`)) {
74
- } else if (yield eatMatch(m`<InstructionString /i["'\u0060]/ />`)) {
75
- } else {
76
- yield eat(m`:JSON: <String /["']/ />`);
63
+ let res = yield match(
64
+ m`/[+-]Infinity|[\d[{'"-]|null|undefined|true|false|(?:m|t|n|re|i)\u0060/`,
65
+ );
66
+ switch (printSource(res)) {
67
+ case '+Infinity':
68
+ case '-Infinity':
69
+ case 'Infinity':
70
+ yield eat(m`:IJSON: <Infinity />`);
71
+ break;
72
+ case '[':
73
+ yield eat(m`:IJSON: <Array />`);
74
+ break;
75
+ case '{':
76
+ yield eat(m`:IJSON: <Object />`);
77
+ break;
78
+ case "'":
79
+ case '"':
80
+ yield eat(m`:IJSON: <String />`);
81
+ break;
82
+ case 'true':
83
+ case 'false':
84
+ yield eat(m`:IJSON: <Boolean />`);
85
+ break;
86
+ case 'null':
87
+ yield eat(m`:IJSON: <Null />`);
88
+ break;
89
+ case 'undefined':
90
+ yield eat(m`:IJSON: <Undefined />`);
91
+ break;
92
+ case 'm`':
93
+ yield eat(m`<SpamexString />`);
94
+ break;
95
+ case 't`':
96
+ yield eat(m`<TagString />`);
97
+ break;
98
+ case 'n`':
99
+ yield eat(m`<NodeString />`);
100
+ break;
101
+ case 'i`':
102
+ yield eat(m`<InstructionString />`);
103
+ break;
104
+ default:
105
+ yield eat(m`:IJSON: <Number />`);
106
+ break;
77
107
  }
78
108
  }
79
109
 
80
110
  *SpamexString() {
81
111
  yield eat(m`sigilToken*: <*Keyword 'm' />`);
82
- let quot = buildString(printSource(yield match(re`/['"\u0060]/`)));
112
+ let quot = buildString(printSource(yield match(m`/['"\u0060]/`)));
83
113
  yield eat(m`openToken*: <* ${quot} />`);
84
114
  yield eat(m`content$: :Spamex: <_Matcher />`);
85
115
  yield eat(m`closeToken*: <* ${quot} />`);
@@ -87,7 +117,7 @@ export const grammar = class BABLRVMInstructionGrammar {
87
117
 
88
118
  *TagString() {
89
119
  yield eat(m`sigilToken*: <*Keyword 't' />`);
90
- let quot = buildString(printSource(yield match(re`/['"\u0060]/`)));
120
+ let quot = buildString(printSource(yield match(m`/['"\u0060]/`)));
91
121
  yield eat(m`openToken*: <* ${quot} />`);
92
122
  yield eat(m`content$: :CSTML: <_Tag />`);
93
123
  yield eat(m`closeToken*: <* ${quot} />`);
@@ -95,23 +125,15 @@ export const grammar = class BABLRVMInstructionGrammar {
95
125
 
96
126
  *NodeString() {
97
127
  yield eat(m`sigilToken*: <*Keyword 'n' />`);
98
- let quot = buildString(printSource(yield match(re`/['"\u0060]/`)));
128
+ let quot = buildString(printSource(yield match(m`/['"\u0060]/`)));
99
129
  yield eat(m`openToken*: <* ${quot} />`);
100
130
  yield eat(m`content$: :CSTML: <_Node />`);
101
131
  yield eat(m`closeToken*: <* ${quot} />`);
102
132
  }
103
133
 
104
- *RegexString() {
105
- yield eat(m`sigilToken*: <*Keyword 're' />`);
106
- let quot = buildString(printSource(yield match(re`/['"\u0060]/`)));
107
- yield eat(m`openToken*: <* ${quot} />`);
108
- yield eat(m`content$: :Regex: <Pattern />`);
109
- yield eat(m`closeToken*: <* ${quot} />`);
110
- }
111
-
112
134
  *InstructionString() {
113
135
  yield eat(m`sigilToken*: <*Keyword 'i' />`);
114
- let quot = buildString(printSource(yield match(re`/['"\u0060]/`)));
136
+ let quot = buildString(printSource(yield match(m`/['"\u0060]/`)));
115
137
  yield eat(m`openToken*: <* ${quot} />`);
116
138
  yield eat(m`content$: <Call />`);
117
139
  yield eat(m`closeToken*: <* ${quot} />`);
@@ -122,8 +144,8 @@ export const grammar = class BABLRVMInstructionGrammar {
122
144
  }
123
145
 
124
146
  *Identifier() {
125
- yield eat(re`/[a-zA-Z]+/`);
147
+ yield eat(m`/[a-zA-Z]+/`);
126
148
  }
127
- };
149
+ }
128
150
 
129
- export default { canonicalURL, dependencies, grammar, defaultMatcher };
151
+ freezeClass(BABLRVMInstruction);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bablr/language-en-bablr-vm-instruction",
3
- "version": "0.11.7",
3
+ "version": "0.12.0",
4
4
  "description": "A BABLR language for BABLR VM instructions",
5
5
  "engines": {
6
6
  "node": ">=12.0.0"
@@ -15,18 +15,17 @@
15
15
  ],
16
16
  "sideEffects": false,
17
17
  "dependencies": {
18
- "@bablr/agast-helpers": "0.10.4",
19
- "@bablr/agast-vm-helpers": "0.10.4",
20
- "@bablr/boot": "0.11.3",
21
- "@bablr/helpers": "0.25.2",
22
- "@bablr/language-en-blank-space": "0.10.12",
23
- "@bablr/language-en-cstml": "0.12.5",
24
- "@bablr/language-en-regex-vm-pattern": "0.12.4",
25
- "@bablr/language-en-spamex": "0.11.7",
26
- "@bablr/language-en-cstml-json": "0.5.4"
18
+ "@bablr/agast-helpers": "0.11.3",
19
+ "@bablr/agast-vm-helpers": "0.11.3",
20
+ "@bablr/helpers": "0.26.4",
21
+ "@bablr/language-en-blank-space": "0.11.1",
22
+ "@bablr/language-en-cstml": "0.13.0",
23
+ "@bablr/language-en-regex-vm-pattern": "0.13.0",
24
+ "@bablr/language-en-spamex": "0.12.1",
25
+ "@bablr/language-en-cstml-json": "0.6.0"
27
26
  },
28
27
  "devDependencies": {
29
- "@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#c97bfa4b3663f8378e9b3e42bb5a41e685406cf9",
28
+ "@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#23b94fb3bdfdbc3ac7ed9cb58d7979d8f07dce2b",
30
29
  "enhanced-resolve": "^5.12.0",
31
30
  "eslint": "^8.47.0",
32
31
  "eslint-import-resolver-enhanced-resolve": "^1.0.5",