@bablr/language-en-spamex 0.6.0 → 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,125 +1,146 @@
1
- import { i } from '@bablr/boot/shorthand.macro';
1
+ import { re, spam as m } from '@bablr/boot';
2
2
  import { Node, CoveredBy, InjectFrom, UnboundAttributes } from '@bablr/helpers/decorators';
3
3
  import * as productions from '@bablr/helpers/productions';
4
+ import { o, eat, eatMatch, match, bindAttribute, fail } from '@bablr/helpers/grammar';
4
5
  import * as Regex from '@bablr/language-en-regex-vm-pattern';
5
6
  import * as CSTML from '@bablr/language-en-cstml';
7
+ import * as JSON from '@bablr/language-en-cstml-json';
6
8
  import * as Space from '@bablr/language-en-blank-space';
7
9
  import { notNull } from '@bablr/agast-helpers/tree';
8
10
 
9
11
  export const canonicalURL = 'https://bablr.org/languages/core/en/spamex';
10
12
 
11
- export const dependencies = { Regex, CSTML, Space };
13
+ export const dependencies = { Regex, CSTML, JSON, Space };
12
14
 
13
15
  const { eatMatchTrivia } = CSTML;
14
16
 
15
17
  export const grammar = class SpamexGrammar {
16
18
  @CoveredBy('Expression')
17
19
  *Matcher() {
18
- yield i`eat(<Any /> null [
19
- <NodeMatcher '<' />
20
- <CSTML:String /['"]/ />
21
- <Regex:Pattern '/' />
22
- ])`;
20
+ yield eat(m`<Any />`, [m`<PropertyMatcher /[a-zA-Z.@#<]/ />`, m`<StringMatcher /[/'"]/ />`]);
21
+ }
22
+
23
+ *NodeMatcher() {
24
+ yield eat(m`<Any />`, [
25
+ m`<GapNodeMatcher '<//>' />`,
26
+ m`<BasicNodeMatcher '<' />`,
27
+ m`<ArrayNodeMatcher '[' />`,
28
+ m`<NullNodeMatcher 'null' />`,
29
+ ]);
30
+ }
31
+
32
+ @Node
33
+ @CoveredBy('NodeMatcher')
34
+ *GapNodeMatcher() {
35
+ yield eat(m`sigilToken: <*Punctuator '<//>' />`);
36
+ }
37
+
38
+ @Node
39
+ @CoveredBy('NodeMatcher')
40
+ *ArrayNodeMatcher() {
41
+ yield eat(m`sigilToken: <*Punctuator '[]' />`);
42
+ }
43
+
44
+ @Node
45
+ @CoveredBy('NodeMatcher')
46
+ *NullNodeMatcher() {
47
+ yield eat(m`sigilToken: <*Punctuator 'null' />`);
23
48
  }
24
49
 
25
50
  @Node
26
51
  @CoveredBy('Matcher')
27
- *NodeMatcher() {
28
- let open = yield i`eat(<OpenNodeMatcher /> 'open')`;
52
+ *PropertyMatcher() {
53
+ yield eatMatch(m`refMatcher: <ReferenceMatcher />`);
54
+ yield* eatMatchTrivia();
55
+ yield eat(m`nodeMatcher: <NodeMatcher />`);
56
+ }
57
+
58
+ @Node
59
+ *ReferenceMatcher() {
60
+ let name;
61
+ if (yield match(re`/[.#@]/`)) {
62
+ name = yield eatMatch(m`name$: <*Punctuator /[.#@]/ />`);
63
+ } else {
64
+ name = yield eatMatch(m`name$: <*CSTML:Identifier />`);
65
+ }
66
+
67
+ if (name && (yield eatMatch(m`openIndexToken: <*Punctuator '[' { balanced: ']' } />`))) {
68
+ yield* eatMatchTrivia();
69
+ yield eatMatch(m`closeIndexToken: <*Punctuator ']' { balancer: true } />`);
70
+ } else {
71
+ yield eatMatch(m`closeIndexToken: null`);
72
+ }
73
+
74
+ yield* eatMatchTrivia();
75
+ yield eatMatch(m`flags: <CSTML:ReferenceFlags />`);
76
+ yield* eatMatchTrivia();
77
+ yield eat(m`sigilToken: <*Punctuator ':' />`);
78
+ }
79
+
80
+ @Node
81
+ @CoveredBy('NodeMatcher')
82
+ *BasicNodeMatcher() {
83
+ let open = yield eat(m`open: <OpenNodeMatcher />`);
29
84
 
30
85
  const selfClosing = notNull(open.get('selfClosingTagToken'));
31
86
 
32
87
  if (selfClosing) {
33
- yield i`eat([] 'children[]$')`;
34
- yield i`eat(null 'close')`;
88
+ yield eat(m`children[]$: []`);
89
+ yield eat(m`close: null`);
35
90
  } else {
36
91
  // TODO
37
92
  yield* eatMatchTrivia();
38
93
 
39
- yield i`eat(<CloseNodeMatcher /> 'close')`;
94
+ yield eat(m`close: <CloseNodeMatcher />`);
40
95
  }
41
96
  }
42
97
 
43
98
  @Node
44
99
  *OpenNodeMatcher() {
45
- yield i`eat(<*Punctuator '<' balancedSpan='Tag' balanced='>' /> 'open')`;
46
- yield i`eat(<CSTML:Flags /> 'flags')`;
100
+ yield eat(m`open: <*Punctuator '<' { balancedSpan: 'Tag', balanced: '>' } />`);
101
+ yield eat(m`flags: <CSTML:NodeFlags />`);
47
102
 
48
- if (yield i`eatMatch(<CSTML:TagType /[a-zA-Z'"\g]/ />)`) {
103
+ if (yield eatMatch(m`<CSTML:TagType /[a-zA-Z'"\g]/ />`)) {
49
104
  // continue
50
- } else if (yield i`eatMatch(<*Punctuator /[ \t]+|?/ /> 'type$')`) {
105
+ } else if (yield eatMatch(m`type$: <*Punctuator /[ \t]+|?/ />`)) {
51
106
  // continue
107
+ } else {
108
+ yield fail();
52
109
  }
53
110
 
54
111
  let sp = yield* eatMatchTrivia();
55
112
 
56
113
  if (
57
114
  sp &&
58
- !(yield i`match(/\/$/)`) &&
59
- (yield i`eatMatch(<StringMatcher /> 'intrinsicValue$')`)
115
+ !(yield match(re`/\/$/`)) &&
116
+ (yield eatMatch(m`intrinsicValue$: <StringMatcher />`))
60
117
  ) {
61
118
  sp = yield* eatMatchTrivia();
62
119
  }
63
120
 
64
- while (sp && (yield i`match(/!?[a-zA-Z]/)`)) {
65
- yield i`eat(<Attribute /> 'attributes[]')`;
121
+ while (sp && (yield match('{'))) {
122
+ yield eat(m`attributes: <JSON:Object />`);
66
123
  sp = yield* eatMatchTrivia();
67
124
  }
68
125
 
69
- yield i`eatMatch(<*Punctuator '/' /> 'selfClosingTagToken')`;
70
- yield i`eat(<*Punctuator '>' balancer /> 'close')`;
126
+ yield eatMatch(m`selfClosingTagToken: <*Punctuator '/' />`);
127
+ yield eat(m`close: <*Punctuator '>' { balancer: true } />`);
71
128
  }
72
129
 
73
130
  @Node
74
131
  @CoveredBy('Matcher')
75
132
  *CloseNodeMatcher() {
76
- yield i`eat(<*Punctuator '</' balanced='>' /> 'openToken')`;
77
- yield i`eatMatch(<TagType />)`;
78
- yield i`eat(<*Punctuator '>' balancer /> 'closeToken')`;
79
- }
80
-
81
- *Attributes() {
82
- yield i`eatMatch(<List /> null {
83
- element: <Attribute />
84
- allowTrailingSeparator: false
85
- })`;
86
- }
87
-
88
- *Attribute() {
89
- if (yield i`match(/[a-zA-Z]+\s*=/)`) {
90
- yield i`eat(<MappingAttribute />)`;
91
- } else {
92
- yield i`eat(<BooleanAttribute />)`;
93
- }
94
- }
95
-
96
- @UnboundAttributes(['true'])
97
- @Node
98
- @CoveredBy('Attribute')
99
- *BooleanAttribute() {
100
- if (yield i`eatMatch(<*Punctuator '!' /> 'negateToken')`) {
101
- yield i`bindAttribute('true' false)`;
102
- } else {
103
- yield i`bindAttribute('true' true)`;
104
- }
105
- yield i`eat(<*CSTML:Identifier /> 'key$')`;
106
- }
107
-
108
- @CoveredBy('Attribute')
109
- @Node
110
- *MappingAttribute() {
111
- yield i`eat(<*CSTML:Identifier /> 'key$')`;
112
- yield i`eat(<*Punctuator '=' /> 'mapOperator')`;
113
- yield i`eat(<CSTML:AttributeValue /> 'value$')`;
133
+ yield eat(m`openToken: <*Punctuator '</' { balanced: '>' } />`);
134
+ yield eat(m`closeToken: <*Punctuator '>' { balancer: true } />`);
114
135
  }
115
136
 
116
137
  @CoveredBy('Matcher')
117
138
  @CoveredBy('Expression')
118
139
  *StringMatcher() {
119
- if (yield i`match(/['"]/)`) {
120
- yield i`eat(<CSTML:String />)`;
140
+ if (yield match(re`/['"]/`)) {
141
+ yield eat(m`<String />`);
121
142
  } else {
122
- yield i`eat(<Regex:Pattern />)`;
143
+ yield eat(m`<Regex />`);
123
144
  }
124
145
  }
125
146
 
@@ -128,7 +149,7 @@ export const grammar = class SpamexGrammar {
128
149
  @CoveredBy('Expression')
129
150
  @Node
130
151
  *String() {
131
- yield i`eat(<CSTML:String />)`;
152
+ yield eat(m`<JSON:String />`, null, o({ suppressNode: true }));
132
153
  }
133
154
 
134
155
  @CoveredBy('StringMatcher')
@@ -136,10 +157,7 @@ export const grammar = class SpamexGrammar {
136
157
  @CoveredBy('Expression')
137
158
  @Node
138
159
  *Regex() {
139
- yield i`eat(<*Punctuator '/' balanced='/' /> 'open')`;
140
- yield i`eat(<Regex:Alternatives /> 'alternatives[]$')`;
141
- yield i`eat(<*Punctuator '/' balancer /> 'close')`;
142
- yield i`eat(<Regex:Flags /> 'flags$')`;
160
+ yield eat(m`<Regex:Pattern />`, null, o({ suppressNode: true }));
143
161
  }
144
162
 
145
163
  @InjectFrom(productions)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bablr/language-en-spamex",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "A BABLR language for SPAM Expressions",
5
5
  "engines": {
6
6
  "node": ">=12.0.0"
@@ -22,15 +22,16 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@babel/runtime": "^7.23.2",
25
- "@bablr/agast-helpers": "^0.5.0",
26
- "@bablr/agast-vm-helpers": "^0.5.0",
27
- "@bablr/helpers": "^0.20.0",
28
- "@bablr/language-en-blank-space": "^0.5.0",
29
- "@bablr/language-en-cstml": "^0.6.0",
30
- "@bablr/language-en-regex-vm-pattern": "^0.7.0"
25
+ "@bablr/agast-helpers": "0.6.0",
26
+ "@bablr/agast-vm-helpers": "0.6.0",
27
+ "@bablr/helpers": "0.21.1",
28
+ "@bablr/language-en-blank-space": "0.6.0",
29
+ "@bablr/language-en-cstml": "0.8.0",
30
+ "@bablr/language-en-cstml-json": "0.1.0",
31
+ "@bablr/language-en-regex-vm-pattern": "0.8.0"
31
32
  },
32
33
  "devDependencies": {
33
- "@bablr/boot": "^0.6.0",
34
+ "@bablr/boot": "^0.7.0",
34
35
  "@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#49f5952efed27f94ee9b94340eb1563c440bf64e",
35
36
  "@bablr/macrome": "^0.1.3",
36
37
  "@bablr/macrome-generator-bablr": "^0.3.2",