@aeriajs/compiler 0.0.12 → 0.0.14
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/parser.js +62 -60
- package/dist/parser.mjs +58 -56
- package/package.json +1 -1
package/dist/parser.js
CHANGED
|
@@ -580,6 +580,30 @@ const parse = (tokens) => {
|
|
|
580
580
|
}
|
|
581
581
|
return parsePropertyType(options);
|
|
582
582
|
};
|
|
583
|
+
const parseAccessCondition = (options = {
|
|
584
|
+
arrayBlock: false,
|
|
585
|
+
}) => {
|
|
586
|
+
if (match(token_js_1.TokenType.Boolean)) {
|
|
587
|
+
const { value } = consume(token_js_1.TokenType.Boolean);
|
|
588
|
+
return value;
|
|
589
|
+
}
|
|
590
|
+
else if (match(token_js_1.TokenType.QuotedString, [
|
|
591
|
+
'unauthenticated',
|
|
592
|
+
'unauthenticated-only',
|
|
593
|
+
])) {
|
|
594
|
+
const { value } = consume(token_js_1.TokenType.QuotedString, [
|
|
595
|
+
'unauthenticated',
|
|
596
|
+
'unauthenticated-only',
|
|
597
|
+
]);
|
|
598
|
+
return value;
|
|
599
|
+
}
|
|
600
|
+
else {
|
|
601
|
+
const { value, symbols } = options.arrayBlock
|
|
602
|
+
? parseArrayBlock()
|
|
603
|
+
: parseArray([token_js_1.TokenType.QuotedString]);
|
|
604
|
+
return checkForValidRoles(value, symbols);
|
|
605
|
+
}
|
|
606
|
+
};
|
|
583
607
|
const parseCollection = (ast) => {
|
|
584
608
|
consume(token_js_1.TokenType.Keyword, 'collection');
|
|
585
609
|
const { value: name } = consume(token_js_1.TokenType.Identifier);
|
|
@@ -681,23 +705,9 @@ const parse = (tokens) => {
|
|
|
681
705
|
const { value: keyword } = consume(token_js_1.TokenType.Keyword, lexer.CONTRACT_KEYWORDS);
|
|
682
706
|
switch (keyword) {
|
|
683
707
|
case 'roles': {
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
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
|
-
}
|
|
708
|
+
node.roles = parseAccessCondition({
|
|
709
|
+
arrayBlock: true,
|
|
710
|
+
});
|
|
701
711
|
break;
|
|
702
712
|
}
|
|
703
713
|
case 'payload': {
|
|
@@ -727,60 +737,52 @@ const parse = (tokens) => {
|
|
|
727
737
|
consume(token_js_1.TokenType.LeftBracket);
|
|
728
738
|
const functions = {};
|
|
729
739
|
while (!match(token_js_1.TokenType.RightBracket)) {
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
740
|
+
try {
|
|
741
|
+
if (match(token_js_1.TokenType.MacroName)) {
|
|
742
|
+
const { value: macroName } = consume(token_js_1.TokenType.MacroName, ['include']);
|
|
743
|
+
switch (macroName) {
|
|
744
|
+
case 'include': {
|
|
745
|
+
const { value: functionSetName, location } = consume(token_js_1.TokenType.Identifier);
|
|
746
|
+
const functionset = ast.functionsets.find((node) => node.name === functionSetName);
|
|
747
|
+
if (!functionset) {
|
|
748
|
+
throw new diagnostic_js_1.Diagnostic(`functionset "${functionSetName}" not found`, location);
|
|
749
|
+
}
|
|
750
|
+
Object.assign(functions, functionset.functions);
|
|
751
|
+
consume(token_js_1.TokenType.RightParens);
|
|
738
752
|
}
|
|
739
|
-
Object.assign(functions, functionset.functions);
|
|
740
|
-
consume(token_js_1.TokenType.RightParens);
|
|
741
753
|
}
|
|
754
|
+
continue;
|
|
742
755
|
}
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
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
|
-
]);
|
|
756
|
+
const { value: functionName } = consume(token_js_1.TokenType.Identifier);
|
|
757
|
+
functions[functionName] = {
|
|
758
|
+
accessCondition: false,
|
|
759
|
+
};
|
|
760
|
+
while (match(token_js_1.TokenType.AttributeName, 'expose')) {
|
|
761
|
+
consume(token_js_1.TokenType.AttributeName, 'expose');
|
|
762
|
+
if (match(token_js_1.TokenType.LeftParens)) {
|
|
763
|
+
consume(token_js_1.TokenType.LeftParens);
|
|
767
764
|
functions[functionName] = {
|
|
768
|
-
accessCondition:
|
|
765
|
+
accessCondition: parseAccessCondition(),
|
|
769
766
|
};
|
|
767
|
+
consume(token_js_1.TokenType.RightParens);
|
|
770
768
|
}
|
|
771
769
|
else {
|
|
772
|
-
const { value, symbols } = parseArray([token_js_1.TokenType.QuotedString]);
|
|
773
|
-
const roles = checkForValidRoles(value, symbols);
|
|
774
770
|
functions[functionName] = {
|
|
775
|
-
accessCondition:
|
|
771
|
+
accessCondition: true,
|
|
776
772
|
};
|
|
777
773
|
}
|
|
778
|
-
consume(token_js_1.TokenType.RightParens);
|
|
779
774
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
775
|
+
}
|
|
776
|
+
catch (err) {
|
|
777
|
+
if (err instanceof diagnostic_js_1.Diagnostic) {
|
|
778
|
+
let token;
|
|
779
|
+
while (token = tokens[++index]) {
|
|
780
|
+
if (token.type === token_js_1.TokenType.Identifier || token.type === token_js_1.TokenType.RightBracket) {
|
|
781
|
+
break;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
errors.push(err);
|
|
785
|
+
continue;
|
|
784
786
|
}
|
|
785
787
|
}
|
|
786
788
|
}
|
package/dist/parser.mjs
CHANGED
|
@@ -531,6 +531,26 @@ export const parse = (tokens) => {
|
|
|
531
531
|
}
|
|
532
532
|
return parsePropertyType(options);
|
|
533
533
|
};
|
|
534
|
+
const parseAccessCondition = (options = {
|
|
535
|
+
arrayBlock: false
|
|
536
|
+
}) => {
|
|
537
|
+
if (match(TokenType.Boolean)) {
|
|
538
|
+
const { value } = consume(TokenType.Boolean);
|
|
539
|
+
return value;
|
|
540
|
+
} else if (match(TokenType.QuotedString, [
|
|
541
|
+
"unauthenticated",
|
|
542
|
+
"unauthenticated-only"
|
|
543
|
+
])) {
|
|
544
|
+
const { value } = consume(TokenType.QuotedString, [
|
|
545
|
+
"unauthenticated",
|
|
546
|
+
"unauthenticated-only"
|
|
547
|
+
]);
|
|
548
|
+
return value;
|
|
549
|
+
} else {
|
|
550
|
+
const { value, symbols } = options.arrayBlock ? parseArrayBlock() : parseArray([TokenType.QuotedString]);
|
|
551
|
+
return checkForValidRoles(value, symbols);
|
|
552
|
+
}
|
|
553
|
+
};
|
|
534
554
|
const parseCollection = (ast2) => {
|
|
535
555
|
consume(TokenType.Keyword, "collection");
|
|
536
556
|
const { value: name } = consume(TokenType.Identifier);
|
|
@@ -631,20 +651,9 @@ export const parse = (tokens) => {
|
|
|
631
651
|
const { value: keyword } = consume(TokenType.Keyword, lexer.CONTRACT_KEYWORDS);
|
|
632
652
|
switch (keyword) {
|
|
633
653
|
case "roles": {
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
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
|
-
}
|
|
654
|
+
node.roles = parseAccessCondition({
|
|
655
|
+
arrayBlock: true
|
|
656
|
+
});
|
|
648
657
|
break;
|
|
649
658
|
}
|
|
650
659
|
case "payload": {
|
|
@@ -674,57 +683,50 @@ export const parse = (tokens) => {
|
|
|
674
683
|
consume(TokenType.LeftBracket);
|
|
675
684
|
const functions = {};
|
|
676
685
|
while (!match(TokenType.RightBracket)) {
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
686
|
+
try {
|
|
687
|
+
if (match(TokenType.MacroName)) {
|
|
688
|
+
const { value: macroName } = consume(TokenType.MacroName, ["include"]);
|
|
689
|
+
switch (macroName) {
|
|
690
|
+
case "include": {
|
|
691
|
+
const { value: functionSetName, location } = consume(TokenType.Identifier);
|
|
692
|
+
const functionset = ast2.functionsets.find((node) => node.name === functionSetName);
|
|
693
|
+
if (!functionset) {
|
|
694
|
+
throw new Diagnostic(`functionset "${functionSetName}" not found`, location);
|
|
695
|
+
}
|
|
696
|
+
Object.assign(functions, functionset.functions);
|
|
697
|
+
consume(TokenType.RightParens);
|
|
685
698
|
}
|
|
686
|
-
Object.assign(functions, functionset.functions);
|
|
687
|
-
consume(TokenType.RightParens);
|
|
688
699
|
}
|
|
700
|
+
continue;
|
|
689
701
|
}
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
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
|
-
]);
|
|
702
|
+
const { value: functionName } = consume(TokenType.Identifier);
|
|
703
|
+
functions[functionName] = {
|
|
704
|
+
accessCondition: false
|
|
705
|
+
};
|
|
706
|
+
while (match(TokenType.AttributeName, "expose")) {
|
|
707
|
+
consume(TokenType.AttributeName, "expose");
|
|
708
|
+
if (match(TokenType.LeftParens)) {
|
|
709
|
+
consume(TokenType.LeftParens);
|
|
713
710
|
functions[functionName] = {
|
|
714
|
-
accessCondition:
|
|
711
|
+
accessCondition: parseAccessCondition()
|
|
715
712
|
};
|
|
713
|
+
consume(TokenType.RightParens);
|
|
716
714
|
} else {
|
|
717
|
-
const { value, symbols } = parseArray([TokenType.QuotedString]);
|
|
718
|
-
const roles = checkForValidRoles(value, symbols);
|
|
719
715
|
functions[functionName] = {
|
|
720
|
-
accessCondition:
|
|
716
|
+
accessCondition: true
|
|
721
717
|
};
|
|
722
718
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
719
|
+
}
|
|
720
|
+
} catch (err) {
|
|
721
|
+
if (err instanceof Diagnostic) {
|
|
722
|
+
let token;
|
|
723
|
+
while (token = tokens[++index]) {
|
|
724
|
+
if (token.type === TokenType.Identifier || token.type === TokenType.RightBracket) {
|
|
725
|
+
break;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
errors.push(err);
|
|
729
|
+
continue;
|
|
728
730
|
}
|
|
729
731
|
}
|
|
730
732
|
}
|