@bablr/language-en-bablr-vm-instruction 0.6.1 → 0.7.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.
@@ -1,141 +1,109 @@
1
- import { i } from '@bablr/boot/shorthand.macro';
1
+ import { re, spam as m } from '@bablr/boot';
2
+ import { extendLanguage, o, eat, match } from '@bablr/helpers/grammar';
2
3
  import { CoveredBy, Node, InjectFrom } from '@bablr/helpers/decorators';
3
4
  import * as Space from '@bablr/language-en-blank-space';
5
+ import * as CSTML from '@bablr/language-en-cstml';
6
+ import * as Spamex from '@bablr/language-en-spamex';
7
+ import * as Regex from '@bablr/language-en-regex-vm-pattern';
8
+ import * as JSON from '@bablr/language-en-cstml-json';
4
9
  import * as productions from '@bablr/helpers/productions';
10
+ import { buildString } from '@bablr/helpers/builders';
5
11
 
6
12
  export const canonicalURL = 'https://bablr.org/languages/core/en/bablr-vm-instruction';
7
13
 
8
- export const dependencies = { Space };
9
-
10
14
  export function* eatMatchTrivia() {
11
- if (yield i`match(/[ \t\n]/)`) {
12
- return yield i`eat(<#*Space:Space />)`;
15
+ if (yield match(re`/[ \t\n]/`)) {
16
+ return yield eat(m`#: <*Space:Space />`);
13
17
  }
14
18
  return null;
15
19
  }
16
20
 
21
+ const IJSON = extendLanguage(JSON, {
22
+ canonicalURL: 'https://bablr.org/languages/core/en/bablr-vm-instruction-json',
23
+ dependencies: {
24
+ Instruction: canonicalURL,
25
+ },
26
+ grammar: class IJSON extends JSON.grammar {
27
+ *Expression(props) {
28
+ if (yield match(re`/(m|re|t)['"\u0060]/`)) {
29
+ yield eat(m`<Instruction:Expression />`);
30
+ } else {
31
+ yield* super.Expression(props);
32
+ }
33
+ }
34
+ },
35
+ });
36
+
37
+ export const dependencies = { Space, CSTML, Spamex, Regex, JSON, IJSON };
38
+
17
39
  export const grammar = class BABLRVMInstructionGrammar {
18
40
  @Node
19
41
  *Call() {
20
- yield i`eat(<*Identifier /> 'callee$')`;
42
+ yield eat(m`callee$: <*Identifier />`);
21
43
  yield* eatMatchTrivia();
22
- yield i`eat(<Tuple /> 'arguments$')`;
23
- }
24
44
 
25
- *Expression() {
26
- yield i`eat(<Any /> null [
27
- <Array '[' />
28
- <Object '{' />
29
- <Tuple '(' />
30
- <*Boolean /true|false/ />
31
- <*Null 'null' />
32
- <*Identifier /[a-zA-Z]+/ />
33
- <Number /[\d]|[+-]?Infinity/ />
34
- ])`;
35
- }
36
-
37
- @CoveredBy('Expression')
38
- @Node
39
- *Array() {
40
- yield i`eat(<*Punctuator '[' balanced=']' /> 'openToken')`;
45
+ yield eat(m`openToken: <*Punctuator '(' { balanced: ')' } />`);
41
46
  let sp = yield* eatMatchTrivia();
42
47
  let first = true;
43
- while ((first || sp) && (yield i`match(/./y)`)) {
44
- yield i`eat(<Expression /> 'elements[]$')`;
48
+ while ((first || sp) && (yield match(re`/./s`))) {
49
+ yield eat(m`values[]$: <Expression />`);
45
50
  sp = yield* eatMatchTrivia();
46
51
  first = false;
47
52
  }
48
- yield i`eat(<*Punctuator ']' balancer /> 'closeToken')`;
53
+ yield eat(m`closeToken: <*Punctuator ')' { balancer: true } />`);
49
54
  }
50
55
 
51
- @CoveredBy('Expression')
52
- @Node
53
- *Object() {
54
- yield i`eat(<*Punctuator '{' balanced='}' /> 'openToken')`;
55
- let sp = yield* eatMatchTrivia();
56
- let first = true;
57
- while ((first || sp) && (yield i`match(/./y)`)) {
58
- yield i`eat(<Property /> 'properties[]$')`;
59
- sp = yield* eatMatchTrivia();
60
- first = false;
61
- }
62
- yield i`eat(<*Punctuator '}' balancer /> 'closeToken')`;
56
+ *Expression() {
57
+ yield eat(m`<Any />`, [
58
+ m`<IJSON:Array '[' />`,
59
+ m`<IJSON:Object '{' />`,
60
+ m`<*JSON:Boolean /true|false/ />`,
61
+ m`<*JSON:Null 'null' />`,
62
+ m`<JSON:Number /[\d]|[+-]?Infinity/ />`,
63
+ m`<SpamexString /m["'\u0060]/ />`,
64
+ m`<CSTMLString /t["'\u0060]/ />`,
65
+ m`<RegexString /re["'\u0060]/ />`,
66
+ m`<JSON:String /["']/ />`,
67
+ ]);
63
68
  }
64
69
 
65
70
  @Node
66
- *Property() {
67
- yield i`eat(<*Identifier /> 'key$')`;
68
- yield* eatMatchTrivia();
69
- yield i`eat(<*Punctuator ':' /> 'mapToken')`;
70
- yield* eatMatchTrivia();
71
- yield i`eat(<Expression /> 'value$')`;
71
+ *SpamexString({ ctx }) {
72
+ yield eat(m`sigilToken: <*Keyword 'm' />`);
73
+ let quot = buildString(ctx.sourceTextFor(yield match(re`/['"\u0060]/`)));
74
+ yield eat(m`openToken: <*Punctuator ${quot} { balanced: ${quot} } />`);
75
+ yield eat(m`content: <Spamex:Matcher />`);
76
+ yield eat(m`closeToken: <*Punctuator ${quot} { balancer: true } />`);
72
77
  }
73
78
 
74
- @CoveredBy('Expression')
75
79
  @Node
76
- *Tuple() {
77
- yield i`eat(<*Punctuator '(' balanced=')' /> 'openToken')`;
78
- let sp = yield* eatMatchTrivia();
79
- let first = true;
80
- while ((first || sp) && (yield i`match(/./y)`)) {
81
- yield i`eat(<Expression /> 'values[]$')`;
82
- sp = yield* eatMatchTrivia();
83
- first = false;
84
- }
85
- yield i`eat(<*Punctuator ')' balancer /> 'closeToken')`;
80
+ *CSTMLString({ ctx }) {
81
+ yield eat(m`sigilToken: <*Keyword 't' />`);
82
+ let quot = buildString(ctx.sourceTextFor(yield match(re`/['"\u0060]/`)));
83
+ yield eat(m`openToken: <*Punctuator ${quot} { balanced: ${quot} } />`);
84
+ yield eat(m`content: <CSTML:Tag />`);
85
+ yield eat(m`closeToken: <*Punctuator ${quot} { balancer: true } />`);
86
86
  }
87
87
 
88
- @CoveredBy('Expression')
89
88
  @Node
90
- *Boolean() {
91
- yield i`eat(<*Keyword /true|false/ /> 'sigilToken')`;
89
+ *RegexString({ ctx }) {
90
+ yield eat(m`sigilToken: <*Keyword 're' />`);
91
+ let quot = buildString(ctx.sourceTextFor(yield match(re`/['"\u0060]/`)));
92
+ yield eat(m`openToken: <*Punctuator ${quot} { balanced: ${quot} } />`);
93
+ yield eat(m`content: <Regex:Pattern />`);
94
+ yield eat(m`closeToken: <*Punctuator ${quot} { balancer: true } />`);
92
95
  }
93
96
 
97
+ @CoveredBy('IJSONExpression')
94
98
  @CoveredBy('Expression')
95
99
  @Node
96
- *Null() {
97
- yield i`eat(<*Keyword 'null' /> 'sigilToken')`;
100
+ *String() {
101
+ yield eat(m`<IJSON:String />`, null, o({ suppressNode: true }));
98
102
  }
99
103
 
100
- @CoveredBy('Expression')
101
104
  @Node
102
105
  *Identifier() {
103
- yield i`eat(/[a-zA-Z]+/)`;
104
- }
105
-
106
- *Number() {
107
- yield i`eat(<Any /> null [
108
- <Integer /-?\d/ />
109
- <Infinity /[+-]I/ />
110
- ])`;
111
- }
112
-
113
- @Node
114
- *UnsignedInteger() {
115
- yield i`eat(<Digits /> 'digits[]')`;
116
- }
117
-
118
- @CoveredBy('Number')
119
- @Node
120
- *Integer() {
121
- yield i`eatMatch(<*Punctuator '-' /> 'negativeToken')`;
122
- yield i`eat(<Digits /> 'digits[]$')`;
123
- }
124
-
125
- *Digits() {
126
- while (yield i`eatMatch(<*Digit /\d/ />)`);
127
- }
128
-
129
- @Node
130
- *Digit() {
131
- yield i`eat(/\d/)`;
132
- }
133
-
134
- @CoveredBy('Number')
135
- @Node
136
- *Infinity() {
137
- yield i`eatMatch(<*Punctuator /[+-]/ /> 'signToken')`;
138
- yield i`eat(<*Keyword 'Infinity' /> 'sigilToken')`;
106
+ yield eat(re`/[a-zA-Z]+/`);
139
107
  }
140
108
 
141
109
  @Node
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bablr/language-en-bablr-vm-instruction",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "A BABLR language for BABLR VM instructions",
5
5
  "engines": {
6
6
  "node": ">=12.0.0"
@@ -23,15 +23,17 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@babel/runtime": "^7.23.2",
26
- "@bablr/agast-helpers": "^0.5.0",
27
- "@bablr/agast-vm-helpers": "^0.5.0",
28
- "@bablr/helpers": "^0.20.0",
29
- "@bablr/language-en-blank-space": "^0.5.0",
30
- "@bablr/language-en-cstml": "^0.6.0",
31
- "@bablr/language-en-spamex": "^0.6.0"
26
+ "@bablr/agast-helpers": "0.6.0",
27
+ "@bablr/agast-vm-helpers": "0.6.0",
28
+ "@bablr/helpers": "0.21.1",
29
+ "@bablr/language-en-blank-space": "0.6.0",
30
+ "@bablr/language-en-cstml": "0.8.0",
31
+ "@bablr/language-en-regex-vm-pattern": "0.8.0",
32
+ "@bablr/language-en-spamex": "0.7.0",
33
+ "@bablr/language-en-cstml-json": "0.1.0"
32
34
  },
33
35
  "devDependencies": {
34
- "@bablr/boot": "^0.6.0",
36
+ "@bablr/boot": "^0.7.0",
35
37
  "@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#49f5952efed27f94ee9b94340eb1563c440bf64e",
36
38
  "@bablr/macrome": "^0.1.3",
37
39
  "@bablr/macrome-generator-bablr": "^0.3.2",
@@ -1,44 +0,0 @@
1
- /* @macrome
2
- * @generatedby @bablr/macrome-generator-bablr
3
- * @generatedfrom ./cstml.grammar.macro.js#0e9820643a50afc4f9566750d5a2f9f5ab0e8ffd
4
- * This file is autogenerated. Please do not edit it directly.
5
- * When editing run `npx macrome watch` then change the file this is generated from.
6
- */
7
- import { interpolateArray as _interpolateArray, interpolateFragmentChildren as _interpolateFragmentChildren, interpolateString as _interpolateString } from "@bablr/agast-helpers/template";
8
- import * as _l from "@bablr/agast-vm-helpers/languages";
9
- import * as _t from "@bablr/agast-helpers/shorthand";
10
- import * as CSTML from '@bablr/language-en-cstml';
11
- import * as Instruction from './grammar.js';
12
- export const canonicalURL = 'https://bablr.org/languages/core/en/bablr-vm-cstml-instruction';
13
- export const dependencies = {
14
- ...Instruction.dependencies,
15
- CSTML
16
- };
17
- export const grammar = class BABLRVMSpamexInstructionGrammar extends Instruction.grammar {
18
- *Expression() {
19
- if (yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
20
- verb: _t.s_node(_l.Instruction, "Identifier", "eatMatch"),
21
- arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`openToken`, _t.ref`values[]`, _t.arr(), _t.ref`values[]`, _t.ref`closeToken`], {
22
- openToken: _t.s_node(_l.Instruction, "Punctuator", "("),
23
- values: [_t.node(_l.Spamex, "NodeMatcher", [_t.ref`open`], {
24
- open: _t.node(_l.Spamex, "OpenNodeMatcher", [_t.ref`openToken`, _t.ref`flags`, _t.ref`language`, _t.ref`namespaceSeparatorToken`, _t.ref`type`, _t.embedded(_t.node(_l.Spamex, "Space", [_t.lit(" ")], {}, {})), _t.ref`selfClosingTagToken`, _t.ref`closeToken`], {
25
- openToken: _t.s_node(_l.Spamex, "Punctuator", "<"),
26
- flags: _t.node(_l.CSTML, "Flags", [], {}, {}),
27
- language: _t.node(_l.CSTML, "IdentifierPath", [_t.ref`segments[]`, _t.arr(), _t.ref`segments[]`], {
28
- segments: [_t.s_node(_l.CSTML, "Identifier", "CSTML")]
29
- }, {}),
30
- namespaceSeparatorToken: _t.s_node(_l.CSTML, "Punctuator", ":"),
31
- type: _t.s_node(_l.CSTML, "Identifier", "Tag"),
32
- selfClosingTagToken: _t.s_node(_l.Spamex, "Punctuator", "/"),
33
- closeToken: _t.s_node(_l.Spamex, "Punctuator", ">")
34
- }, {})
35
- }, {})],
36
- closeToken: _t.s_node(_l.Instruction, "Punctuator", ")")
37
- }, {})
38
- }, {})) {
39
- // done
40
- } else {
41
- yield* super.Expression();
42
- }
43
- }
44
- };
@@ -1,17 +0,0 @@
1
- import { i } from '@bablr/boot/shorthand.macro';
2
- import * as CSTML from '@bablr/language-en-cstml';
3
- import * as Instruction from './grammar.js';
4
-
5
- export const canonicalURL = 'https://bablr.org/languages/core/en/bablr-vm-cstml-instruction';
6
-
7
- export const dependencies = { ...Instruction.dependencies, CSTML };
8
-
9
- export const grammar = class BABLRVMSpamexInstructionGrammar extends Instruction.grammar {
10
- *Expression() {
11
- if (yield i`eatMatch(<CSTML:Tag />)`) {
12
- // done
13
- } else {
14
- yield* super.Expression();
15
- }
16
- }
17
- };
@@ -1,57 +0,0 @@
1
- /* @macrome
2
- * @generatedby @bablr/macrome-generator-bablr
3
- * @generatedfrom ./spamex.grammar.macro.js#50b55ad80fe83916d9ab600b27e0c4ae14fe1399
4
- * This file is autogenerated. Please do not edit it directly.
5
- * When editing run `npx macrome watch` then change the file this is generated from.
6
- */
7
- import { interpolateArray as _interpolateArray, interpolateFragmentChildren as _interpolateFragmentChildren, interpolateString as _interpolateString } from "@bablr/agast-helpers/template";
8
- import * as _l from "@bablr/agast-vm-helpers/languages";
9
- import * as _t from "@bablr/agast-helpers/shorthand";
10
- import * as Spamex from '@bablr/language-en-spamex';
11
- import * as Instruction from './grammar.js';
12
- export const canonicalURL = 'https://bablr.org/languages/core/en/bablr-vm-spamex-instruction';
13
- export const dependencies = {
14
- ...Instruction.dependencies,
15
- Spamex
16
- };
17
- export const grammar = class BABLRVMSpamexInstructionGrammar extends Instruction.grammar {
18
- *Expression() {
19
- if (yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
20
- verb: _t.s_node(_l.Instruction, "Identifier", "eatMatch"),
21
- arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`openToken`, _t.ref`values[]`, _t.arr(), _t.ref`values[]`, _t.ref`closeToken`], {
22
- openToken: _t.s_node(_l.Instruction, "Punctuator", "("),
23
- values: [_t.node(_l.Spamex, "NodeMatcher", [_t.ref`open`], {
24
- open: _t.node(_l.Spamex, "OpenNodeMatcher", [10, [[_t.ref`openToken`, _t.ref`flags`, _t.ref`language`, _t.ref`namespaceSeparatorToken`], [_t.ref`type`, _t.embedded(_t.node(_l.Spamex, "Space", [_t.lit(" ")], {}, {})), _t.ref`intrinsicValue`, _t.embedded(_t.node(_l.Spamex, "Space", [_t.lit(" ")], {}, {})), _t.ref`selfClosingTagToken`, _t.ref`closeToken`]]], {
25
- openToken: _t.s_node(_l.Spamex, "Punctuator", "<"),
26
- flags: _t.node(_l.CSTML, "Flags", [], {}, {}),
27
- language: _t.node(_l.CSTML, "IdentifierPath", [_t.ref`segments[]`, _t.arr(), _t.ref`segments[]`], {
28
- segments: [_t.s_node(_l.CSTML, "Identifier", "Spamex")]
29
- }, {}),
30
- namespaceSeparatorToken: _t.s_node(_l.CSTML, "Punctuator", ":"),
31
- type: _t.s_node(_l.CSTML, "Identifier", "Matcher"),
32
- intrinsicValue: _t.node(_l.Regex, "Pattern", [_t.ref`openToken`, _t.ref`alternatives[]`, _t.arr(), _t.ref`alternatives[]`, _t.ref`closeToken`], {
33
- openToken: _t.s_node(_l.Regex, "Punctuator", "/"),
34
- alternatives: [_t.node(_l.Regex, "Alternative", [_t.ref`elements[]`, _t.arr(), _t.ref`elements[]`], {
35
- elements: [_t.node(_l.Regex, "CharacterClass", [_t.ref`openToken`, _t.ref`elements[]`, _t.arr(), _t.ref`elements[]`, _t.ref`elements[]`, _t.ref`elements[]`, _t.ref`elements[]`, _t.ref`closeToken`], {
36
- openToken: _t.s_node(_l.Regex, "Punctuator", "["),
37
- elements: [_t.node(_l.Regex, "Character", [_t.lit("<")], {}, {}), _t.node(_l.Regex, "Character", [_t.lit("'")], {}, {}), _t.node(_l.Regex, "Character", [_t.lit("\"")], {}, {}), _t.node(_l.Regex, "Character", [_t.lit("/")], {}, {})],
38
- closeToken: _t.s_node(_l.Regex, "Punctuator", "]")
39
- }, {
40
- negate: false
41
- })]
42
- }, {})],
43
- closeToken: _t.s_node(_l.Regex, "Punctuator", "/")
44
- }, {}),
45
- selfClosingTagToken: _t.s_node(_l.Spamex, "Punctuator", "/"),
46
- closeToken: _t.s_node(_l.Spamex, "Punctuator", ">")
47
- }, {})
48
- }, {})],
49
- closeToken: _t.s_node(_l.Instruction, "Punctuator", ")")
50
- }, {})
51
- }, {})) {
52
- // done
53
- } else {
54
- yield* super.Expression();
55
- }
56
- }
57
- };
@@ -1,17 +0,0 @@
1
- import { i } from '@bablr/boot/shorthand.macro';
2
- import * as Spamex from '@bablr/language-en-spamex';
3
- import * as Instruction from './grammar.js';
4
-
5
- export const canonicalURL = 'https://bablr.org/languages/core/en/bablr-vm-spamex-instruction';
6
-
7
- export const dependencies = { ...Instruction.dependencies, Spamex };
8
-
9
- export const grammar = class BABLRVMSpamexInstructionGrammar extends Instruction.grammar {
10
- *Expression() {
11
- if (yield i`eatMatch(<Spamex:Matcher /[<'"/]/ />)`) {
12
- // done
13
- } else {
14
- yield* super.Expression();
15
- }
16
- }
17
- };