@aeriajs/compiler 0.0.12 → 0.0.15

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/dist/ast.d.ts CHANGED
@@ -9,6 +9,7 @@ export declare const PropertyType: {
9
9
  readonly enum: "enum";
10
10
  readonly date: "string";
11
11
  readonly datetime: "string";
12
+ readonly const: "const";
12
13
  };
13
14
  export declare const PropertyModifiers: Record<'Error' | 'Result', ExportSymbol>;
14
15
  export type ExportSymbol = {
package/dist/ast.js CHANGED
@@ -10,6 +10,7 @@ exports.PropertyType = {
10
10
  enum: 'enum',
11
11
  date: 'string',
12
12
  datetime: 'string',
13
+ const: 'const',
13
14
  };
14
15
  exports.PropertyModifiers = {
15
16
  Error: {
package/dist/ast.mjs CHANGED
@@ -7,7 +7,8 @@ export const PropertyType = {
7
7
  bool: "boolean",
8
8
  enum: "enum",
9
9
  date: "string",
10
- datetime: "string"
10
+ datetime: "string",
11
+ const: "const"
11
12
  };
12
13
  export const PropertyModifiers = {
13
14
  Error: {
package/dist/parser.js CHANGED
@@ -179,6 +179,9 @@ const parse = (tokens) => {
179
179
  array.push(identifier);
180
180
  symbols.push(elemSymbol);
181
181
  exports.locationMap.set(elemSymbol, location);
182
+ if (match(token_js_1.TokenType.Comma)) {
183
+ consume(token_js_1.TokenType.Comma);
184
+ }
182
185
  }
183
186
  consume(token_js_1.TokenType.RightBracket);
184
187
  return {
@@ -225,6 +228,22 @@ const parse = (tokens) => {
225
228
  ]).value;
226
229
  return;
227
230
  }
231
+ if ('const' in property && attributeName === 'value') {
232
+ const token = current();
233
+ advance();
234
+ switch (token.type) {
235
+ case token_js_1.TokenType.Number:
236
+ case token_js_1.TokenType.Boolean:
237
+ case token_js_1.TokenType.Null:
238
+ case token_js_1.TokenType.QuotedString: {
239
+ property.const = token.value;
240
+ return;
241
+ }
242
+ default: {
243
+ throw new diagnostic_js_1.Diagnostic(`const received invalid value: "${token.value}"`, location);
244
+ }
245
+ }
246
+ }
228
247
  switch (attributeName) {
229
248
  case 'icon': {
230
249
  const { value } = consume(token_js_1.TokenType.QuotedString, ICON_NAMES);
@@ -461,6 +480,12 @@ const parse = (tokens) => {
461
480
  };
462
481
  break;
463
482
  }
483
+ case 'const': {
484
+ property = {
485
+ const: null,
486
+ };
487
+ break;
488
+ }
464
489
  case 'date': {
465
490
  property = {
466
491
  type: 'string',
@@ -580,6 +605,30 @@ const parse = (tokens) => {
580
605
  }
581
606
  return parsePropertyType(options);
582
607
  };
608
+ const parseAccessCondition = (options = {
609
+ arrayBlock: false,
610
+ }) => {
611
+ if (match(token_js_1.TokenType.Boolean)) {
612
+ const { value } = consume(token_js_1.TokenType.Boolean);
613
+ return value;
614
+ }
615
+ else if (match(token_js_1.TokenType.QuotedString, [
616
+ 'unauthenticated',
617
+ 'unauthenticated-only',
618
+ ])) {
619
+ const { value } = consume(token_js_1.TokenType.QuotedString, [
620
+ 'unauthenticated',
621
+ 'unauthenticated-only',
622
+ ]);
623
+ return value;
624
+ }
625
+ else {
626
+ const { value, symbols } = options.arrayBlock
627
+ ? parseArrayBlock()
628
+ : parseArray([token_js_1.TokenType.QuotedString]);
629
+ return checkForValidRoles(value, symbols);
630
+ }
631
+ };
583
632
  const parseCollection = (ast) => {
584
633
  consume(token_js_1.TokenType.Keyword, 'collection');
585
634
  const { value: name } = consume(token_js_1.TokenType.Identifier);
@@ -681,23 +730,9 @@ const parse = (tokens) => {
681
730
  const { value: keyword } = consume(token_js_1.TokenType.Keyword, lexer.CONTRACT_KEYWORDS);
682
731
  switch (keyword) {
683
732
  case 'roles': {
684
- if (match(token_js_1.TokenType.Boolean)) {
685
- const { value: boolean } = consume(token_js_1.TokenType.Boolean);
686
- node.roles = boolean;
687
- }
688
- else if (match(token_js_1.TokenType.QuotedString, 'unauthenticated')) {
689
- consume(token_js_1.TokenType.QuotedString);
690
- node.roles = 'unauthenticated';
691
- }
692
- else if (match(token_js_1.TokenType.QuotedString, 'unauthenticated-only')) {
693
- consume(token_js_1.TokenType.QuotedString);
694
- node.roles = 'unauthenticated-only';
695
- }
696
- else {
697
- const { value, symbols } = parseArrayBlock();
698
- const roles = checkForValidRoles(value, symbols);
699
- node.roles = roles;
700
- }
733
+ node.roles = parseAccessCondition({
734
+ arrayBlock: true,
735
+ });
701
736
  break;
702
737
  }
703
738
  case 'payload': {
@@ -727,60 +762,52 @@ const parse = (tokens) => {
727
762
  consume(token_js_1.TokenType.LeftBracket);
728
763
  const functions = {};
729
764
  while (!match(token_js_1.TokenType.RightBracket)) {
730
- if (match(token_js_1.TokenType.MacroName)) {
731
- const { value: macroName } = consume(token_js_1.TokenType.MacroName, ['include']);
732
- switch (macroName) {
733
- case 'include': {
734
- const { value: functionSetName, location } = consume(token_js_1.TokenType.Identifier);
735
- const functionset = ast.functionsets.find((node) => node.name === functionSetName);
736
- if (!functionset) {
737
- throw new diagnostic_js_1.Diagnostic(`functionset "${functionSetName}" not found`, location);
765
+ try {
766
+ if (match(token_js_1.TokenType.MacroName)) {
767
+ const { value: macroName } = consume(token_js_1.TokenType.MacroName, ['include']);
768
+ switch (macroName) {
769
+ case 'include': {
770
+ const { value: functionSetName, location } = consume(token_js_1.TokenType.Identifier);
771
+ const functionset = ast.functionsets.find((node) => node.name === functionSetName);
772
+ if (!functionset) {
773
+ throw new diagnostic_js_1.Diagnostic(`functionset "${functionSetName}" not found`, location);
774
+ }
775
+ Object.assign(functions, functionset.functions);
776
+ consume(token_js_1.TokenType.RightParens);
738
777
  }
739
- Object.assign(functions, functionset.functions);
740
- consume(token_js_1.TokenType.RightParens);
741
778
  }
779
+ continue;
742
780
  }
743
- continue;
744
- }
745
- const { value: functionName } = consume(token_js_1.TokenType.Identifier);
746
- functions[functionName] = {
747
- accessCondition: false,
748
- };
749
- while (match(token_js_1.TokenType.AttributeName, 'expose')) {
750
- consume(token_js_1.TokenType.AttributeName, 'expose');
751
- if (match(token_js_1.TokenType.LeftParens)) {
752
- consume(token_js_1.TokenType.LeftParens);
753
- if (match(token_js_1.TokenType.Boolean)) {
754
- const { value } = consume(token_js_1.TokenType.Boolean);
755
- functions[functionName] = {
756
- accessCondition: value,
757
- };
758
- }
759
- else if (match(token_js_1.TokenType.QuotedString, [
760
- 'unauthenticated',
761
- 'unauthenticated-only',
762
- ])) {
763
- const { value } = consume(token_js_1.TokenType.QuotedString, [
764
- 'unauthenticated',
765
- 'unauthenticated-only',
766
- ]);
781
+ const { value: functionName } = consume(token_js_1.TokenType.Identifier);
782
+ functions[functionName] = {
783
+ accessCondition: false,
784
+ };
785
+ while (match(token_js_1.TokenType.AttributeName, 'expose')) {
786
+ consume(token_js_1.TokenType.AttributeName, 'expose');
787
+ if (match(token_js_1.TokenType.LeftParens)) {
788
+ consume(token_js_1.TokenType.LeftParens);
767
789
  functions[functionName] = {
768
- accessCondition: value,
790
+ accessCondition: parseAccessCondition(),
769
791
  };
792
+ consume(token_js_1.TokenType.RightParens);
770
793
  }
771
794
  else {
772
- const { value, symbols } = parseArray([token_js_1.TokenType.QuotedString]);
773
- const roles = checkForValidRoles(value, symbols);
774
795
  functions[functionName] = {
775
- accessCondition: roles,
796
+ accessCondition: true,
776
797
  };
777
798
  }
778
- consume(token_js_1.TokenType.RightParens);
779
799
  }
780
- else {
781
- functions[functionName] = {
782
- accessCondition: true,
783
- };
800
+ }
801
+ catch (err) {
802
+ if (err instanceof diagnostic_js_1.Diagnostic) {
803
+ let token;
804
+ while (token = tokens[++index]) {
805
+ if (token.type === token_js_1.TokenType.Identifier || token.type === token_js_1.TokenType.RightBracket) {
806
+ break;
807
+ }
808
+ }
809
+ errors.push(err);
810
+ continue;
784
811
  }
785
812
  }
786
813
  }
package/dist/parser.mjs CHANGED
@@ -141,6 +141,9 @@ export const parse = (tokens) => {
141
141
  array.push(identifier);
142
142
  symbols.push(elemSymbol);
143
143
  locationMap.set(elemSymbol, location);
144
+ if (match(TokenType.Comma)) {
145
+ consume(TokenType.Comma);
146
+ }
144
147
  }
145
148
  consume(TokenType.RightBracket);
146
149
  return {
@@ -184,6 +187,22 @@ export const parse = (tokens) => {
184
187
  ]).value;
185
188
  return;
186
189
  }
190
+ if ("const" in property && attributeName === "value") {
191
+ const token = current();
192
+ advance();
193
+ switch (token.type) {
194
+ case TokenType.Number:
195
+ case TokenType.Boolean:
196
+ case TokenType.Null:
197
+ case TokenType.QuotedString: {
198
+ property.const = token.value;
199
+ return;
200
+ }
201
+ default: {
202
+ throw new Diagnostic(`const received invalid value: "${token.value}"`, location);
203
+ }
204
+ }
205
+ }
187
206
  switch (attributeName) {
188
207
  case "icon": {
189
208
  const { value } = consume(TokenType.QuotedString, ICON_NAMES);
@@ -416,6 +435,12 @@ export const parse = (tokens) => {
416
435
  };
417
436
  break;
418
437
  }
438
+ case "const": {
439
+ property = {
440
+ const: null
441
+ };
442
+ break;
443
+ }
419
444
  case "date": {
420
445
  property = {
421
446
  type: "string",
@@ -531,6 +556,26 @@ export const parse = (tokens) => {
531
556
  }
532
557
  return parsePropertyType(options);
533
558
  };
559
+ const parseAccessCondition = (options = {
560
+ arrayBlock: false
561
+ }) => {
562
+ if (match(TokenType.Boolean)) {
563
+ const { value } = consume(TokenType.Boolean);
564
+ return value;
565
+ } else if (match(TokenType.QuotedString, [
566
+ "unauthenticated",
567
+ "unauthenticated-only"
568
+ ])) {
569
+ const { value } = consume(TokenType.QuotedString, [
570
+ "unauthenticated",
571
+ "unauthenticated-only"
572
+ ]);
573
+ return value;
574
+ } else {
575
+ const { value, symbols } = options.arrayBlock ? parseArrayBlock() : parseArray([TokenType.QuotedString]);
576
+ return checkForValidRoles(value, symbols);
577
+ }
578
+ };
534
579
  const parseCollection = (ast2) => {
535
580
  consume(TokenType.Keyword, "collection");
536
581
  const { value: name } = consume(TokenType.Identifier);
@@ -631,20 +676,9 @@ export const parse = (tokens) => {
631
676
  const { value: keyword } = consume(TokenType.Keyword, lexer.CONTRACT_KEYWORDS);
632
677
  switch (keyword) {
633
678
  case "roles": {
634
- if (match(TokenType.Boolean)) {
635
- const { value: boolean } = consume(TokenType.Boolean);
636
- node.roles = boolean;
637
- } else if (match(TokenType.QuotedString, "unauthenticated")) {
638
- consume(TokenType.QuotedString);
639
- node.roles = "unauthenticated";
640
- } else if (match(TokenType.QuotedString, "unauthenticated-only")) {
641
- consume(TokenType.QuotedString);
642
- node.roles = "unauthenticated-only";
643
- } else {
644
- const { value, symbols } = parseArrayBlock();
645
- const roles = checkForValidRoles(value, symbols);
646
- node.roles = roles;
647
- }
679
+ node.roles = parseAccessCondition({
680
+ arrayBlock: true
681
+ });
648
682
  break;
649
683
  }
650
684
  case "payload": {
@@ -674,57 +708,50 @@ export const parse = (tokens) => {
674
708
  consume(TokenType.LeftBracket);
675
709
  const functions = {};
676
710
  while (!match(TokenType.RightBracket)) {
677
- if (match(TokenType.MacroName)) {
678
- const { value: macroName } = consume(TokenType.MacroName, ["include"]);
679
- switch (macroName) {
680
- case "include": {
681
- const { value: functionSetName, location } = consume(TokenType.Identifier);
682
- const functionset = ast2.functionsets.find((node) => node.name === functionSetName);
683
- if (!functionset) {
684
- throw new Diagnostic(`functionset "${functionSetName}" not found`, location);
711
+ try {
712
+ if (match(TokenType.MacroName)) {
713
+ const { value: macroName } = consume(TokenType.MacroName, ["include"]);
714
+ switch (macroName) {
715
+ case "include": {
716
+ const { value: functionSetName, location } = consume(TokenType.Identifier);
717
+ const functionset = ast2.functionsets.find((node) => node.name === functionSetName);
718
+ if (!functionset) {
719
+ throw new Diagnostic(`functionset "${functionSetName}" not found`, location);
720
+ }
721
+ Object.assign(functions, functionset.functions);
722
+ consume(TokenType.RightParens);
685
723
  }
686
- Object.assign(functions, functionset.functions);
687
- consume(TokenType.RightParens);
688
724
  }
725
+ continue;
689
726
  }
690
- continue;
691
- }
692
- const { value: functionName } = consume(TokenType.Identifier);
693
- functions[functionName] = {
694
- accessCondition: false
695
- };
696
- while (match(TokenType.AttributeName, "expose")) {
697
- consume(TokenType.AttributeName, "expose");
698
- if (match(TokenType.LeftParens)) {
699
- consume(TokenType.LeftParens);
700
- if (match(TokenType.Boolean)) {
701
- const { value } = consume(TokenType.Boolean);
702
- functions[functionName] = {
703
- accessCondition: value
704
- };
705
- } else if (match(TokenType.QuotedString, [
706
- "unauthenticated",
707
- "unauthenticated-only"
708
- ])) {
709
- const { value } = consume(TokenType.QuotedString, [
710
- "unauthenticated",
711
- "unauthenticated-only"
712
- ]);
727
+ const { value: functionName } = consume(TokenType.Identifier);
728
+ functions[functionName] = {
729
+ accessCondition: false
730
+ };
731
+ while (match(TokenType.AttributeName, "expose")) {
732
+ consume(TokenType.AttributeName, "expose");
733
+ if (match(TokenType.LeftParens)) {
734
+ consume(TokenType.LeftParens);
713
735
  functions[functionName] = {
714
- accessCondition: value
736
+ accessCondition: parseAccessCondition()
715
737
  };
738
+ consume(TokenType.RightParens);
716
739
  } else {
717
- const { value, symbols } = parseArray([TokenType.QuotedString]);
718
- const roles = checkForValidRoles(value, symbols);
719
740
  functions[functionName] = {
720
- accessCondition: roles
741
+ accessCondition: true
721
742
  };
722
743
  }
723
- consume(TokenType.RightParens);
724
- } else {
725
- functions[functionName] = {
726
- accessCondition: true
727
- };
744
+ }
745
+ } catch (err) {
746
+ if (err instanceof Diagnostic) {
747
+ let token;
748
+ while (token = tokens[++index]) {
749
+ if (token.type === TokenType.Identifier || token.type === TokenType.RightBracket) {
750
+ break;
751
+ }
752
+ }
753
+ errors.push(err);
754
+ continue;
728
755
  }
729
756
  }
730
757
  }
package/dist/token.d.ts CHANGED
@@ -12,6 +12,7 @@ export declare const TokenType: {
12
12
  readonly Dot: "DOT";
13
13
  readonly Number: "NUMBER";
14
14
  readonly Boolean: "BOOLEAN";
15
+ readonly Null: "NULL";
15
16
  readonly Keyword: "KEYWORD";
16
17
  readonly Identifier: "IDENTIFIER";
17
18
  readonly QuotedString: "QUOTED_STRING";
@@ -23,6 +24,7 @@ export type TokenType = typeof TokenType[keyof typeof TokenType];
23
24
  export type TypeMap = {
24
25
  [TokenType.Number]: number;
25
26
  [TokenType.Boolean]: boolean;
27
+ [TokenType.Null]: null;
26
28
  [TokenType.Range]: readonly [number, number];
27
29
  };
28
30
  export type Location = {
package/dist/token.js CHANGED
@@ -15,6 +15,7 @@ exports.TokenType = {
15
15
  Dot: 'DOT',
16
16
  Number: 'NUMBER',
17
17
  Boolean: 'BOOLEAN',
18
+ Null: 'NULL',
18
19
  Keyword: 'KEYWORD',
19
20
  Identifier: 'IDENTIFIER',
20
21
  QuotedString: 'QUOTED_STRING',
package/dist/token.mjs CHANGED
@@ -13,6 +13,7 @@ export const TokenType = {
13
13
  Dot: "DOT",
14
14
  Number: "NUMBER",
15
15
  Boolean: "BOOLEAN",
16
+ Null: "NULL",
16
17
  Keyword: "KEYWORD",
17
18
  Identifier: "IDENTIFIER",
18
19
  QuotedString: "QUOTED_STRING",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/compiler",
3
- "version": "0.0.12",
3
+ "version": "0.0.15",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",