@bablr/language-en-cstml-json 0.1.0 → 0.3.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,45 +1,121 @@
1
1
  /* @macrome
2
2
  * @generatedby @bablr/macrome-generator-bablr
3
- * @generatedfrom ./grammar.macro.js#0a642a38394d3786460fc65bbdb11a747007cd42
3
+ * @generatedfrom ./grammar.macro.js#f8e2c51c617b6c838e8b6f6b8894d8f5fa25d273
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, _NaNDecs;
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 grammar = basicTriviaEnhancer({
21
+ triviaIsAllowed: s => s.span === 'Bare',
22
+ triviaMatcher: m`#: :Space: <*Space /[ \n\r\t]/ />`
23
+ }, class CSTMLJSONGrammar extends (_JSON$grammar = JSON.grammar) {
28
24
  static {
29
- [_initProto] = _applyDecs(this, [[_NaNDecs, 2, "NaN"]], [], 0, void 0, _JSON$grammar).e;
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;
30
26
  }
31
27
  constructor(...args) {
32
28
  super(...args);
33
29
  _initProto(this);
34
30
  }
35
- *[(_NaNDecs = [CoveredBy('Expression'), Node], "Expression")](props) {
31
+ *[(_StringDecs = [CoveredBy('Expression'), Node], _NotANumberDecs = [CoveredBy('Expression'), Node], _UndefinedDecs = [CoveredBy('Expression'), Node], _InfinityDecs = [CoveredBy('Expression'), Node], "Expression")](props) {
36
32
  if (yield match('NaN')) {
37
- yield eat(m`<NaN />`);
38
- } else {
33
+ yield eat(m`<NotANumber />`);
34
+ } else if (yield match('undefined')) {
35
+ yield eat(m`<Undefined />`);
36
+ } else if (yield eatMatch(m`<Infinity /[+-]?Infinity/ />`)) {} else {
39
37
  yield* super.Expression(props);
40
38
  }
41
39
  }
42
- *NaN() {
40
+ *String({
41
+ ctx
42
+ }) {
43
+ let q = yield match(re`/['"]/`);
44
+ 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' } />`);
47
+ yield eat(m`content$: <*StringContent />`);
48
+ yield q_ === "'" ? eat(m`closeToken: <*Punctuator "'" { balancer: true } />`) : eat(m`closeToken: <*Punctuator '"' { balancer: true } />`);
49
+ }
50
+ *Property() {
51
+ if (yield match(re`/['"]/`)) {
52
+ yield eatMatch(m`key$: <String />`);
53
+ } else {
54
+ yield eatMatch(m`key$: <Identifier />`);
55
+ }
56
+ yield eat(m`sigilToken: <*Punctuator ':' />`);
57
+ yield eat(m`value+$: <__Expression />`);
58
+ }
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
+ }
81
+ }
82
+ *IdentifierContent({
83
+ props: {
84
+ quoted = false
85
+ }
86
+ }) {
87
+ let lit, esc;
88
+ do {
89
+ if (esc = yield match('\\')) {
90
+ esc = yield eatMatch(m`@: <EscapeSequence />`);
91
+ } 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
+ }
97
+ }
98
+ } while (lit || esc);
99
+ }
100
+ *NotANumber() {
43
101
  yield eat(m`sigilToken: <*Keyword 'NaN' />`);
44
102
  }
45
- };
103
+ *Undefined() {
104
+ yield eat(m`sigilToken: <*Keyword 'undefined' />`);
105
+ }
106
+ *EscapeSequence(args) {
107
+ yield* super.EscapeSequence(args);
108
+ let {
109
+ cooked
110
+ } = args.s.node.attributes;
111
+ if (cooked >= '\uD800' && cooked <= '\uDFFF') {
112
+ throw new Error('unpaired surrogates are invalid in CSTML JSON');
113
+ }
114
+ }
115
+ *Infinity() {
116
+ yield eatMatch(m`signToken: <*Punctuator /[+-]/ />`, null, o({
117
+ bind: true
118
+ }));
119
+ yield eat(m`sigilToken: <*Keyword 'Infinity' />`);
120
+ }
121
+ });
@@ -1,36 +1,134 @@
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);
12
+ export const grammar = basicTriviaEnhancer(
13
+ {
14
+ triviaIsAllowed: (s) => s.span === 'Bare',
15
+ triviaMatcher: m`#: :Space: <*Space /[ \n\r\t]/ />`,
16
+ },
14
17
 
15
- if (cooked >= '\uD800' && cooked <= '\uDFFF') {
16
- throw new Error('unpaired surrogates are invalid in CSTML JSON');
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`/["']/`));
18
65
 
19
- return cooked;
20
- };
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
+ }
21
75
 
22
- export const grammar = class BABLRVMInstructionGrammar extends JSON.grammar {
23
- *Expression(props) {
24
- if (yield match('NaN')) {
25
- yield eat(m`<NaN />`);
26
- } else {
27
- yield* super.Expression(props);
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
+ }
28
86
  }
29
- }
30
87
 
31
- @CoveredBy('Expression')
32
- @Node
33
- *NaN() {
34
- yield eat(m`sigilToken: <*Keyword 'NaN' />`);
35
- }
36
- };
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
+ );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bablr/language-en-cstml-json",
3
- "version": "0.1.0",
3
+ "version": "0.3.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
24
  "@babel/runtime": "^7.22.15",
24
- "@bablr/agast-helpers": "0.6.0",
25
- "@bablr/agast-vm-helpers": "0.6.0",
26
- "@bablr/helpers": "0.21.1",
27
- "@bablr/language-en-json": "0.9.0"
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"
28
30
  },
29
31
  "devDependencies": {
32
+ "bablr": "^0.9.0",
30
33
  "@bablr/macrome": "^0.1.3",
31
34
  "@bablr/macrome-generator-bablr": "^0.3.2",
32
- "@bablr/boot": "^0.7.0",
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",