@bablr/language-en-cstml-json 0.2.0 → 0.4.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,50 +1,122 @@
1
1
  /* @macrome
2
2
  * @generatedby @bablr/macrome-generator-bablr
3
- * @generatedfrom ./grammar.macro.js#9ffcbbc77664d07e4bf9c4a31213ed360b26c007
3
+ * @generatedfrom ./grammar.macro.js#a9659e5fbbb99478498fa677705cdb98fb38dd6c
4
4
  * This file is autogenerated. Please do not edit it directly.
5
5
  * When editing run `npx macrome watch` then change the file this is generated from.
6
6
  */
7
7
  import _applyDecs from "@babel/runtime/helpers/applyDecs2305";
8
8
  var _JSON$grammar;
9
- let _initProto, _NotANumberDecs, _UndefinedDecs;
10
- import { re, spam as m } from '@bablr/boot';
11
- import { extendLanguage, o, eat, match } from '@bablr/helpers/grammar';
12
- import { CoveredBy, Node, InjectFrom } from '@bablr/helpers/decorators';
9
+ let _initProto, _StringDecs, _NotANumberDecs, _UndefinedDecs, _InfinityDecs;
10
+ 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
13
  import * as JSON from '@bablr/language-en-json';
14
- import * as productions from '@bablr/helpers/productions';
15
14
  import { buildString } from '@bablr/helpers/builders';
15
+ import { basicTriviaEnhancer } from '@bablr/helpers/trivia';
16
16
  export const canonicalURL = 'https://bablr.org/languages/core/en/cstml-json';
17
17
  export const {
18
18
  dependencies
19
19
  } = JSON;
20
- export const getCooked = (escapeNode, span, ctx) => {
21
- let cooked = JSON.getCooked(escapeNode, span, ctx);
22
- if (cooked >= '\uD800' && cooked <= '\uDFFF') {
23
- throw new Error('unpaired surrogates are invalid in CSTML JSON');
24
- }
25
- return cooked;
26
- };
27
- export const grammar = class BABLRVMInstructionGrammar extends (_JSON$grammar = JSON.grammar) {
20
+ 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) {
28
25
  static {
29
- [_initProto] = _applyDecs(this, [[_NotANumberDecs, 2, "NotANumber"], [_UndefinedDecs, 2, "Undefined"]], [], 0, void 0, _JSON$grammar).e;
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;
30
27
  }
31
28
  constructor(...args) {
32
29
  super(...args);
33
30
  _initProto(this);
34
31
  }
35
- *[(_NotANumberDecs = [CoveredBy('Expression'), Node], _UndefinedDecs = [CoveredBy('Expression'), Node], "Expression")](props) {
32
+ *[(_StringDecs = [CoveredBy('Expression'), Node], _NotANumberDecs = [CoveredBy('Expression'), Node], _UndefinedDecs = [CoveredBy('Expression'), Node], _InfinityDecs = [CoveredBy('Expression'), Node], "Expression")](props) {
36
33
  if (yield match('NaN')) {
37
34
  yield eat(m`<NotANumber />`);
38
35
  } else if (yield match('undefined')) {
39
36
  yield eat(m`<Undefined />`);
40
- } else {
37
+ } else if (yield eatMatch(m`<Infinity /[+-]?Infinity/ />`)) {} else {
41
38
  yield* super.Expression(props);
42
39
  }
43
40
  }
41
+ *String({
42
+ ctx
43
+ }) {
44
+ let q = yield match(re`/['"]/`);
45
+ 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' } />`);
48
+ yield eat(m`content$: <*StringContent />`);
49
+ yield q_ === "'" ? eat(m`closeToken: <*Punctuator "'" { balancer: true } />`) : eat(m`closeToken: <*Punctuator '"' { balancer: true } />`);
50
+ }
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
+ *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
+ }
82
+ }
83
+ *IdentifierContent({
84
+ props: {
85
+ quoted = false
86
+ }
87
+ }) {
88
+ let lit, esc;
89
+ do {
90
+ if (esc = yield match('\\')) {
91
+ esc = yield eatMatch(m`@: <EscapeSequence />`);
92
+ } 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
+ }
98
+ }
99
+ } while (lit || esc);
100
+ }
44
101
  *NotANumber() {
45
102
  yield eat(m`sigilToken: <*Keyword 'NaN' />`);
46
103
  }
47
104
  *Undefined() {
48
105
  yield eat(m`sigilToken: <*Keyword 'undefined' />`);
49
106
  }
50
- };
107
+ *EscapeSequence(args) {
108
+ yield* super.EscapeSequence(args);
109
+ let {
110
+ cooked
111
+ } = args.s.node.attributes;
112
+ if (cooked >= '\uD800' && cooked <= '\uDFFF') {
113
+ throw new Error('unpaired surrogates are invalid in CSTML JSON');
114
+ }
115
+ }
116
+ *Infinity() {
117
+ yield eatMatch(m`signToken: <*Punctuator /[+-]/ />`, null, o({
118
+ bind: true
119
+ }));
120
+ yield eat(m`sigilToken: <*Keyword 'Infinity' />`);
121
+ }
122
+ });
@@ -1,44 +1,136 @@
1
- import { re, spam as m } from '@bablr/boot';
2
- import { extendLanguage, o, eat, match } from '@bablr/helpers/grammar';
3
- import { CoveredBy, Node, InjectFrom } from '@bablr/helpers/decorators';
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
4
  import * as JSON from '@bablr/language-en-json';
5
- import * as productions from '@bablr/helpers/productions';
6
5
  import { buildString } from '@bablr/helpers/builders';
6
+ import { basicTriviaEnhancer } from '@bablr/helpers/trivia';
7
7
 
8
8
  export const canonicalURL = 'https://bablr.org/languages/core/en/cstml-json';
9
9
 
10
10
  export const { dependencies } = JSON;
11
11
 
12
- export const getCooked = (escapeNode, span, ctx) => {
13
- let cooked = JSON.getCooked(escapeNode, span, ctx);
14
-
15
- if (cooked >= '\uD800' && cooked <= '\uDFFF') {
16
- throw new Error('unpaired surrogates are invalid in CSTML JSON');
17
- }
18
-
19
- return cooked;
20
- };
21
-
22
- export const grammar = class BABLRVMInstructionGrammar extends JSON.grammar {
23
- *Expression(props) {
24
- if (yield match('NaN')) {
25
- yield eat(m`<NotANumber />`);
26
- } else if (yield match('undefined')) {
27
- yield eat(m`<Undefined />`);
28
- } else {
29
- yield* super.Expression(props);
30
- }
31
- }
32
-
33
- @CoveredBy('Expression')
34
- @Node
35
- *NotANumber() {
36
- yield eat(m`sigilToken: <*Keyword 'NaN' />`);
37
- }
38
-
39
- @CoveredBy('Expression')
40
- @Node
41
- *Undefined() {
42
- yield eat(m`sigilToken: <*Keyword 'undefined' />`);
43
- }
44
- };
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
+ );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bablr/language-en-cstml-json",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "A BABLR language for CSTML-style JSON",
5
5
  "engines": {
6
6
  "node": ">=12.0.0"
@@ -17,32 +17,37 @@
17
17
  "scripts": {
18
18
  "build": "macrome build",
19
19
  "watch": "macrome watch",
20
- "clean": "macrome clean"
20
+ "clean": "macrome clean",
21
+ "test": "mocha"
21
22
  },
22
23
  "dependencies": {
23
- "@babel/runtime": "^7.22.15",
24
- "@bablr/agast-helpers": "0.7.1",
25
- "@bablr/agast-vm-helpers": "0.7.1",
26
- "@bablr/boot": "0.8.1",
27
- "@bablr/helpers": "0.22.1",
28
- "@bablr/language-en-json": "0.10.0"
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"
29
30
  },
30
31
  "devDependencies": {
32
+ "bablr": "^0.10.0",
31
33
  "@bablr/macrome": "^0.1.3",
32
34
  "@bablr/macrome-generator-bablr": "^0.3.2",
33
35
  "@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#49f5952efed27f94ee9b94340eb1563c440bf64e",
36
+ "@qnighy/dedent": "0.1.1",
34
37
  "enhanced-resolve": "^5.12.0",
35
38
  "eslint": "^8.47.0",
36
39
  "eslint-import-resolver-enhanced-resolve": "^1.0.5",
37
40
  "eslint-plugin-import": "^2.27.5",
41
+ "iter-tools-es": "^7.5.3",
42
+ "mocha": "10.4.0",
43
+ "expect": "29.7.0",
38
44
  "prettier": "^2.0.5"
39
45
  },
40
46
  "keywords": [
41
47
  "bablr-language",
42
48
  "grammar",
43
49
  "english",
44
- "comment",
45
- "c"
50
+ "json"
46
51
  ],
47
52
  "repository": "git@github.com:bablr-lang/language-en-cstml-json.git",
48
53
  "homepage": "https://github.com/bablr-lang/language-en-cstml-json",