@guardian-network/policy-dsl 0.3.2

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.
Files changed (121) hide show
  1. package/README.md +82 -0
  2. package/dist/antlr/generated/grammar/LacLangLexer.d.ts +53 -0
  3. package/dist/antlr/generated/grammar/LacLangLexer.d.ts.map +1 -0
  4. package/dist/antlr/generated/grammar/LacLangLexer.js +322 -0
  5. package/dist/antlr/generated/grammar/LacLangLexer.js.map +1 -0
  6. package/dist/antlr/generated/grammar/LacLangListener.d.ts +39 -0
  7. package/dist/antlr/generated/grammar/LacLangListener.d.ts.map +1 -0
  8. package/dist/antlr/generated/grammar/LacLangListener.js +3 -0
  9. package/dist/antlr/generated/grammar/LacLangListener.js.map +1 -0
  10. package/dist/antlr/generated/grammar/LacLangParser.d.ts +231 -0
  11. package/dist/antlr/generated/grammar/LacLangParser.d.ts.map +1 -0
  12. package/dist/antlr/generated/grammar/LacLangParser.js +1399 -0
  13. package/dist/antlr/generated/grammar/LacLangParser.js.map +1 -0
  14. package/dist/antlr/index.d.ts +4 -0
  15. package/dist/antlr/index.d.ts.map +1 -0
  16. package/dist/antlr/index.js +20 -0
  17. package/dist/antlr/index.js.map +1 -0
  18. package/dist/index.d.ts +4 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +23 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/ir-generation/hashing.helper.d.ts +3 -0
  23. package/dist/ir-generation/hashing.helper.d.ts.map +1 -0
  24. package/dist/ir-generation/hashing.helper.js +12 -0
  25. package/dist/ir-generation/hashing.helper.js.map +1 -0
  26. package/dist/ir-generation/index.d.ts +3 -0
  27. package/dist/ir-generation/index.d.ts.map +1 -0
  28. package/dist/ir-generation/index.js +19 -0
  29. package/dist/ir-generation/index.js.map +1 -0
  30. package/dist/ir-generation/parsed-state-to-ir.transformer.d.ts +11 -0
  31. package/dist/ir-generation/parsed-state-to-ir.transformer.d.ts.map +1 -0
  32. package/dist/ir-generation/parsed-state-to-ir.transformer.js +30 -0
  33. package/dist/ir-generation/parsed-state-to-ir.transformer.js.map +1 -0
  34. package/dist/transpiler/Transpiler.d.ts +17 -0
  35. package/dist/transpiler/Transpiler.d.ts.map +1 -0
  36. package/dist/transpiler/Transpiler.js +43 -0
  37. package/dist/transpiler/Transpiler.js.map +1 -0
  38. package/dist/transpiler/errors/ErrorFactory.d.ts +22 -0
  39. package/dist/transpiler/errors/ErrorFactory.d.ts.map +1 -0
  40. package/dist/transpiler/errors/ErrorFactory.js +62 -0
  41. package/dist/transpiler/errors/ErrorFactory.js.map +1 -0
  42. package/dist/transpiler/errors/helpers.d.ts +3 -0
  43. package/dist/transpiler/errors/helpers.d.ts.map +1 -0
  44. package/dist/transpiler/errors/helpers.js +6 -0
  45. package/dist/transpiler/errors/helpers.js.map +1 -0
  46. package/dist/transpiler/errors/index.d.ts +2 -0
  47. package/dist/transpiler/errors/index.d.ts.map +1 -0
  48. package/dist/transpiler/errors/index.js +18 -0
  49. package/dist/transpiler/errors/index.js.map +1 -0
  50. package/dist/transpiler/errors/validation-errors.d.ts +57 -0
  51. package/dist/transpiler/errors/validation-errors.d.ts.map +1 -0
  52. package/dist/transpiler/errors/validation-errors.js +132 -0
  53. package/dist/transpiler/errors/validation-errors.js.map +1 -0
  54. package/dist/transpiler/helpers/formatter.d.ts +10 -0
  55. package/dist/transpiler/helpers/formatter.d.ts.map +1 -0
  56. package/dist/transpiler/helpers/formatter.js +140 -0
  57. package/dist/transpiler/helpers/formatter.js.map +1 -0
  58. package/dist/transpiler/helpers/index.d.ts +5 -0
  59. package/dist/transpiler/helpers/index.d.ts.map +1 -0
  60. package/dist/transpiler/helpers/index.js +21 -0
  61. package/dist/transpiler/helpers/index.js.map +1 -0
  62. package/dist/transpiler/helpers/resources.helper.d.ts +4 -0
  63. package/dist/transpiler/helpers/resources.helper.d.ts.map +1 -0
  64. package/dist/transpiler/helpers/resources.helper.js +50 -0
  65. package/dist/transpiler/helpers/resources.helper.js.map +1 -0
  66. package/dist/transpiler/helpers/types.d.ts +12 -0
  67. package/dist/transpiler/helpers/types.d.ts.map +1 -0
  68. package/dist/transpiler/helpers/types.js +3 -0
  69. package/dist/transpiler/helpers/types.js.map +1 -0
  70. package/dist/transpiler/helpers/validations.helper.d.ts +8 -0
  71. package/dist/transpiler/helpers/validations.helper.d.ts.map +1 -0
  72. package/dist/transpiler/helpers/validations.helper.js +41 -0
  73. package/dist/transpiler/helpers/validations.helper.js.map +1 -0
  74. package/dist/transpiler/index.d.ts +3 -0
  75. package/dist/transpiler/index.d.ts.map +1 -0
  76. package/dist/transpiler/index.js +21 -0
  77. package/dist/transpiler/index.js.map +1 -0
  78. package/dist/transpiler/listener.d.ts +17 -0
  79. package/dist/transpiler/listener.d.ts.map +1 -0
  80. package/dist/transpiler/listener.js +94 -0
  81. package/dist/transpiler/listener.js.map +1 -0
  82. package/dist/transpiler/state/LatentState.d.ts +30 -0
  83. package/dist/transpiler/state/LatentState.d.ts.map +1 -0
  84. package/dist/transpiler/state/LatentState.js +130 -0
  85. package/dist/transpiler/state/LatentState.js.map +1 -0
  86. package/dist/transpiler/state/index.d.ts +3 -0
  87. package/dist/transpiler/state/index.d.ts.map +1 -0
  88. package/dist/transpiler/state/index.js +19 -0
  89. package/dist/transpiler/state/index.js.map +1 -0
  90. package/dist/transpiler/state/types.d.ts +42 -0
  91. package/dist/transpiler/state/types.d.ts.map +1 -0
  92. package/dist/transpiler/state/types.js +3 -0
  93. package/dist/transpiler/state/types.js.map +1 -0
  94. package/package.json +79 -0
  95. package/src/antlr/generated/grammar/LacLang.interp +88 -0
  96. package/src/antlr/generated/grammar/LacLang.tokens +52 -0
  97. package/src/antlr/generated/grammar/LacLangLexer.interp +108 -0
  98. package/src/antlr/generated/grammar/LacLangLexer.tokens +52 -0
  99. package/src/antlr/generated/grammar/LacLangLexer.ts +331 -0
  100. package/src/antlr/generated/grammar/LacLangListener.ts +216 -0
  101. package/src/antlr/generated/grammar/LacLangParser.ts +1484 -0
  102. package/src/antlr/index.ts +3 -0
  103. package/src/index.ts +3 -0
  104. package/src/ir-generation/hashing.helper.ts +13 -0
  105. package/src/ir-generation/index.ts +2 -0
  106. package/src/ir-generation/parsed-state-to-ir.transformer.ts +50 -0
  107. package/src/transpiler/Transpiler.ts +58 -0
  108. package/src/transpiler/errors/ErrorFactory.ts +130 -0
  109. package/src/transpiler/errors/helpers.ts +4 -0
  110. package/src/transpiler/errors/index.ts +1 -0
  111. package/src/transpiler/errors/validation-errors.ts +157 -0
  112. package/src/transpiler/helpers/formatter.ts +173 -0
  113. package/src/transpiler/helpers/index.ts +4 -0
  114. package/src/transpiler/helpers/resources.helper.ts +83 -0
  115. package/src/transpiler/helpers/types.ts +23 -0
  116. package/src/transpiler/helpers/validations.helper.ts +69 -0
  117. package/src/transpiler/index.ts +2 -0
  118. package/src/transpiler/listener.ts +180 -0
  119. package/src/transpiler/state/LatentState.ts +202 -0
  120. package/src/transpiler/state/index.ts +2 -0
  121. package/src/transpiler/state/types.ts +50 -0
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LacLangTranspiler = void 0;
4
+ const node_path_1 = require("node:path");
5
+ const ir_generation_1 = require("../ir-generation");
6
+ const ErrorFactory_1 = require("./errors/ErrorFactory");
7
+ const helpers_1 = require("./helpers");
8
+ const validations_helper_1 = require("./helpers/validations.helper");
9
+ const LatentState_1 = require("./state/LatentState");
10
+ const Transpiler_1 = require("./Transpiler");
11
+ class LacLangTranspiler {
12
+ latentState = new LatentState_1.LatentState();
13
+ config;
14
+ constructor(options) {
15
+ this.config = options;
16
+ }
17
+ enterDirective(ctx) {
18
+ switch (true) {
19
+ case !!ctx.directiveIndentifier().injectedOnlyDirective():
20
+ this.latentState.setInjectionConstraint(false);
21
+ break;
22
+ default:
23
+ throw ErrorFactory_1.ErrorFactory.unknownDirective(ctx.directiveIndentifier().text, ctx);
24
+ }
25
+ }
26
+ enterImportStatement(ctx) {
27
+ const url = ctx.STRING_LITERAL().text.replace(/^['"]|['"]$/g, '');
28
+ const normalizedUrl = (0, helpers_1.isLocalUrl)(url) || (0, helpers_1.isLocalRelativeUrl)(url)
29
+ ? (0, node_path_1.normalize)((0, node_path_1.join)(this.config.sourcesDir, url))
30
+ : url;
31
+ const sources = (0, helpers_1.fetchContent)(normalizedUrl);
32
+ const subTranspiler = Transpiler_1.Transpiler.create(sources, {
33
+ partialSources: true,
34
+ sourcesDir: this.config.sourcesDir,
35
+ });
36
+ subTranspiler.transpile();
37
+ const subState = subTranspiler.getLatentState();
38
+ this.latentState.merge(subState);
39
+ }
40
+ enterVarDeclaration(ctx) {
41
+ const name = ctx.IDENTIFIER().text;
42
+ (0, validations_helper_1.lookupAndThrow)(name, this.latentState.variables, (declared) => ErrorFactory_1.ErrorFactory.variableAlreadyDefined(name, ctx, declared.ctx));
43
+ this.latentState.setVariables(ctx);
44
+ }
45
+ enterConstantDeclaration(ctx) {
46
+ const name = ctx.IDENTIFIER().text;
47
+ (0, validations_helper_1.lookupAndThrow)(name, this.latentState.constants, (declared) => ErrorFactory_1.ErrorFactory.constantIsAlreadyDefined(name, ctx, declared.ctx));
48
+ this.latentState.setConstants(ctx);
49
+ }
50
+ enterArtifactDeclaration(ctx) {
51
+ const name = ctx.IDENTIFIER().text;
52
+ (0, validations_helper_1.lookupAndThrow)(name, this.latentState.artifacts, (declared) => ErrorFactory_1.ErrorFactory.artifactAlreadyDefined(name, ctx, declared.ctx));
53
+ this.latentState.setArtifacts(ctx);
54
+ }
55
+ enterInstanceDeclaration(ctx) {
56
+ const name = ctx.IDENTIFIER().text;
57
+ (0, validations_helper_1.lookupAndThrow)(name, this.latentState.instancesByName, (declared) => ErrorFactory_1.ErrorFactory.instanceAlreadyDefined(name, ctx, declared.ctx));
58
+ const execArguments = (0, helpers_1.extractAndLookupExecArguments)(ctx, this.latentState);
59
+ const initArguments = (0, helpers_1.extractAndLookupInitArguments)(ctx, this.latentState);
60
+ const artifactDereferenced = (0, helpers_1.dereferenceArtifact)(ctx, this.latentState.artifacts);
61
+ const instanceConfig = {
62
+ artifactAddress: artifactDereferenced,
63
+ needsInitialization: !!initArguments,
64
+ execArguments,
65
+ initArguments: initArguments ?? [],
66
+ };
67
+ const instancesCount = this.latentState.instancesByName.size;
68
+ const nodeId = (0, ir_generation_1.nodeIdFromDeclaration)(instanceConfig, instancesCount);
69
+ (0, validations_helper_1.findSelfReferenceAndThrow)(name, nodeId, execArguments, ctx);
70
+ this.latentState.setInstancesByName(ctx, nodeId, instanceConfig, instancesCount);
71
+ this.latentState.setInstancesById(ctx, nodeId, instanceConfig, instancesCount);
72
+ (0, validations_helper_1.findCycleAndThrow)(this.latentState.instancesByName, this.latentState.instancesById);
73
+ }
74
+ enterEvaluateStatement(ctx) {
75
+ const previouslyDeclared = this.latentState.evaluateRelativeTo;
76
+ if (!!previouslyDeclared) {
77
+ throw ErrorFactory_1.ErrorFactory.evaluateAlreadyDeclared(ctx, previouslyDeclared.ctx);
78
+ }
79
+ const instanceName = ctx.IDENTIFIER().text;
80
+ const refInst = (0, validations_helper_1.lookupOrThrow)(instanceName, this.latentState.instancesByName, ErrorFactory_1.ErrorFactory.instanceNotDefined(instanceName, ctx));
81
+ if (refInst.type != 'bool')
82
+ throw ErrorFactory_1.ErrorFactory.evaluateTypeNotBool(instanceName, ctx, refInst.ctx);
83
+ this.latentState.setEvaluateRelativeTo = {
84
+ nodeId: refInst.id,
85
+ ctx,
86
+ };
87
+ }
88
+ exitProgram(_) {
89
+ if (!this.latentState.evaluateRelativeTo && !this.config.partialSources)
90
+ throw ErrorFactory_1.ErrorFactory.noEvaluateStatement();
91
+ }
92
+ }
93
+ exports.LacLangTranspiler = LacLangTranspiler;
94
+ //# sourceMappingURL=listener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listener.js","sourceRoot":"","sources":["../../src/transpiler/listener.ts"],"names":[],"mappings":";;;AACA,yCAA4C;AAY5C,oDAA4E;AAC5E,w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,GAAG,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC;QAC/D,IAAI,CAAC,CAAC,kBAAkB,EAAE,CAAC;YACzB,MAAM,2BAAY,CAAC,uBAAuB,CAAC,GAAG,EAAE,kBAAkB,CAAC,GAAG,CAAC,CAAC;QAC1E,CAAC;QAED,MAAM,YAAY,GAAG,GAAG,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC;QAC3C,MAAM,OAAO,GAAG,IAAA,kCAAa,EAC3B,YAAY,EACZ,IAAI,CAAC,WAAW,CAAC,eAAe,EAChC,2BAAY,CAAC,kBAAkB,CAAC,YAAY,EAAE,GAAG,CAAC,CACnD,CAAC;QAEF,IAAI,OAAO,CAAC,IAAI,IAAI,MAAM;YACxB,MAAM,2BAAY,CAAC,mBAAmB,CAAC,YAAY,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QAEzE,IAAI,CAAC,WAAW,CAAC,qBAAqB,GAAG;YACvC,MAAM,EAAE,OAAO,CAAC,EAAE;YAClB,GAAG;SACJ,CAAC;IACJ,CAAC;IAGD,WAAW,CAAC,CAAiB;QAC3B,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,kBAAkB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc;YACrE,MAAM,2BAAY,CAAC,mBAAmB,EAAE,CAAC;IAC7C,CAAC;CACF;AAlJD,8CAkJC"}
@@ -0,0 +1,30 @@
1
+ import { InstanceConfig } from '@guardian-network/shared';
2
+ import { ArtifactDeclarationContext, ConstantDeclarationContext, InstanceDeclarationContext, VarDeclarationContext } from '../../antlr';
3
+ import { Artifacts, Constants, Evaluating, InstancesById, InstancesByName, Variables } from './types';
4
+ export declare class LatentState {
5
+ private constantsMap;
6
+ private variablesMap;
7
+ private artifactsMap;
8
+ private instancesByNameMap;
9
+ private instancesByIdMap;
10
+ private evaluateRelativeToInternal?;
11
+ private onlyInjectedVariables?;
12
+ constructor();
13
+ get constants(): Constants;
14
+ get variables(): Variables;
15
+ get artifacts(): Artifacts;
16
+ get instancesByName(): InstancesByName;
17
+ get instancesById(): InstancesById;
18
+ get evaluateRelativeTo(): Evaluating | undefined;
19
+ set setEvaluateRelativeTo(value: Evaluating);
20
+ setVariables(ctx: VarDeclarationContext): void;
21
+ setConstants(ctx: ConstantDeclarationContext): void;
22
+ setArtifacts(ctx: ArtifactDeclarationContext): void;
23
+ setInstancesByName(ctx: InstanceDeclarationContext, nodeId: string, instanceConfig: InstanceConfig, instancesCount: number): void;
24
+ setInstancesById(ctx: InstanceDeclarationContext, nodeId: string, instanceConfig: InstanceConfig, instancesCount: number): void;
25
+ setInjectionConstraint(allowNonInjectedVariables: boolean): void;
26
+ merge(subState: LatentState): void;
27
+ private concatMaps;
28
+ private moveValue;
29
+ }
30
+ //# sourceMappingURL=LatentState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LatentState.d.ts","sourceRoot":"","sources":["../../../src/transpiler/state/LatentState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,0BAA0B,EAC1B,qBAAqB,EACtB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,SAAS,EACT,SAAS,EACT,UAAU,EACV,aAAa,EACb,eAAe,EACf,SAAS,EACV,MAAM,SAAS,CAAC;AAEjB,qBAAa,WAAW;IACtB,OAAO,CAAC,YAAY,CAAY;IAEhC,OAAO,CAAC,YAAY,CAAY;IAEhC,OAAO,CAAC,YAAY,CAAY;IAEhC,OAAO,CAAC,kBAAkB,CAAkB;IAE5C,OAAO,CAAC,gBAAgB,CAAgB;IAExC,OAAO,CAAC,0BAA0B,CAAC,CAAa;IAEhD,OAAO,CAAC,qBAAqB,CAAC,CAAU;;IAexC,IAAI,SAAS,cAEZ;IAED,IAAI,SAAS,cAEZ;IAED,IAAI,SAAS,cAEZ;IAED,IAAI,eAAe,oBAElB;IAED,IAAI,aAAa,kBAEhB;IAED,IAAI,kBAAkB,2BAErB;IACD,IAAI,qBAAqB,CAAC,KAAK,EAAE,UAAU,EAE1C;IAED,YAAY,CAAC,GAAG,EAAE,qBAAqB;IAcvC,YAAY,CAAC,GAAG,EAAE,0BAA0B;IAY5C,YAAY,CAAC,GAAG,EAAE,0BAA0B;IAU5C,kBAAkB,CAChB,GAAG,EAAE,0BAA0B,EAC/B,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,MAAM;IAcxB,gBAAgB,CACd,GAAG,EAAE,0BAA0B,EAC/B,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,MAAM;IAcxB,sBAAsB,CAAC,yBAAyB,EAAE,OAAO;IAIzD,KAAK,CAAC,QAAQ,EAAE,WAAW;IAmB3B,OAAO,CAAC,UAAU;IAyBlB,OAAO,CAAC,SAAS;CASlB"}
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LatentState = void 0;
4
+ const errors_1 = require("../errors");
5
+ class LatentState {
6
+ constantsMap;
7
+ variablesMap;
8
+ artifactsMap;
9
+ instancesByNameMap;
10
+ instancesByIdMap;
11
+ evaluateRelativeToInternal;
12
+ onlyInjectedVariables;
13
+ constructor() {
14
+ this.constantsMap = new Map();
15
+ this.variablesMap = new Map();
16
+ this.artifactsMap = new Map();
17
+ this.instancesByNameMap = new Map();
18
+ this.instancesByIdMap = new Map();
19
+ }
20
+ get constants() {
21
+ return this.constantsMap;
22
+ }
23
+ get variables() {
24
+ return this.variablesMap;
25
+ }
26
+ get artifacts() {
27
+ return this.artifactsMap;
28
+ }
29
+ get instancesByName() {
30
+ return this.instancesByNameMap;
31
+ }
32
+ get instancesById() {
33
+ return this.instancesByIdMap;
34
+ }
35
+ get evaluateRelativeTo() {
36
+ return this.evaluateRelativeToInternal;
37
+ }
38
+ set setEvaluateRelativeTo(value) {
39
+ this.evaluateRelativeToInternal = value;
40
+ }
41
+ setVariables(ctx) {
42
+ const { text: name } = ctx.IDENTIFIER();
43
+ const { text: type } = ctx.dataType();
44
+ let injection = ctx.injectionModifier()?.STRING_LITERAL().text;
45
+ if (!injection && this.onlyInjectedVariables)
46
+ throw errors_1.ErrorFactory.nonInjectedVariable(name, ctx);
47
+ injection = injection ?? '';
48
+ this.variablesMap.set(name, { type, ctx, injection });
49
+ }
50
+ setConstants(ctx) {
51
+ const { text: name } = ctx.IDENTIFIER();
52
+ const { text: value } = ctx.literal();
53
+ const { text: type } = ctx.dataType();
54
+ this.constantsMap.set(name, {
55
+ value,
56
+ type,
57
+ ctx,
58
+ });
59
+ }
60
+ setArtifacts(ctx) {
61
+ const { text: name } = ctx.IDENTIFIER();
62
+ const { text: address } = ctx.ADDRESS_LITERAL();
63
+ this.artifactsMap.set(name, {
64
+ address,
65
+ ctx,
66
+ });
67
+ }
68
+ setInstancesByName(ctx, nodeId, instanceConfig, instancesCount) {
69
+ const { text: name } = ctx.IDENTIFIER();
70
+ const { text: type } = ctx.dataType();
71
+ this.instancesByNameMap.set(name, {
72
+ id: nodeId,
73
+ config: instanceConfig,
74
+ type,
75
+ index: instancesCount,
76
+ ctx,
77
+ });
78
+ }
79
+ setInstancesById(ctx, nodeId, instanceConfig, instancesCount) {
80
+ const { text: name } = ctx.IDENTIFIER();
81
+ const { text: type } = ctx.dataType();
82
+ this.instancesByIdMap.set(nodeId, {
83
+ name,
84
+ config: instanceConfig,
85
+ type,
86
+ index: instancesCount,
87
+ ctx,
88
+ });
89
+ }
90
+ setInjectionConstraint(allowNonInjectedVariables) {
91
+ this.onlyInjectedVariables = !allowNonInjectedVariables;
92
+ }
93
+ merge(subState) {
94
+ for (const property of Object.keys(this)) {
95
+ const indexingProperty = property;
96
+ try {
97
+ if (this[indexingProperty] instanceof Map) {
98
+ this.concatMaps(subState[indexingProperty], this[indexingProperty]);
99
+ }
100
+ else {
101
+ this.moveValue(subState[indexingProperty], this[indexingProperty]);
102
+ }
103
+ }
104
+ catch (e) {
105
+ throw errors_1.ErrorFactory.importAmbiguity(property, e.message);
106
+ }
107
+ }
108
+ }
109
+ concatMaps(source, target) {
110
+ for (const originalKey of source.keys()) {
111
+ const originalValue = source.get(originalKey);
112
+ if (target.get(originalKey) != undefined) {
113
+ if (Array.isArray(originalValue)) {
114
+ target.set(originalKey, originalValue.concat(target.get(originalKey)).sort());
115
+ return;
116
+ }
117
+ throw new Error(`Ambiguity while merging maps: target already has "${originalKey}" record`);
118
+ }
119
+ target.set(originalKey, originalValue);
120
+ }
121
+ }
122
+ moveValue(source, target) {
123
+ if (!!target) {
124
+ throw new Error(`Ambiguity while merging values: target already set to "${target}"`);
125
+ }
126
+ target = source;
127
+ }
128
+ }
129
+ exports.LatentState = LatentState;
130
+ //# sourceMappingURL=LatentState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LatentState.js","sourceRoot":"","sources":["../../../src/transpiler/state/LatentState.ts"],"names":[],"mappings":";;;AAOA,sCAAyC;AAUzC,MAAa,WAAW;IACd,YAAY,CAAY;IAExB,YAAY,CAAY;IAExB,YAAY,CAAY;IAExB,kBAAkB,CAAkB;IAEpC,gBAAgB,CAAgB;IAEhC,0BAA0B,CAAc;IAExC,qBAAqB,CAAW;IAGxC;QACE,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;QAE9B,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;QAE9B,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;QAE9B,IAAI,CAAC,kBAAkB,GAAG,IAAI,GAAG,EAAE,CAAC;QAEpC,IAAI,CAAC,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;IACpC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,IAAI,SAA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C;QACzC,CAAC;IACH,CAAC;IAEO,SAAS,CAAI,MAAS,EAAE,MAAS;QACvC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CACb,0DAA0D,MAAM,GAAG,CACpE,CAAC;QACJ,CAAC;QAED,MAAM,GAAG,MAAM,CAAC;IAClB,CAAC;CACF;AAxLD,kCAwLC"}
@@ -0,0 +1,3 @@
1
+ export * from './LatentState';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transpiler/state/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./LatentState"), exports);
18
+ __exportStar(require("./types"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transpiler/state/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,0CAAwB"}
@@ -0,0 +1,42 @@
1
+ import { InstanceConfig } from '@guardian-network/shared';
2
+ import { ParserRuleContext } from 'antlr4ts';
3
+ type KeyType = string;
4
+ type IdKeyType = KeyType;
5
+ type NameKeyType = KeyType;
6
+ type DataType = {
7
+ type: string;
8
+ };
9
+ type AddressType = {
10
+ address: string;
11
+ };
12
+ type NameType = {
13
+ name: string;
14
+ };
15
+ type NodeIdType = {
16
+ nodeId: string;
17
+ };
18
+ type IndexType = {
19
+ index: number;
20
+ };
21
+ type ConfigType = {
22
+ config: InstanceConfig;
23
+ };
24
+ type InjectionType = {
25
+ injection: string;
26
+ };
27
+ type ValueType = {
28
+ value: string;
29
+ };
30
+ type ContextWrapped = {
31
+ ctx: ParserRuleContext;
32
+ };
33
+ export type Constants = Map<KeyType, ValueType & DataType & ContextWrapped>;
34
+ export type Variables = Map<KeyType, DataType & ContextWrapped & InjectionType>;
35
+ export type Artifacts = Map<KeyType, AddressType & ContextWrapped>;
36
+ export type InstancesByName = Map<NameKeyType, {
37
+ id: string;
38
+ } & IndexType & ConfigType & DataType & ContextWrapped>;
39
+ export type InstancesById = Map<IdKeyType, NameType & IndexType & ConfigType & DataType & ContextWrapped>;
40
+ export type Evaluating = NodeIdType & ContextWrapped;
41
+ export {};
42
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/transpiler/state/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,KAAK,OAAO,GAAG,MAAM,CAAC;AACtB,KAAK,SAAS,GAAG,OAAO,CAAC;AACzB,KAAK,WAAW,GAAG,OAAO,CAAC;AAE3B,KAAK,QAAQ,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AACjC,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AACF,KAAK,QAAQ,GAAG;IACd,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AACF,KAAK,UAAU,GAAG;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AACF,KAAK,SAAS,GAAG;IACf,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AACF,KAAK,UAAU,GAAG;IAChB,MAAM,EAAE,cAAc,CAAC;CACxB,CAAC;AACF,KAAK,aAAa,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAC3C,KAAK,SAAS,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnC,KAAK,cAAc,GAAG;IAAE,GAAG,EAAE,iBAAiB,CAAA;CAAE,CAAC;AAEjD,MAAM,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,EAAE,SAAS,GAAG,QAAQ,GAAG,cAAc,CAAC,CAAC;AAE5E,MAAM,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,EAAE,QAAQ,GAAG,cAAc,GAAG,aAAa,CAAC,CAAC;AAEhF,MAAM,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CAAC,CAAC;AAEnE,MAAM,MAAM,eAAe,GAAG,GAAG,CAC/B,WAAW,EACX;IACE,EAAE,EAAE,MAAM,CAAC;CACZ,GAAG,SAAS,GACX,UAAU,GACV,QAAQ,GACR,cAAc,CACjB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,GAAG,CAC7B,SAAS,EACT,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,QAAQ,GAAG,cAAc,CAC9D,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,cAAc,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/transpiler/state/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@guardian-network/policy-dsl",
3
+ "author": "vpriadko@lacero.io",
4
+ "description": "Artifcts high level declaration language",
5
+ "version": "0.3.2",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "src"
11
+ ],
12
+ "engines": {
13
+ "node": ">=18.20.4"
14
+ },
15
+ "publishConfig": {
16
+ "registry": "https://registry.npmjs.org",
17
+ "access": "public"
18
+ },
19
+ "keywords": [],
20
+ "devDependencies": {
21
+ "@eslint/eslintrc": "^3.1.0",
22
+ "@eslint/js": "^9.13.0",
23
+ "@istanbuljs/nyc-config-typescript": "^1.0.2",
24
+ "@types/chai": "4.3.3",
25
+ "@types/mocha": "^10.0.9",
26
+ "@types/node": "^22.8.0",
27
+ "@typescript-eslint/eslint-plugin": "^8.61.1",
28
+ "@typescript-eslint/parser": "^8.8.0",
29
+ "antlr4ts-cli": "0.5.0-alpha.4",
30
+ "chai": "^4.5.0",
31
+ "copyfiles": "^2.4.1",
32
+ "eslint": "^9.11.1",
33
+ "eslint-config-prettier": "^9.1.0",
34
+ "eslint-import-resolver-typescript": "^3.6.3",
35
+ "eslint-plugin-import": "^2.31.0",
36
+ "eslint-plugin-mocha": "^10.5.0",
37
+ "eslint-plugin-n": "^17.10.3",
38
+ "eslint-plugin-prettier": "^5.2.1",
39
+ "eslint-plugin-promise": "^7.1.0",
40
+ "eslint-plugin-unused-imports": "^4.1.4",
41
+ "globals": "^15.11.0",
42
+ "mocha": "^10.8.2",
43
+ "nyc": "^18.0.0",
44
+ "prettier": "^3.3.3",
45
+ "prettier-plugin-organize-imports": "^4.1.0",
46
+ "rimraf": "^6.0.1"
47
+ },
48
+ "dependencies": {
49
+ "@types/node-fetch": "2.6.13",
50
+ "@types/sync-fetch": "^0.4.4",
51
+ "antlr4ts": "0.5.0-alpha.4",
52
+ "dotenv": "^16.4.5",
53
+ "ethers": "^6.16.0",
54
+ "generator-code": "^1.11.18",
55
+ "sync-fetch": "0.6.0",
56
+ "ts-node": "^10.9.2",
57
+ "typescript": "^5.6.2",
58
+ "@guardian-network/shared": "0.3.2"
59
+ },
60
+ "scripts": {
61
+ "antlr": "antlr4ts ./grammar/LacLang.g4 -o ./src/antlr/generated",
62
+ "antlr:make": "pnpm antlr && pnpm format:ts:fix",
63
+ "build": "pnpm format:all:fix && tsc -p tsconfig-prod.json && pnpm copy-dts",
64
+ "check": "pnpm lint:ts && pnpm check:ts",
65
+ "check:ts": "tsc -p tsconfig-prod.json --noEmit",
66
+ "check:ts:dev": "tsc -p tsconfig.json --noEmit",
67
+ "clean": "pnpm remove:dist",
68
+ "copy-dts": "copyfiles -u 1 \"src/**/*.d.ts\" dist",
69
+ "format:all:fix": "pnpm format:ts:fix",
70
+ "format:ts:fix": "prettier -w -c \"src/**/*.ts\" \"test/**/*.ts\"",
71
+ "lint:ts": "eslint",
72
+ "lint:ts:fix": "eslint --fix",
73
+ "publish-package": "pnpm publish --no-git-checks",
74
+ "remove:dist": "npx rimraf dist",
75
+ "test": "mocha",
76
+ "tests:coverage:ts": "nyc pnpm test",
77
+ "version": "pnpm version"
78
+ }
79
+ }
@@ -0,0 +1,88 @@
1
+ token literal names:
2
+ null
3
+ 'import'
4
+ ';'
5
+ 'pragma'
6
+ 'injected-only'
7
+ 'var'
8
+ 'inject'
9
+ '('
10
+ ')'
11
+ 'constant'
12
+ '='
13
+ 'artifact'
14
+ 'instance'
15
+ 'of'
16
+ 'takes'
17
+ 'with'
18
+ 'evaluate'
19
+ 'bool'
20
+ 'number'
21
+ 'string'
22
+ 'bytes'
23
+ 'address'
24
+ ','
25
+ null
26
+ null
27
+ null
28
+ null
29
+ null
30
+ null
31
+ null
32
+ null
33
+
34
+ token symbolic names:
35
+ null
36
+ null
37
+ null
38
+ null
39
+ null
40
+ null
41
+ null
42
+ null
43
+ null
44
+ null
45
+ null
46
+ null
47
+ null
48
+ null
49
+ null
50
+ null
51
+ null
52
+ null
53
+ null
54
+ null
55
+ null
56
+ null
57
+ null
58
+ ADDRESS_LITERAL
59
+ BOOL_LITERAL
60
+ NUMBER_LITERAL
61
+ STRING_LITERAL
62
+ BYTES_LITERAL
63
+ IDENTIFIER
64
+ WHITESPACE
65
+ COMMENT
66
+
67
+ rule names:
68
+ program
69
+ statement
70
+ importStatement
71
+ directive
72
+ directiveIndentifier
73
+ injectedOnlyDirective
74
+ varDeclaration
75
+ injectionModifier
76
+ constantDeclaration
77
+ artifactDeclaration
78
+ instanceDeclaration
79
+ evaluateStatement
80
+ dataType
81
+ constantsList
82
+ argumentsList
83
+ identifier_or_literal
84
+ literal
85
+
86
+
87
+ atn:
88
+ [3, 51485, 51898, 1421, 44986, 20307, 1543, 60043, 49729, 3, 32, 145, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 4, 16, 9, 16, 4, 17, 9, 17, 4, 18, 9, 18, 3, 2, 7, 2, 38, 10, 2, 12, 2, 14, 2, 41, 11, 2, 3, 2, 7, 2, 44, 10, 2, 12, 2, 14, 2, 47, 11, 2, 3, 2, 7, 2, 50, 10, 2, 12, 2, 14, 2, 53, 11, 2, 3, 2, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, 62, 10, 3, 3, 4, 3, 4, 3, 4, 3, 4, 3, 5, 3, 5, 3, 5, 3, 5, 3, 6, 3, 6, 3, 7, 3, 7, 3, 8, 3, 8, 5, 8, 78, 10, 8, 3, 8, 3, 8, 3, 8, 3, 8, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 10, 3, 10, 3, 10, 3, 10, 3, 10, 3, 10, 3, 10, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 12, 3, 12, 3, 12, 3, 12, 3, 12, 3, 12, 3, 12, 3, 12, 5, 12, 110, 10, 12, 3, 12, 3, 12, 3, 12, 3, 12, 5, 12, 116, 10, 12, 3, 12, 5, 12, 119, 10, 12, 3, 12, 3, 12, 3, 13, 3, 13, 3, 13, 3, 13, 3, 14, 3, 14, 3, 15, 3, 15, 3, 16, 3, 16, 3, 16, 7, 16, 134, 10, 16, 12, 16, 14, 16, 137, 11, 16, 3, 17, 3, 17, 5, 17, 141, 10, 17, 3, 18, 3, 18, 3, 18, 5, 39, 45, 51, 2, 2, 19, 2, 2, 4, 2, 6, 2, 8, 2, 10, 2, 12, 2, 14, 2, 16, 2, 18, 2, 20, 2, 22, 2, 24, 2, 26, 2, 28, 2, 30, 2, 32, 2, 34, 2, 2, 4, 3, 2, 19, 23, 3, 2, 25, 29, 2, 140, 2, 39, 3, 2, 2, 2, 4, 61, 3, 2, 2, 2, 6, 63, 3, 2, 2, 2, 8, 67, 3, 2, 2, 2, 10, 71, 3, 2, 2, 2, 12, 73, 3, 2, 2, 2, 14, 75, 3, 2, 2, 2, 16, 83, 3, 2, 2, 2, 18, 88, 3, 2, 2, 2, 20, 95, 3, 2, 2, 2, 22, 101, 3, 2, 2, 2, 24, 122, 3, 2, 2, 2, 26, 126, 3, 2, 2, 2, 28, 128, 3, 2, 2, 2, 30, 130, 3, 2, 2, 2, 32, 140, 3, 2, 2, 2, 34, 142, 3, 2, 2, 2, 36, 38, 5, 6, 4, 2, 37, 36, 3, 2, 2, 2, 38, 41, 3, 2, 2, 2, 39, 40, 3, 2, 2, 2, 39, 37, 3, 2, 2, 2, 40, 45, 3, 2, 2, 2, 41, 39, 3, 2, 2, 2, 42, 44, 5, 8, 5, 2, 43, 42, 3, 2, 2, 2, 44, 47, 3, 2, 2, 2, 45, 46, 3, 2, 2, 2, 45, 43, 3, 2, 2, 2, 46, 51, 3, 2, 2, 2, 47, 45, 3, 2, 2, 2, 48, 50, 5, 4, 3, 2, 49, 48, 3, 2, 2, 2, 50, 53, 3, 2, 2, 2, 51, 52, 3, 2, 2, 2, 51, 49, 3, 2, 2, 2, 52, 54, 3, 2, 2, 2, 53, 51, 3, 2, 2, 2, 54, 55, 7, 2, 2, 3, 55, 3, 3, 2, 2, 2, 56, 62, 5, 14, 8, 2, 57, 62, 5, 18, 10, 2, 58, 62, 5, 20, 11, 2, 59, 62, 5, 22, 12, 2, 60, 62, 5, 24, 13, 2, 61, 56, 3, 2, 2, 2, 61, 57, 3, 2, 2, 2, 61, 58, 3, 2, 2, 2, 61, 59, 3, 2, 2, 2, 61, 60, 3, 2, 2, 2, 62, 5, 3, 2, 2, 2, 63, 64, 7, 3, 2, 2, 64, 65, 7, 28, 2, 2, 65, 66, 7, 4, 2, 2, 66, 7, 3, 2, 2, 2, 67, 68, 7, 5, 2, 2, 68, 69, 5, 10, 6, 2, 69, 70, 7, 4, 2, 2, 70, 9, 3, 2, 2, 2, 71, 72, 5, 12, 7, 2, 72, 11, 3, 2, 2, 2, 73, 74, 7, 6, 2, 2, 74, 13, 3, 2, 2, 2, 75, 77, 7, 7, 2, 2, 76, 78, 5, 16, 9, 2, 77, 76, 3, 2, 2, 2, 77, 78, 3, 2, 2, 2, 78, 79, 3, 2, 2, 2, 79, 80, 5, 26, 14, 2, 80, 81, 7, 30, 2, 2, 81, 82, 7, 4, 2, 2, 82, 15, 3, 2, 2, 2, 83, 84, 7, 8, 2, 2, 84, 85, 7, 9, 2, 2, 85, 86, 7, 28, 2, 2, 86, 87, 7, 10, 2, 2, 87, 17, 3, 2, 2, 2, 88, 89, 7, 11, 2, 2, 89, 90, 5, 26, 14, 2, 90, 91, 7, 30, 2, 2, 91, 92, 7, 12, 2, 2, 92, 93, 5, 34, 18, 2, 93, 94, 7, 4, 2, 2, 94, 19, 3, 2, 2, 2, 95, 96, 7, 13, 2, 2, 96, 97, 7, 30, 2, 2, 97, 98, 7, 12, 2, 2, 98, 99, 7, 25, 2, 2, 99, 100, 7, 4, 2, 2, 100, 21, 3, 2, 2, 2, 101, 102, 7, 14, 2, 2, 102, 103, 5, 26, 14, 2, 103, 104, 7, 30, 2, 2, 104, 105, 7, 15, 2, 2, 105, 106, 5, 32, 17, 2, 106, 107, 7, 16, 2, 2, 107, 109, 7, 9, 2, 2, 108, 110, 5, 30, 16, 2, 109, 108, 3, 2, 2, 2, 109, 110, 3, 2, 2, 2, 110, 111, 3, 2, 2, 2, 111, 118, 7, 10, 2, 2, 112, 113, 7, 17, 2, 2, 113, 115, 7, 9, 2, 2, 114, 116, 5, 28, 15, 2, 115, 114, 3, 2, 2, 2, 115, 116, 3, 2, 2, 2, 116, 117, 3, 2, 2, 2, 117, 119, 7, 10, 2, 2, 118, 112, 3, 2, 2, 2, 118, 119, 3, 2, 2, 2, 119, 120, 3, 2, 2, 2, 120, 121, 7, 4, 2, 2, 121, 23, 3, 2, 2, 2, 122, 123, 7, 18, 2, 2, 123, 124, 7, 30, 2, 2, 124, 125, 7, 4, 2, 2, 125, 25, 3, 2, 2, 2, 126, 127, 9, 2, 2, 2, 127, 27, 3, 2, 2, 2, 128, 129, 5, 30, 16, 2, 129, 29, 3, 2, 2, 2, 130, 135, 5, 32, 17, 2, 131, 132, 7, 24, 2, 2, 132, 134, 5, 32, 17, 2, 133, 131, 3, 2, 2, 2, 134, 137, 3, 2, 2, 2, 135, 133, 3, 2, 2, 2, 135, 136, 3, 2, 2, 2, 136, 31, 3, 2, 2, 2, 137, 135, 3, 2, 2, 2, 138, 141, 7, 30, 2, 2, 139, 141, 5, 34, 18, 2, 140, 138, 3, 2, 2, 2, 140, 139, 3, 2, 2, 2, 141, 33, 3, 2, 2, 2, 142, 143, 9, 3, 2, 2, 143, 35, 3, 2, 2, 2, 12, 39, 45, 51, 61, 77, 109, 115, 118, 135, 140]
@@ -0,0 +1,52 @@
1
+ T__0=1
2
+ T__1=2
3
+ T__2=3
4
+ T__3=4
5
+ T__4=5
6
+ T__5=6
7
+ T__6=7
8
+ T__7=8
9
+ T__8=9
10
+ T__9=10
11
+ T__10=11
12
+ T__11=12
13
+ T__12=13
14
+ T__13=14
15
+ T__14=15
16
+ T__15=16
17
+ T__16=17
18
+ T__17=18
19
+ T__18=19
20
+ T__19=20
21
+ T__20=21
22
+ T__21=22
23
+ ADDRESS_LITERAL=23
24
+ BOOL_LITERAL=24
25
+ NUMBER_LITERAL=25
26
+ STRING_LITERAL=26
27
+ BYTES_LITERAL=27
28
+ IDENTIFIER=28
29
+ WHITESPACE=29
30
+ COMMENT=30
31
+ 'import'=1
32
+ ';'=2
33
+ 'pragma'=3
34
+ 'injected-only'=4
35
+ 'var'=5
36
+ 'inject'=6
37
+ '('=7
38
+ ')'=8
39
+ 'constant'=9
40
+ '='=10
41
+ 'artifact'=11
42
+ 'instance'=12
43
+ 'of'=13
44
+ 'takes'=14
45
+ 'with'=15
46
+ 'evaluate'=16
47
+ 'bool'=17
48
+ 'number'=18
49
+ 'string'=19
50
+ 'bytes'=20
51
+ 'address'=21
52
+ ','=22