@bablr/language-en-cstml-json 0.3.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,121 +1,100 @@
1
- /* @macrome
2
- * @generatedby @bablr/macrome-generator-bablr
3
- * @generatedfrom ./grammar.macro.js#f8e2c51c617b6c838e8b6f6b8894d8f5fa25d273
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;
20
- export const grammar = basicTriviaEnhancer({
21
- triviaIsAllowed: s => s.span === 'Bare',
22
- triviaMatcher: m`#: :Space: <*Space /[ \n\r\t]/ />`
23
- }, class CSTMLJSONGrammar extends (_JSON$grammar = JSON.grammar) {
24
- static {
25
- [_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;
8
+
9
+ export const defaultMatcher = m`<_Expression />`;
10
+
11
+ export function* eatMatchTrivia() {
12
+ let trivia = null;
13
+ while (yield match(re`/[ \t\r\n]/`)) {
14
+ trivia = yield eat(m`#: :Space: <_Blank />`);
26
15
  }
27
- constructor(...args) {
28
- super(...args);
29
- _initProto(this);
30
- }
31
- *[(_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) {
32
21
  if (yield match('NaN')) {
33
22
  yield eat(m`<NotANumber />`);
34
23
  } else if (yield match('undefined')) {
35
24
  yield eat(m`<Undefined />`);
36
- } else if (yield eatMatch(m`<Infinity /[+-]?Infinity/ />`)) {} else {
25
+ } else if (yield eatMatch(m`<Infinity /[+-]?Infinity/ />`)) {
26
+ } else {
37
27
  yield* super.Expression(props);
38
28
  }
39
29
  }
40
- *String({
41
- ctx
42
- }) {
30
+
31
+ *String() {
43
32
  let q = yield match(re`/['"]/`);
33
+
44
34
  if (!q) yield fail();
45
- const q_ = ctx.sourceTextFor(q);
46
- 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_);
47
41
  yield eat(m`content$: <*StringContent />`);
48
- 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*: <* '"' />`);
49
44
  }
45
+
50
46
  *Property() {
51
47
  if (yield match(re`/['"]/`)) {
52
48
  yield eatMatch(m`key$: <String />`);
53
49
  } else {
54
50
  yield eatMatch(m`key$: <Identifier />`);
55
51
  }
56
- yield eat(m`sigilToken: <*Punctuator ':' />`);
57
- yield eat(m`value+$: <__Expression />`);
52
+
53
+ yield* eatMatchTrivia();
54
+ yield eat(m`sigilToken*: <* ':' />`);
55
+ yield* eatMatchTrivia();
56
+ yield eat(m`value+$: <_Expression />`);
58
57
  }
59
- *Identifier({
60
- ctx
61
- }) {
62
- let q;
63
- let pn = ctx.sourceTextFor(yield match(re`/["']/`));
64
- if (pn) {
65
- q = yield eatMatch(m`openToken: <*Punctuator ${buildString(pn)} { balanced: ${buildString(pn)} } />`, o({}), o({
66
- bind: true
67
- }));
68
- } else {
69
- q = yield eat(m`openToken: null`);
70
- }
71
- yield eat(m`content: <*IdentifierContent { span: 'Identifier' } />`, o({
72
- quoted: !!q
73
- }));
74
- if (q) {
75
- yield eat(m`closeToken: <*Punctuator ${buildString(pn)} { balancer: true } />`, o({}), o({
76
- bind: true
77
- }));
78
- } else {
79
- yield eat(m`closeToken: null`);
80
- }
58
+
59
+ *Identifier() {
60
+ yield eat(m`content*: <*IdentifierContent />`);
81
61
  }
82
- *IdentifierContent({
83
- props: {
84
- quoted = false
85
- }
86
- }) {
62
+
63
+ *IdentifierContent() {
87
64
  let lit, esc;
88
65
  do {
89
- if (esc = yield match('\\')) {
66
+ if ((esc = yield match('\\'))) {
90
67
  esc = yield eatMatch(m`@: <EscapeSequence />`);
91
68
  } else {
92
- if (!quoted) {
93
- lit = yield eatMatch(re`/[a-zA-Z\u{80}-\u{10ffff}][a-zA-Z0-9_\u{80}-\u{10ffff}-]*/`);
94
- } else {
95
- lit = yield eatMatch(re`/[^\u0060\r\n]+/`);
96
- }
69
+ lit = yield eatMatch(re`/[a-zA-Z\u{80}-\u{10ffff}][a-zA-Z0-9_\u{80}-\u{10ffff}-]*/`);
97
70
  }
98
71
  } while (lit || esc);
99
72
  }
73
+
100
74
  *NotANumber() {
101
- yield eat(m`sigilToken: <*Keyword 'NaN' />`);
75
+ yield eat(m`sigilToken*: <*Keyword 'NaN' />`);
102
76
  }
77
+
103
78
  *Undefined() {
104
- yield eat(m`sigilToken: <*Keyword 'undefined' />`);
79
+ yield eat(m`sigilToken*: <*Keyword 'undefined' />`);
105
80
  }
81
+
106
82
  *EscapeSequence(args) {
107
83
  yield* super.EscapeSequence(args);
108
- let {
109
- cooked
110
- } = args.s.node.attributes;
84
+
85
+ let s = args.getState();
86
+
87
+ let { cooked } = s.node.value.attributes;
88
+
111
89
  if (cooked >= '\uD800' && cooked <= '\uDFFF') {
112
90
  throw new Error('unpaired surrogates are invalid in CSTML JSON');
113
91
  }
114
92
  }
93
+
115
94
  *Infinity() {
116
- yield eatMatch(m`signToken: <*Punctuator /[+-]/ />`, null, o({
117
- bind: true
118
- }));
119
- yield eat(m`sigilToken: <*Keyword 'Infinity' />`);
95
+ yield eatMatch(m`signToken*: <* /[+-]/ />`);
96
+ yield eat(m`sigilToken*: <*Keyword 'Infinity' />`);
120
97
  }
121
- });
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.3.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.22.15",
25
- "@bablr/agast-helpers": "0.8.0",
26
- "@bablr/agast-vm-helpers": "0.8.0",
27
- "@bablr/boot": "0.9.0",
28
- "@bablr/helpers": "0.23.0",
29
- "@bablr/language-en-json": "0.11.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.9.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,134 +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 grammar = basicTriviaEnhancer(
13
- {
14
- triviaIsAllowed: (s) => s.span === 'Bare',
15
- triviaMatcher: m`#: :Space: <*Space /[ \n\r\t]/ />`,
16
- },
17
-
18
- class CSTMLJSONGrammar extends JSON.grammar {
19
- *Expression(props) {
20
- if (yield match('NaN')) {
21
- yield eat(m`<NotANumber />`);
22
- } else if (yield match('undefined')) {
23
- yield eat(m`<Undefined />`);
24
- } else if (yield eatMatch(m`<Infinity /[+-]?Infinity/ />`)) {
25
- } else {
26
- yield* super.Expression(props);
27
- }
28
- }
29
-
30
- @CoveredBy('Expression')
31
- @Node
32
- *String({ ctx }) {
33
- let q = yield match(re`/['"]/`);
34
-
35
- if (!q) yield fail();
36
-
37
- const q_ = ctx.sourceTextFor(q);
38
-
39
- yield q_ === "'"
40
- ? eat(m`openToken: <*Punctuator "'" { balanced: "'", balancedSpan: 'String:Single' } />`)
41
- : eat(m`openToken: <*Punctuator '"' { balanced: '"', balancedSpan: 'String:Double' } />`);
42
-
43
- yield eat(m`content$: <*StringContent />`);
44
-
45
- yield q_ === "'"
46
- ? eat(m`closeToken: <*Punctuator "'" { balancer: true } />`)
47
- : eat(m`closeToken: <*Punctuator '"' { balancer: true } />`);
48
- }
49
-
50
- @Node
51
- *Property() {
52
- if (yield match(re`/['"]/`)) {
53
- yield eatMatch(m`key$: <String />`);
54
- } else {
55
- yield eatMatch(m`key$: <Identifier />`);
56
- }
57
- yield eat(m`sigilToken: <*Punctuator ':' />`);
58
- yield eat(m`value+$: <__Expression />`);
59
- }
60
-
61
- @Node
62
- *Identifier({ ctx }) {
63
- let q;
64
- let pn = ctx.sourceTextFor(yield match(re`/["']/`));
65
-
66
- if (pn) {
67
- q = yield eatMatch(
68
- m`openToken: <*Punctuator ${buildString(pn)} { balanced: ${buildString(pn)} } />`,
69
- o({}),
70
- o({ bind: true }),
71
- );
72
- } else {
73
- q = yield eat(m`openToken: null`);
74
- }
75
-
76
- yield eat(m`content: <*IdentifierContent { span: 'Identifier' } />`, o({ quoted: !!q }));
77
- if (q) {
78
- yield eat(
79
- m`closeToken: <*Punctuator ${buildString(pn)} { balancer: true } />`,
80
- o({}),
81
- o({ bind: true }),
82
- );
83
- } else {
84
- yield eat(m`closeToken: null`);
85
- }
86
- }
87
-
88
- @Node
89
- *IdentifierContent({ props: { quoted = false } }) {
90
- let lit, esc;
91
- do {
92
- if ((esc = yield match('\\'))) {
93
- esc = yield eatMatch(m`@: <EscapeSequence />`);
94
- } else {
95
- if (!quoted) {
96
- lit = yield eatMatch(re`/[a-zA-Z\u{80}-\u{10ffff}][a-zA-Z0-9_\u{80}-\u{10ffff}-]*/`);
97
- } else {
98
- lit = yield eatMatch(re`/[^\u0060\r\n]+/`);
99
- }
100
- }
101
- } while (lit || esc);
102
- }
103
-
104
- @CoveredBy('Expression')
105
- @Node
106
- *NotANumber() {
107
- yield eat(m`sigilToken: <*Keyword 'NaN' />`);
108
- }
109
-
110
- @CoveredBy('Expression')
111
- @Node
112
- *Undefined() {
113
- yield eat(m`sigilToken: <*Keyword 'undefined' />`);
114
- }
115
-
116
- @Node
117
- *EscapeSequence(args) {
118
- yield* super.EscapeSequence(args);
119
-
120
- let { cooked } = args.s.node.attributes;
121
-
122
- if (cooked >= '\uD800' && cooked <= '\uDFFF') {
123
- throw new Error('unpaired surrogates are invalid in CSTML JSON');
124
- }
125
- }
126
-
127
- @CoveredBy('Expression')
128
- @Node
129
- *Infinity() {
130
- yield eatMatch(m`signToken: <*Punctuator /[+-]/ />`, null, o({ bind: true }));
131
- yield eat(m`sigilToken: <*Keyword 'Infinity' />`);
132
- }
133
- },
134
- );