@bablr/language-en-bablr-vm-instruction 0.6.1 → 0.8.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,121 @@
1
- import { i } from '@bablr/boot/shorthand.macro';
1
+ import { re, spam as m } from '@bablr/boot';
2
+ import { extendLanguage, o, eat, match, eatMatch } 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
 
17
- export const grammar = class BABLRVMInstructionGrammar {
18
- @Node
19
- *Call() {
20
- yield i`eat(<*Identifier /> 'callee$')`;
21
- yield* eatMatchTrivia();
22
- yield i`eat(<Tuple /> 'arguments$')`;
23
- }
24
-
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')`;
41
- let sp = yield* eatMatchTrivia();
42
- let first = true;
43
- while ((first || sp) && (yield i`match(/./y)`)) {
44
- yield i`eat(<Expression /> 'elements[]$')`;
45
- sp = yield* eatMatchTrivia();
46
- first = false;
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|i)['"\u0060]/`)) {
29
+ yield eat(m`<__Instruction:Expression />`);
30
+ } else {
31
+ yield* super.Expression(props);
32
+ }
47
33
  }
48
- yield i`eat(<*Punctuator ']' balancer /> 'closeToken')`;
49
- }
34
+ },
35
+ });
50
36
 
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')`;
63
- }
37
+ export const dependencies = { Space, CSTML, Spamex, Regex, JSON, IJSON };
64
38
 
39
+ export const grammar = class BABLRVMInstructionGrammar {
65
40
  @Node
66
- *Property() {
67
- yield i`eat(<*Identifier /> 'key$')`;
68
- yield* eatMatchTrivia();
69
- yield i`eat(<*Punctuator ':' /> 'mapToken')`;
41
+ *Call() {
42
+ yield eat(m`callee$: <*Identifier />`);
70
43
  yield* eatMatchTrivia();
71
- yield i`eat(<Expression /> 'value$')`;
72
- }
73
44
 
74
- @CoveredBy('Expression')
75
- @Node
76
- *Tuple() {
77
- yield i`eat(<*Punctuator '(' balanced=')' /> 'openToken')`;
45
+ yield eat(m`openToken: <*Punctuator '(' { balanced: ')' } />`);
78
46
  let sp = yield* eatMatchTrivia();
79
47
  let first = true;
80
- while ((first || sp) && (yield i`match(/./y)`)) {
81
- yield i`eat(<Expression /> 'values[]$')`;
82
- sp = yield* eatMatchTrivia();
48
+ while ((first || sp) && (yield match(re`/./s`))) {
49
+ yield eat(m`values[]$: <__Expression />`);
50
+ yield* eatMatchTrivia();
51
+ sp = yield eatMatch(m`separatorTokens[]: <*Punctuator ',' />`);
52
+ yield* eatMatchTrivia();
83
53
  first = false;
84
54
  }
85
- yield i`eat(<*Punctuator ')' balancer /> 'closeToken')`;
55
+ yield eat(m`closeToken: <*Punctuator ')' { balancer: true } />`);
86
56
  }
87
57
 
88
- @CoveredBy('Expression')
89
- @Node
90
- *Boolean() {
91
- yield i`eat(<*Keyword /true|false/ /> 'sigilToken')`;
58
+ *Expression() {
59
+ yield eat(m`<_Any />`, [
60
+ m`<IJSON:Array '[' />`,
61
+ m`<IJSON:Object '{' />`,
62
+ m`<JSON:Boolean /true|false/ />`,
63
+ m`<JSON:Null 'null' />`,
64
+ m`<JSON:Number /[\d]|[+-]?Infinity/ />`,
65
+ m`<SpamexString /m["'\u0060]/ />`,
66
+ m`<CSTMLString /t["'\u0060]/ />`,
67
+ m`<RegexString /re["'\u0060]/ />`,
68
+ m`<InstructionString /i["'\u0060]/ />`,
69
+ m`<JSON:String /["']/ />`,
70
+ ]);
92
71
  }
93
72
 
94
- @CoveredBy('Expression')
95
73
  @Node
96
- *Null() {
97
- yield i`eat(<*Keyword 'null' /> 'sigilToken')`;
74
+ *SpamexString({ ctx }) {
75
+ yield eat(m`sigilToken: <*Keyword 'm' />`);
76
+ let quot = buildString(ctx.sourceTextFor(yield match(re`/['"\u0060]/`)));
77
+ yield eat(m`openToken: <*Punctuator ${quot} { balanced: ${quot} } />`);
78
+ yield eat(m`content: <__Spamex:Matcher />`);
79
+ yield eat(m`closeToken: <*Punctuator ${quot} { balancer: true } />`);
98
80
  }
99
81
 
100
- @CoveredBy('Expression')
101
82
  @Node
102
- *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
- ])`;
83
+ *CSTMLString({ ctx }) {
84
+ yield eat(m`sigilToken: <*Keyword 't' />`);
85
+ let quot = buildString(ctx.sourceTextFor(yield match(re`/['"\u0060]/`)));
86
+ yield eat(m`openToken: <*Punctuator ${quot} { balanced: ${quot} } />`);
87
+ yield eat(m`content: <__CSTML:Tag />`);
88
+ yield eat(m`closeToken: <*Punctuator ${quot} { balancer: true } />`);
111
89
  }
112
90
 
113
91
  @Node
114
- *UnsignedInteger() {
115
- yield i`eat(<Digits /> 'digits[]')`;
92
+ *RegexString({ ctx }) {
93
+ yield eat(m`sigilToken: <*Keyword 're' />`);
94
+ let quot = buildString(ctx.sourceTextFor(yield match(re`/['"\u0060]/`)));
95
+ yield eat(m`openToken: <*Punctuator ${quot} { balanced: ${quot} } />`);
96
+ yield eat(m`content: <Regex:Pattern />`);
97
+ yield eat(m`closeToken: <*Punctuator ${quot} { balancer: true } />`);
116
98
  }
117
99
 
118
- @CoveredBy('Number')
119
100
  @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/ />)`);
101
+ *InstructionString({ ctx }) {
102
+ yield eat(m`sigilToken: <*Keyword 'i' />`);
103
+ let quot = buildString(ctx.sourceTextFor(yield match(re`/['"\u0060]/`)));
104
+ yield eat(m`openToken: <*Punctuator ${quot} { balanced: ${quot} } />`);
105
+ yield eat(m`content: <Call />`);
106
+ yield eat(m`closeToken: <*Punctuator ${quot} { balancer: true } />`);
127
107
  }
128
108
 
109
+ @CoveredBy('IJSONExpression')
110
+ @CoveredBy('Expression')
129
111
  @Node
130
- *Digit() {
131
- yield i`eat(/\d/)`;
112
+ *String() {
113
+ yield eat(m`<_IJSON:String />`);
132
114
  }
133
115
 
134
- @CoveredBy('Number')
135
116
  @Node
136
- *Infinity() {
137
- yield i`eatMatch(<*Punctuator /[+-]/ /> 'signToken')`;
138
- yield i`eat(<*Keyword 'Infinity' /> 'sigilToken')`;
117
+ *Identifier() {
118
+ yield eat(re`/[a-zA-Z]+/`);
139
119
  }
140
120
 
141
121
  @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.8.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.7.1",
27
+ "@bablr/agast-vm-helpers": "0.7.1",
28
+ "@bablr/boot": "0.8.1",
29
+ "@bablr/helpers": "0.22.1",
30
+ "@bablr/language-en-blank-space": "0.7.0",
31
+ "@bablr/language-en-cstml": "0.9.0",
32
+ "@bablr/language-en-regex-vm-pattern": "0.9.0",
33
+ "@bablr/language-en-spamex": "0.8.0",
34
+ "@bablr/language-en-cstml-json": "0.2.0"
32
35
  },
33
36
  "devDependencies": {
34
- "@bablr/boot": "^0.6.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
- };