@bablr/language-en-cstml-json 0.4.0 → 0.5.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.
package/lib/grammar.js CHANGED
@@ -1,122 +1,100 @@
1
- /* @macrome
2
- * @generatedby @bablr/macrome-generator-bablr
3
- * @generatedfrom ./grammar.macro.js#a9659e5fbbb99478498fa677705cdb98fb38dd6c
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 _applyDecs from "@babel/runtime/helpers/applyDecs2305";
8
- var _JSON$grammar;
9
- let _initProto, _StringDecs, _NotANumberDecs, _UndefinedDecs, _InfinityDecs;
10
1
  import { spam as m, re } from '@bablr/boot';
11
- import { o, eat, eatMatch, match, fail } from '@bablr/helpers/grammar';
12
- import { CoveredBy, Node } from '@bablr/helpers/decorators';
13
- import * as JSON from '@bablr/language-en-json';
2
+ import { o, eat, eatMatch, match, fail, startSpan, endSpan } from '@bablr/helpers/grammar';
3
+ import { default as JSON, dependencies } from '@bablr/language-en-json';
14
4
  import { buildString } from '@bablr/helpers/builders';
15
- import { basicTriviaEnhancer } from '@bablr/helpers/trivia';
5
+ import { printSource } from '@bablr/agast-helpers/tree';
6
+
16
7
  export const canonicalURL = 'https://bablr.org/languages/core/en/cstml-json';
17
- export const {
18
- dependencies
19
- } = JSON;
8
+
20
9
  export const defaultMatcher = m`<_Expression />`;
21
- export const grammar = basicTriviaEnhancer({
22
- triviaIsAllowed: s => s.span === 'Bare',
23
- triviaMatcher: m`#: :Space: <__Blank /[ \n\r\t]/ />`
24
- }, class CSTMLJSONGrammar extends (_JSON$grammar = JSON.grammar) {
25
- static {
26
- [_initProto] = _applyDecs(this, [[_StringDecs, 2, "String"], [Node, 2, "Property"], [Node, 2, "Identifier"], [Node, 2, "IdentifierContent"], [_NotANumberDecs, 2, "NotANumber"], [_UndefinedDecs, 2, "Undefined"], [Node, 2, "EscapeSequence"], [_InfinityDecs, 2, "Infinity"]], [], 0, void 0, _JSON$grammar).e;
10
+
11
+ export function* eatMatchTrivia() {
12
+ let trivia = null;
13
+ while (yield match(re`/[ \t\r\n]/`)) {
14
+ trivia = yield eat(m`#: :Space: <_Blank />`);
27
15
  }
28
- constructor(...args) {
29
- super(...args);
30
- _initProto(this);
31
- }
32
- *[(_StringDecs = [CoveredBy('Expression'), Node], _NotANumberDecs = [CoveredBy('Expression'), Node], _UndefinedDecs = [CoveredBy('Expression'), Node], _InfinityDecs = [CoveredBy('Expression'), Node], "Expression")](props) {
16
+ return trivia;
17
+ }
18
+
19
+ export const grammar = class CSTMLJSONGrammar extends JSON.grammar {
20
+ *Expression(props) {
33
21
  if (yield match('NaN')) {
34
22
  yield eat(m`<NotANumber />`);
35
23
  } else if (yield match('undefined')) {
36
24
  yield eat(m`<Undefined />`);
37
- } else if (yield eatMatch(m`<Infinity /[+-]?Infinity/ />`)) {} else {
25
+ } else if (yield eatMatch(m`<Infinity /[+-]?Infinity/ />`)) {
26
+ } else {
38
27
  yield* super.Expression(props);
39
28
  }
40
29
  }
41
- *String({
42
- ctx
43
- }) {
30
+
31
+ *String() {
44
32
  let q = yield match(re`/['"]/`);
33
+
45
34
  if (!q) yield fail();
46
- const q_ = ctx.sourceTextFor(q);
47
- yield q_ === "'" ? eat(m`openToken: <*Punctuator "'" { balanced: "'", balancedSpan: 'String:Single' } />`) : eat(m`openToken: <*Punctuator '"' { balanced: '"', balancedSpan: 'String:Double' } />`);
35
+
36
+ const q_ = printSource(q);
37
+
38
+ yield q_ === "'" ? eat(m`openToken*: <* "'" />`) : eat(m`openToken*: <* '"' />`);
39
+ let span = q_ === "'" ? 'String:Single' : 'String:Double';
40
+ yield startSpan(span, q_);
48
41
  yield eat(m`content$: <*StringContent />`);
49
- yield q_ === "'" ? eat(m`closeToken: <*Punctuator "'" { balancer: true } />`) : eat(m`closeToken: <*Punctuator '"' { balancer: true } />`);
42
+ yield endSpan();
43
+ yield q_ === "'" ? eat(m`closeToken*: <* "'" />`) : eat(m`closeToken*: <* '"' />`);
50
44
  }
45
+
51
46
  *Property() {
52
47
  if (yield match(re`/['"]/`)) {
53
48
  yield eatMatch(m`key$: <String />`);
54
49
  } else {
55
50
  yield eatMatch(m`key$: <Identifier />`);
56
51
  }
57
- yield eat(m`sigilToken: <*Punctuator ':' />`);
52
+
53
+ yield* eatMatchTrivia();
54
+ yield eat(m`sigilToken*: <* ':' />`);
55
+ yield* eatMatchTrivia();
58
56
  yield eat(m`value+$: <_Expression />`);
59
57
  }
60
- *Identifier({
61
- ctx
62
- }) {
63
- let q;
64
- let pn = ctx.sourceTextFor(yield match(re`/["']/`));
65
- if (pn) {
66
- q = yield eatMatch(m`openToken: <*Punctuator ${buildString(pn)} { balanced: ${buildString(pn)} } />`, o({}), o({
67
- bind: true
68
- }));
69
- } else {
70
- q = yield eat(m`openToken: null`);
71
- }
72
- yield eat(m`content: <*IdentifierContent { span: 'Identifier' } />`, o({
73
- quoted: !!q
74
- }));
75
- if (q) {
76
- yield eat(m`closeToken: <*Punctuator ${buildString(pn)} { balancer: true } />`, o({}), o({
77
- bind: true
78
- }));
79
- } else {
80
- yield eat(m`closeToken: null`);
81
- }
58
+
59
+ *Identifier() {
60
+ yield eat(m`content*: <*IdentifierContent />`);
82
61
  }
83
- *IdentifierContent({
84
- props: {
85
- quoted = false
86
- }
87
- }) {
62
+
63
+ *IdentifierContent() {
88
64
  let lit, esc;
89
65
  do {
90
- if (esc = yield match('\\')) {
66
+ if ((esc = yield match('\\'))) {
91
67
  esc = yield eatMatch(m`@: <EscapeSequence />`);
92
68
  } else {
93
- if (!quoted) {
94
- lit = yield eatMatch(re`/[a-zA-Z\u{80}-\u{10ffff}][a-zA-Z0-9_\u{80}-\u{10ffff}-]*/`);
95
- } else {
96
- lit = yield eatMatch(re`/[^\u0060\r\n]+/`);
97
- }
69
+ lit = yield eatMatch(re`/[a-zA-Z\u{80}-\u{10ffff}][a-zA-Z0-9_\u{80}-\u{10ffff}-]*/`);
98
70
  }
99
71
  } while (lit || esc);
100
72
  }
73
+
101
74
  *NotANumber() {
102
- yield eat(m`sigilToken: <*Keyword 'NaN' />`);
75
+ yield eat(m`sigilToken*: <*Keyword 'NaN' />`);
103
76
  }
77
+
104
78
  *Undefined() {
105
- yield eat(m`sigilToken: <*Keyword 'undefined' />`);
79
+ yield eat(m`sigilToken*: <*Keyword 'undefined' />`);
106
80
  }
81
+
107
82
  *EscapeSequence(args) {
108
83
  yield* super.EscapeSequence(args);
109
- let {
110
- cooked
111
- } = args.s.node.attributes;
84
+
85
+ let s = args.getState();
86
+
87
+ let { cooked } = s.node.value.attributes;
88
+
112
89
  if (cooked >= '\uD800' && cooked <= '\uDFFF') {
113
90
  throw new Error('unpaired surrogates are invalid in CSTML JSON');
114
91
  }
115
92
  }
93
+
116
94
  *Infinity() {
117
- yield eatMatch(m`signToken: <*Punctuator /[+-]/ />`, null, o({
118
- bind: true
119
- }));
120
- yield eat(m`sigilToken: <*Keyword 'Infinity' />`);
95
+ yield eatMatch(m`signToken*: <* /[+-]/ />`);
96
+ yield eat(m`sigilToken*: <*Keyword 'Infinity' />`);
121
97
  }
122
- });
98
+ };
99
+
100
+ export default { canonicalURL, dependencies, grammar, defaultMatcher };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bablr/language-en-cstml-json",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "A BABLR language for CSTML-style JSON",
5
5
  "engines": {
6
6
  "node": ">=12.0.0"
@@ -15,23 +15,17 @@
15
15
  ],
16
16
  "sideEffects": false,
17
17
  "scripts": {
18
- "build": "macrome build",
19
- "watch": "macrome watch",
20
- "clean": "macrome clean",
21
18
  "test": "mocha"
22
19
  },
23
20
  "dependencies": {
24
- "@babel/runtime": "7.28.2",
25
- "@bablr/agast-helpers": "0.9.0",
26
- "@bablr/agast-vm-helpers": "0.9.0",
27
- "@bablr/boot": "0.10.0",
28
- "@bablr/helpers": "0.24.0",
29
- "@bablr/language-en-json": "0.12.0"
21
+ "@bablr/agast-helpers": "0.10.0",
22
+ "@bablr/agast-vm-helpers": "0.10.0",
23
+ "@bablr/boot": "0.11.0",
24
+ "@bablr/helpers": "0.25.0",
25
+ "@bablr/language-en-json": "0.13.0"
30
26
  },
31
27
  "devDependencies": {
32
- "bablr": "^0.10.0",
33
- "@bablr/macrome": "^0.1.3",
34
- "@bablr/macrome-generator-bablr": "^0.3.2",
28
+ "bablr": "^0.11.0",
35
29
  "@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#49f5952efed27f94ee9b94340eb1563c440bf64e",
36
30
  "@qnighy/dedent": "0.1.1",
37
31
  "enhanced-resolve": "^5.12.0",
@@ -49,7 +43,10 @@
49
43
  "english",
50
44
  "json"
51
45
  ],
52
- "repository": "git@github.com:bablr-lang/language-en-cstml-json.git",
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+ssh://git@github.com/bablr-lang/language-en-cstml-json.git"
49
+ },
53
50
  "homepage": "https://github.com/bablr-lang/language-en-cstml-json",
54
51
  "author": "Conrad Buck <conartist6@gmail.com>",
55
52
  "license": "MIT"
@@ -1,136 +0,0 @@
1
- import { spam as m, re } from '@bablr/boot';
2
- import { o, eat, eatMatch, match, fail } from '@bablr/helpers/grammar';
3
- import { CoveredBy, Node } from '@bablr/helpers/decorators';
4
- import * as JSON from '@bablr/language-en-json';
5
- import { buildString } from '@bablr/helpers/builders';
6
- import { basicTriviaEnhancer } from '@bablr/helpers/trivia';
7
-
8
- export const canonicalURL = 'https://bablr.org/languages/core/en/cstml-json';
9
-
10
- export const { dependencies } = JSON;
11
-
12
- export const defaultMatcher = m`<_Expression />`;
13
-
14
- export const grammar = basicTriviaEnhancer(
15
- {
16
- triviaIsAllowed: (s) => s.span === 'Bare',
17
- triviaMatcher: m`#: :Space: <__Blank /[ \n\r\t]/ />`,
18
- },
19
-
20
- class CSTMLJSONGrammar extends JSON.grammar {
21
- *Expression(props) {
22
- if (yield match('NaN')) {
23
- yield eat(m`<NotANumber />`);
24
- } else if (yield match('undefined')) {
25
- yield eat(m`<Undefined />`);
26
- } else if (yield eatMatch(m`<Infinity /[+-]?Infinity/ />`)) {
27
- } else {
28
- yield* super.Expression(props);
29
- }
30
- }
31
-
32
- @CoveredBy('Expression')
33
- @Node
34
- *String({ ctx }) {
35
- let q = yield match(re`/['"]/`);
36
-
37
- if (!q) yield fail();
38
-
39
- const q_ = ctx.sourceTextFor(q);
40
-
41
- yield q_ === "'"
42
- ? eat(m`openToken: <*Punctuator "'" { balanced: "'", balancedSpan: 'String:Single' } />`)
43
- : eat(m`openToken: <*Punctuator '"' { balanced: '"', balancedSpan: 'String:Double' } />`);
44
-
45
- yield eat(m`content$: <*StringContent />`);
46
-
47
- yield q_ === "'"
48
- ? eat(m`closeToken: <*Punctuator "'" { balancer: true } />`)
49
- : eat(m`closeToken: <*Punctuator '"' { balancer: true } />`);
50
- }
51
-
52
- @Node
53
- *Property() {
54
- if (yield match(re`/['"]/`)) {
55
- yield eatMatch(m`key$: <String />`);
56
- } else {
57
- yield eatMatch(m`key$: <Identifier />`);
58
- }
59
- yield eat(m`sigilToken: <*Punctuator ':' />`);
60
- yield eat(m`value+$: <_Expression />`);
61
- }
62
-
63
- @Node
64
- *Identifier({ ctx }) {
65
- let q;
66
- let pn = ctx.sourceTextFor(yield match(re`/["']/`));
67
-
68
- if (pn) {
69
- q = yield eatMatch(
70
- m`openToken: <*Punctuator ${buildString(pn)} { balanced: ${buildString(pn)} } />`,
71
- o({}),
72
- o({ bind: true }),
73
- );
74
- } else {
75
- q = yield eat(m`openToken: null`);
76
- }
77
-
78
- yield eat(m`content: <*IdentifierContent { span: 'Identifier' } />`, o({ quoted: !!q }));
79
- if (q) {
80
- yield eat(
81
- m`closeToken: <*Punctuator ${buildString(pn)} { balancer: true } />`,
82
- o({}),
83
- o({ bind: true }),
84
- );
85
- } else {
86
- yield eat(m`closeToken: null`);
87
- }
88
- }
89
-
90
- @Node
91
- *IdentifierContent({ props: { quoted = false } }) {
92
- let lit, esc;
93
- do {
94
- if ((esc = yield match('\\'))) {
95
- esc = yield eatMatch(m`@: <EscapeSequence />`);
96
- } else {
97
- if (!quoted) {
98
- lit = yield eatMatch(re`/[a-zA-Z\u{80}-\u{10ffff}][a-zA-Z0-9_\u{80}-\u{10ffff}-]*/`);
99
- } else {
100
- lit = yield eatMatch(re`/[^\u0060\r\n]+/`);
101
- }
102
- }
103
- } while (lit || esc);
104
- }
105
-
106
- @CoveredBy('Expression')
107
- @Node
108
- *NotANumber() {
109
- yield eat(m`sigilToken: <*Keyword 'NaN' />`);
110
- }
111
-
112
- @CoveredBy('Expression')
113
- @Node
114
- *Undefined() {
115
- yield eat(m`sigilToken: <*Keyword 'undefined' />`);
116
- }
117
-
118
- @Node
119
- *EscapeSequence(args) {
120
- yield* super.EscapeSequence(args);
121
-
122
- let { cooked } = args.s.node.attributes;
123
-
124
- if (cooked >= '\uD800' && cooked <= '\uDFFF') {
125
- throw new Error('unpaired surrogates are invalid in CSTML JSON');
126
- }
127
- }
128
-
129
- @CoveredBy('Expression')
130
- @Node
131
- *Infinity() {
132
- yield eatMatch(m`signToken: <*Punctuator /[+-]/ />`, null, o({ bind: true }));
133
- yield eat(m`sigilToken: <*Keyword 'Infinity' />`);
134
- }
135
- },
136
- );