cashc 0.9.2 → 0.9.3
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/AstBuilder.d.ts +7 -6
- package/dist/ast/AstBuilder.js +49 -37
- package/dist/ast/Location.d.ts +1 -2
- package/dist/ast/Location.js +4 -4
- package/dist/ast/Pragma.d.ts +1 -1
- package/dist/ast/Pragma.js +1 -1
- package/dist/ast/ThrowingErrorListener.d.ts +4 -4
- package/dist/ast/ThrowingErrorListener.js +3 -1
- package/dist/compiler.js +4 -4
- package/dist/grammar/CashScriptLexer.d.ts +11 -15
- package/dist/grammar/CashScriptLexer.js +355 -432
- package/dist/grammar/CashScriptParser.d.ts +106 -112
- package/dist/grammar/CashScriptParser.js +864 -839
- package/dist/grammar/CashScriptVisitor.d.ts +114 -121
- package/dist/grammar/CashScriptVisitor.js +11 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +5 -6
package/dist/ast/AstBuilder.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
export default class AstBuilder extends AbstractParseTreeVisitor<Node> implements CashScriptVisitor<Node> {
|
|
1
|
+
import { ParseTree, ParseTreeVisitor } from 'antlr4';
|
|
2
|
+
import { Node, SourceFileNode, ContractNode, ParameterNode, VariableDefinitionNode, FunctionDefinitionNode, AssignNode, IdentifierNode, BranchNode, CastNode, FunctionCallNode, UnaryOpNode, BinaryOpNode, BoolLiteralNode, IntLiteralNode, HexLiteralNode, StringLiteralNode, ExpressionNode, StatementNode, LiteralNode, BlockNode, TimeOpNode, ArrayNode, TupleIndexOpNode, RequireNode, InstantiationNode, TupleAssignmentNode, NullaryOpNode } from './AST.js';
|
|
3
|
+
import type { ContractDefinitionContext, FunctionDefinitionContext, VariableDefinitionContext, TupleAssignmentContext, ParameterContext, AssignStatementContext, IfStatementContext, FunctionCallContext, CastContext, LiteralContext, SourceFileContext, BlockContext, TimeOpStatementContext, ArrayContext, ParenthesisedContext, FunctionCallExpressionContext, UnaryOpContext, BinaryOpContext, IdentifierContext, LiteralExpressionContext, TupleIndexOpContext, RequireStatementContext, PragmaDirectiveContext, InstantiationContext, NullaryOpContext, UnaryIntrospectionOpContext, StatementContext } from '../grammar/CashScriptParser.js';
|
|
4
|
+
import CashScriptVisitor from '../grammar/CashScriptVisitor.js';
|
|
5
|
+
export default class AstBuilder extends ParseTreeVisitor<Node> implements CashScriptVisitor<Node> {
|
|
7
6
|
private tree;
|
|
8
7
|
constructor(tree: ParseTree);
|
|
9
8
|
defaultResult(): Node;
|
|
@@ -13,6 +12,7 @@ export default class AstBuilder extends AbstractParseTreeVisitor<Node> implement
|
|
|
13
12
|
visitContractDefinition(ctx: ContractDefinitionContext): ContractNode;
|
|
14
13
|
visitFunctionDefinition(ctx: FunctionDefinitionContext): FunctionDefinitionNode;
|
|
15
14
|
visitParameter(ctx: ParameterContext): ParameterNode;
|
|
15
|
+
visitStatement(ctx: StatementContext): StatementNode;
|
|
16
16
|
visitVariableDefinition(ctx: VariableDefinitionContext): VariableDefinitionNode;
|
|
17
17
|
visitTupleAssignment(ctx: TupleAssignmentContext): TupleAssignmentNode;
|
|
18
18
|
visitAssignStatement(ctx: AssignStatementContext): AssignNode;
|
|
@@ -39,4 +39,5 @@ export default class AstBuilder extends AbstractParseTreeVisitor<Node> implement
|
|
|
39
39
|
createStringLiteral(ctx: LiteralContext): StringLiteralNode;
|
|
40
40
|
createDateLiteral(ctx: LiteralContext): IntLiteralNode;
|
|
41
41
|
createHexLiteral(ctx: LiteralContext): HexLiteralNode;
|
|
42
|
+
visitChildren(): Node;
|
|
42
43
|
}
|
package/dist/ast/AstBuilder.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { ParseTreeVisitor } from 'antlr4';
|
|
1
2
|
import { hexToBin } from '@bitauth/libauth';
|
|
2
3
|
import { parseType } from '@cashscript/utils';
|
|
3
|
-
import { AbstractParseTreeVisitor } from 'antlr4ts/tree/AbstractParseTreeVisitor.js';
|
|
4
4
|
import semver from 'semver';
|
|
5
5
|
import { SourceFileNode, ContractNode, ParameterNode, VariableDefinitionNode, FunctionDefinitionNode, AssignNode, IdentifierNode, BranchNode, CastNode, FunctionCallNode, UnaryOpNode, BinaryOpNode, BoolLiteralNode, IntLiteralNode, HexLiteralNode, StringLiteralNode, BlockNode, TimeOpNode, ArrayNode, TupleIndexOpNode, RequireNode, InstantiationNode, TupleAssignmentNode, NullaryOpNode, } from './AST.js';
|
|
6
6
|
import { Location } from './Location.js';
|
|
@@ -8,7 +8,7 @@ import { NumberUnit, } from './Globals.js';
|
|
|
8
8
|
import { getPragmaName, PragmaName, getVersionOpFromCtx } from './Pragma.js';
|
|
9
9
|
import { version } from '../index.js';
|
|
10
10
|
import { ParseError, VersionError } from '../Errors.js';
|
|
11
|
-
export default class AstBuilder extends
|
|
11
|
+
export default class AstBuilder extends ParseTreeVisitor {
|
|
12
12
|
constructor(tree) {
|
|
13
13
|
super();
|
|
14
14
|
this.tree = tree;
|
|
@@ -20,7 +20,7 @@ export default class AstBuilder extends AbstractParseTreeVisitor {
|
|
|
20
20
|
return this.visit(this.tree);
|
|
21
21
|
}
|
|
22
22
|
visitSourceFile(ctx) {
|
|
23
|
-
ctx.
|
|
23
|
+
ctx.pragmaDirective_list().forEach((pragma) => {
|
|
24
24
|
this.processPragma(pragma);
|
|
25
25
|
});
|
|
26
26
|
const contract = this.visit(ctx.contractDefinition());
|
|
@@ -29,31 +29,31 @@ export default class AstBuilder extends AbstractParseTreeVisitor {
|
|
|
29
29
|
return sourceFileNode;
|
|
30
30
|
}
|
|
31
31
|
processPragma(ctx) {
|
|
32
|
-
const pragmaName = getPragmaName(ctx.pragmaName().
|
|
32
|
+
const pragmaName = getPragmaName(ctx.pragmaName().getText());
|
|
33
33
|
if (pragmaName !== PragmaName.CASHSCRIPT)
|
|
34
34
|
throw new Error(); // Shouldn't happen
|
|
35
35
|
// Strip any -beta tags
|
|
36
36
|
const actualVersion = version.replace(/-.*/g, '');
|
|
37
|
-
ctx.pragmaValue().
|
|
37
|
+
ctx.pragmaValue().versionConstraint_list().forEach((constraint) => {
|
|
38
38
|
const op = getVersionOpFromCtx(constraint.versionOperator());
|
|
39
|
-
const versionConstraint = `${op}${constraint.VersionLiteral().
|
|
39
|
+
const versionConstraint = `${op}${constraint.VersionLiteral().getText()}`;
|
|
40
40
|
if (!semver.satisfies(actualVersion, versionConstraint)) {
|
|
41
41
|
throw new VersionError(actualVersion, versionConstraint);
|
|
42
42
|
}
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
visitContractDefinition(ctx) {
|
|
46
|
-
const name = ctx.Identifier().
|
|
47
|
-
const parameters = ctx.parameterList().
|
|
48
|
-
const functions = ctx.
|
|
46
|
+
const name = ctx.Identifier().getText();
|
|
47
|
+
const parameters = ctx.parameterList().parameter_list().map((p) => this.visit(p));
|
|
48
|
+
const functions = ctx.functionDefinition_list().map((f) => this.visit(f));
|
|
49
49
|
const contract = new ContractNode(name, parameters, functions);
|
|
50
50
|
contract.location = Location.fromCtx(ctx);
|
|
51
51
|
return contract;
|
|
52
52
|
}
|
|
53
53
|
visitFunctionDefinition(ctx) {
|
|
54
|
-
const name = ctx.Identifier().
|
|
55
|
-
const parameters = ctx.parameterList().
|
|
56
|
-
const statements = ctx.
|
|
54
|
+
const name = ctx.Identifier().getText();
|
|
55
|
+
const parameters = ctx.parameterList().parameter_list().map((p) => this.visit(p));
|
|
56
|
+
const statements = ctx.statement_list().map((s) => this.visit(s));
|
|
57
57
|
const block = new BlockNode(statements);
|
|
58
58
|
block.location = Location.fromCtx(ctx);
|
|
59
59
|
const functionDefinition = new FunctionDefinitionNode(name, parameters, block);
|
|
@@ -61,16 +61,20 @@ export default class AstBuilder extends AbstractParseTreeVisitor {
|
|
|
61
61
|
return functionDefinition;
|
|
62
62
|
}
|
|
63
63
|
visitParameter(ctx) {
|
|
64
|
-
const type = parseType(ctx.typeName().
|
|
65
|
-
const name = ctx.Identifier().
|
|
64
|
+
const type = parseType(ctx.typeName().getText());
|
|
65
|
+
const name = ctx.Identifier().getText();
|
|
66
66
|
const parameter = new ParameterNode(type, name);
|
|
67
67
|
parameter.location = Location.fromCtx(ctx);
|
|
68
68
|
return parameter;
|
|
69
69
|
}
|
|
70
|
+
visitStatement(ctx) {
|
|
71
|
+
// Statement nodes only have a single child, so we can just visit that child
|
|
72
|
+
return this.visit(ctx.getChild(0));
|
|
73
|
+
}
|
|
70
74
|
visitVariableDefinition(ctx) {
|
|
71
|
-
const type = parseType(ctx.typeName().
|
|
72
|
-
const modifiers = ctx.
|
|
73
|
-
const name = ctx.Identifier().
|
|
75
|
+
const type = parseType(ctx.typeName().getText());
|
|
76
|
+
const modifiers = ctx.modifier_list().map((modifier) => modifier.getText());
|
|
77
|
+
const name = ctx.Identifier().getText();
|
|
74
78
|
const expression = this.visit(ctx.expression());
|
|
75
79
|
const variableDefinition = new VariableDefinitionNode(type, modifiers, name, expression);
|
|
76
80
|
variableDefinition.location = Location.fromCtx(ctx);
|
|
@@ -78,15 +82,18 @@ export default class AstBuilder extends AbstractParseTreeVisitor {
|
|
|
78
82
|
}
|
|
79
83
|
visitTupleAssignment(ctx) {
|
|
80
84
|
const expression = this.visit(ctx.expression());
|
|
81
|
-
const names = ctx.
|
|
82
|
-
const types = ctx.
|
|
83
|
-
const [var1, var2] = names.map((name, i) => ({
|
|
85
|
+
const names = ctx.Identifier_list();
|
|
86
|
+
const types = ctx.typeName_list();
|
|
87
|
+
const [var1, var2] = names.map((name, i) => ({
|
|
88
|
+
name: name.getText(),
|
|
89
|
+
type: parseType(types[i].getText()),
|
|
90
|
+
}));
|
|
84
91
|
const tupleAssignment = new TupleAssignmentNode(var1, var2, expression);
|
|
85
92
|
tupleAssignment.location = Location.fromCtx(ctx);
|
|
86
93
|
return tupleAssignment;
|
|
87
94
|
}
|
|
88
95
|
visitAssignStatement(ctx) {
|
|
89
|
-
const identifier = new IdentifierNode(ctx.Identifier().
|
|
96
|
+
const identifier = new IdentifierNode(ctx.Identifier().getText());
|
|
90
97
|
identifier.location = Location.fromToken(ctx.Identifier().symbol);
|
|
91
98
|
const expression = this.visit(ctx.expression());
|
|
92
99
|
const assign = new AssignNode(identifier, expression);
|
|
@@ -95,7 +102,7 @@ export default class AstBuilder extends AbstractParseTreeVisitor {
|
|
|
95
102
|
}
|
|
96
103
|
visitTimeOpStatement(ctx) {
|
|
97
104
|
const expression = this.visit(ctx.expression());
|
|
98
|
-
const timeOp = new TimeOpNode(ctx.TxVar().
|
|
105
|
+
const timeOp = new TimeOpNode(ctx.TxVar().getText(), expression);
|
|
99
106
|
timeOp.location = Location.fromCtx(ctx);
|
|
100
107
|
return timeOp;
|
|
101
108
|
}
|
|
@@ -114,7 +121,7 @@ export default class AstBuilder extends AbstractParseTreeVisitor {
|
|
|
114
121
|
return branch;
|
|
115
122
|
}
|
|
116
123
|
visitBlock(ctx) {
|
|
117
|
-
const statements = ctx.
|
|
124
|
+
const statements = ctx.statement_list().map((s) => this.visit(s));
|
|
118
125
|
const block = new BlockNode(statements);
|
|
119
126
|
block.location = Location.fromCtx(ctx);
|
|
120
127
|
return block;
|
|
@@ -123,7 +130,7 @@ export default class AstBuilder extends AbstractParseTreeVisitor {
|
|
|
123
130
|
return this.visit(ctx.expression());
|
|
124
131
|
}
|
|
125
132
|
visitCast(ctx) {
|
|
126
|
-
const type = parseType(ctx.typeName().
|
|
133
|
+
const type = parseType(ctx.typeName().getText());
|
|
127
134
|
const expression = this.visit(ctx._castable);
|
|
128
135
|
const size = ctx._size && this.visit(ctx._size);
|
|
129
136
|
const cast = new CastNode(type, expression, size);
|
|
@@ -134,17 +141,17 @@ export default class AstBuilder extends AbstractParseTreeVisitor {
|
|
|
134
141
|
return this.visit(ctx.functionCall());
|
|
135
142
|
}
|
|
136
143
|
visitFunctionCall(ctx) {
|
|
137
|
-
const identifier = new IdentifierNode(ctx.Identifier().
|
|
144
|
+
const identifier = new IdentifierNode(ctx.Identifier().getText());
|
|
138
145
|
identifier.location = Location.fromToken(ctx.Identifier().symbol);
|
|
139
|
-
const parameters = ctx.expressionList().
|
|
146
|
+
const parameters = ctx.expressionList().expression_list().map((e) => this.visit(e));
|
|
140
147
|
const functionCall = new FunctionCallNode(identifier, parameters);
|
|
141
148
|
functionCall.location = Location.fromCtx(ctx);
|
|
142
149
|
return functionCall;
|
|
143
150
|
}
|
|
144
151
|
visitInstantiation(ctx) {
|
|
145
|
-
const identifier = new IdentifierNode(ctx.Identifier().
|
|
152
|
+
const identifier = new IdentifierNode(ctx.Identifier().getText());
|
|
146
153
|
identifier.location = Location.fromToken(ctx.Identifier().symbol);
|
|
147
|
-
const parameters = ctx.expressionList().
|
|
154
|
+
const parameters = ctx.expressionList().expression_list().map((e) => this.visit(e));
|
|
148
155
|
const instantiation = new InstantiationNode(identifier, parameters);
|
|
149
156
|
instantiation.location = Location.fromCtx(ctx);
|
|
150
157
|
return instantiation;
|
|
@@ -157,7 +164,7 @@ export default class AstBuilder extends AbstractParseTreeVisitor {
|
|
|
157
164
|
return tupleIndexOp;
|
|
158
165
|
}
|
|
159
166
|
visitNullaryOp(ctx) {
|
|
160
|
-
const operator = ctx.
|
|
167
|
+
const operator = ctx.getText();
|
|
161
168
|
const nullaryOp = new NullaryOpNode(operator);
|
|
162
169
|
nullaryOp.location = Location.fromCtx(ctx);
|
|
163
170
|
return nullaryOp;
|
|
@@ -185,13 +192,13 @@ export default class AstBuilder extends AbstractParseTreeVisitor {
|
|
|
185
192
|
return binaryOp;
|
|
186
193
|
}
|
|
187
194
|
visitArray(ctx) {
|
|
188
|
-
const elements = ctx.
|
|
195
|
+
const elements = ctx.expression_list().map((e) => this.visit(e));
|
|
189
196
|
const array = new ArrayNode(elements);
|
|
190
197
|
array.location = Location.fromCtx(ctx);
|
|
191
198
|
return array;
|
|
192
199
|
}
|
|
193
200
|
visitIdentifier(ctx) {
|
|
194
|
-
const identifier = new IdentifierNode(ctx.Identifier().
|
|
201
|
+
const identifier = new IdentifierNode(ctx.Identifier().getText());
|
|
195
202
|
identifier.location = Location.fromCtx(ctx);
|
|
196
203
|
return identifier;
|
|
197
204
|
}
|
|
@@ -217,7 +224,7 @@ export default class AstBuilder extends AbstractParseTreeVisitor {
|
|
|
217
224
|
throw new Error(); // Should not happen
|
|
218
225
|
}
|
|
219
226
|
createBooleanLiteral(ctx) {
|
|
220
|
-
const boolString = ctx.BooleanLiteral().
|
|
227
|
+
const boolString = ctx.BooleanLiteral().getText();
|
|
221
228
|
const boolValue = boolString === 'true';
|
|
222
229
|
const booleanLiteral = new BoolLiteralNode(boolValue);
|
|
223
230
|
booleanLiteral.location = Location.fromCtx(ctx);
|
|
@@ -225,15 +232,15 @@ export default class AstBuilder extends AbstractParseTreeVisitor {
|
|
|
225
232
|
}
|
|
226
233
|
createIntLiteral(ctx) {
|
|
227
234
|
const numberCtx = ctx.numberLiteral();
|
|
228
|
-
const numberString = numberCtx.NumberLiteral().
|
|
229
|
-
const numberUnit = numberCtx.NumberUnit()?.
|
|
235
|
+
const numberString = numberCtx.NumberLiteral().getText();
|
|
236
|
+
const numberUnit = numberCtx.NumberUnit()?.getText();
|
|
230
237
|
const numberValue = BigInt(numberString) * BigInt(numberUnit ? NumberUnit[numberUnit.toUpperCase()] : 1);
|
|
231
238
|
const intLiteral = new IntLiteralNode(numberValue);
|
|
232
239
|
intLiteral.location = Location.fromCtx(ctx);
|
|
233
240
|
return intLiteral;
|
|
234
241
|
}
|
|
235
242
|
createStringLiteral(ctx) {
|
|
236
|
-
const rawString = ctx.StringLiteral().
|
|
243
|
+
const rawString = ctx.StringLiteral().getText();
|
|
237
244
|
const stringValue = rawString.substring(1, rawString.length - 1);
|
|
238
245
|
const quote = rawString.substring(0, 1);
|
|
239
246
|
const stringLiteral = new StringLiteralNode(stringValue, quote);
|
|
@@ -241,7 +248,7 @@ export default class AstBuilder extends AbstractParseTreeVisitor {
|
|
|
241
248
|
return stringLiteral;
|
|
242
249
|
}
|
|
243
250
|
createDateLiteral(ctx) {
|
|
244
|
-
const rawString = ctx.DateLiteral().
|
|
251
|
+
const rawString = ctx.DateLiteral().getText();
|
|
245
252
|
const stringValue = rawString.substring(6, rawString.length - 2).trim();
|
|
246
253
|
if (!/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d$/.test(stringValue)) {
|
|
247
254
|
throw new ParseError('Date should be in format `YYYY-MM-DDThh:mm:ss`', Location.fromCtx(ctx));
|
|
@@ -255,11 +262,16 @@ export default class AstBuilder extends AbstractParseTreeVisitor {
|
|
|
255
262
|
return intLiteral;
|
|
256
263
|
}
|
|
257
264
|
createHexLiteral(ctx) {
|
|
258
|
-
const hexString = ctx.HexLiteral().
|
|
265
|
+
const hexString = ctx.HexLiteral().getText();
|
|
259
266
|
const hexValue = hexToBin(hexString.substring(2));
|
|
260
267
|
const hexLiteral = new HexLiteralNode(hexValue);
|
|
261
268
|
hexLiteral.location = Location.fromCtx(ctx);
|
|
262
269
|
return hexLiteral;
|
|
263
270
|
}
|
|
271
|
+
// For safety reasons, we throw an error when the "default" visitChildren is called. *All* nodes
|
|
272
|
+
// must have a custom visit method, so that we can be sure that we've covered all cases.
|
|
273
|
+
visitChildren() {
|
|
274
|
+
throw new Error('Safety Warning: Unhandled node in AST builder');
|
|
275
|
+
}
|
|
264
276
|
}
|
|
265
277
|
//# sourceMappingURL=AstBuilder.js.map
|
package/dist/ast/Location.d.ts
CHANGED
package/dist/ast/Location.js
CHANGED
|
@@ -6,14 +6,14 @@ export class Location {
|
|
|
6
6
|
static fromCtx(ctx) {
|
|
7
7
|
const stop = ctx.stop?.text ? ctx.stop : ctx.start;
|
|
8
8
|
const textLength = (stop.text ?? '').length;
|
|
9
|
-
const start = new Point(ctx.start.line, ctx.start.
|
|
10
|
-
const end = new Point(stop.line, stop.
|
|
9
|
+
const start = new Point(ctx.start.line, ctx.start.column);
|
|
10
|
+
const end = new Point(stop.line, stop.column + textLength);
|
|
11
11
|
return new Location(start, end);
|
|
12
12
|
}
|
|
13
13
|
static fromToken(token) {
|
|
14
14
|
const textLength = (token.text ?? '').length;
|
|
15
|
-
const start = new Point(token.line, token.
|
|
16
|
-
const end = new Point(token.line, token.
|
|
15
|
+
const start = new Point(token.line, token.column);
|
|
16
|
+
const end = new Point(token.line, token.column + textLength);
|
|
17
17
|
return new Location(start, end);
|
|
18
18
|
}
|
|
19
19
|
text(code) {
|
package/dist/ast/Pragma.d.ts
CHANGED
package/dist/ast/Pragma.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ErrorListener, RecognitionException, Recognizer } from 'antlr4';
|
|
2
2
|
/**
|
|
3
3
|
* ANTLR Error Listener that immediately throws on error. This is used so that
|
|
4
4
|
* ANTLR doesn't attempt any error recovery during lexing/parsing and fails early.
|
|
5
5
|
*/
|
|
6
|
-
export default class ThrowingErrorListener
|
|
7
|
-
static readonly INSTANCE: ThrowingErrorListener
|
|
8
|
-
syntaxError
|
|
6
|
+
export default class ThrowingErrorListener<TSymbol> extends ErrorListener<TSymbol> {
|
|
7
|
+
static readonly INSTANCE: ThrowingErrorListener<unknown>;
|
|
8
|
+
syntaxError(recognizer: Recognizer<TSymbol>, offendingSymbol: TSymbol, line: number, charPositionInLine: number, message: string, e?: RecognitionException): void;
|
|
9
9
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import { ErrorListener } from 'antlr4';
|
|
1
3
|
import { ParseError } from '../Errors.js';
|
|
2
4
|
import { Point } from './Location.js';
|
|
3
5
|
/**
|
|
4
6
|
* ANTLR Error Listener that immediately throws on error. This is used so that
|
|
5
7
|
* ANTLR doesn't attempt any error recovery during lexing/parsing and fails early.
|
|
6
8
|
*/
|
|
7
|
-
export default class ThrowingErrorListener {
|
|
9
|
+
export default class ThrowingErrorListener extends ErrorListener {
|
|
8
10
|
syntaxError(recognizer, offendingSymbol, line, charPositionInLine, message, e) {
|
|
9
11
|
const capitalisedMessage = message.charAt(0).toUpperCase() + message.slice(1);
|
|
10
12
|
throw new ParseError(capitalisedMessage, new Point(line, charPositionInLine));
|
package/dist/compiler.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { CharStream, CommonTokenStream } from 'antlr4';
|
|
1
2
|
import { optimiseBytecode } from '@cashscript/utils';
|
|
2
|
-
import { ANTLRInputStream, CommonTokenStream } from 'antlr4ts';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import { generateArtifact } from './artifact/Artifact.js';
|
|
5
5
|
import AstBuilder from './ast/AstBuilder.js';
|
|
6
6
|
import ThrowingErrorListener from './ast/ThrowingErrorListener.js';
|
|
7
7
|
import GenerateTargetTraversal from './generation/GenerateTargetTraversal.js';
|
|
8
|
-
import
|
|
9
|
-
import
|
|
8
|
+
import CashScriptLexer from './grammar/CashScriptLexer.js';
|
|
9
|
+
import CashScriptParser from './grammar/CashScriptParser.js';
|
|
10
10
|
import SymbolTableTraversal from './semantic/SymbolTableTraversal.js';
|
|
11
11
|
import TypeCheckTraversal from './semantic/TypeCheckTraversal.js';
|
|
12
12
|
import EnsureFinalRequireTraversal from './semantic/EnsureFinalRequireTraversal.js';
|
|
@@ -31,7 +31,7 @@ export function compileFile(codeFile) {
|
|
|
31
31
|
}
|
|
32
32
|
export function parseCode(code) {
|
|
33
33
|
// Lexing (throwing on errors)
|
|
34
|
-
const inputStream = new
|
|
34
|
+
const inputStream = new CharStream(code);
|
|
35
35
|
const lexer = new CashScriptLexer(inputStream);
|
|
36
36
|
lexer.removeErrorListeners();
|
|
37
37
|
lexer.addErrorListener(ThrowingErrorListener.INSTANCE);
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { ATN } from "
|
|
2
|
-
|
|
3
|
-
import { Lexer } from "antlr4ts/Lexer.js";
|
|
4
|
-
import { Vocabulary } from "antlr4ts/Vocabulary.js";
|
|
5
|
-
export declare class CashScriptLexer extends Lexer {
|
|
1
|
+
import { ATN, CharStream, DFA, Lexer } from "antlr4";
|
|
2
|
+
export default class CashScriptLexer extends Lexer {
|
|
6
3
|
static readonly T__0 = 1;
|
|
7
4
|
static readonly T__1 = 2;
|
|
8
5
|
static readonly T__2 = 3;
|
|
@@ -74,23 +71,22 @@ export declare class CashScriptLexer extends Lexer {
|
|
|
74
71
|
static readonly WHITESPACE = 69;
|
|
75
72
|
static readonly COMMENT = 70;
|
|
76
73
|
static readonly LINE_COMMENT = 71;
|
|
74
|
+
static readonly EOF: number;
|
|
77
75
|
static readonly channelNames: string[];
|
|
76
|
+
static readonly literalNames: (string | null)[];
|
|
77
|
+
static readonly symbolicNames: (string | null)[];
|
|
78
78
|
static readonly modeNames: string[];
|
|
79
79
|
static readonly ruleNames: string[];
|
|
80
|
-
private static readonly _LITERAL_NAMES;
|
|
81
|
-
private static readonly _SYMBOLIC_NAMES;
|
|
82
|
-
static readonly VOCABULARY: Vocabulary;
|
|
83
|
-
get vocabulary(): Vocabulary;
|
|
84
80
|
constructor(input: CharStream);
|
|
85
81
|
get grammarFileName(): string;
|
|
82
|
+
get literalNames(): (string | null)[];
|
|
83
|
+
get symbolicNames(): (string | null)[];
|
|
86
84
|
get ruleNames(): string[];
|
|
87
|
-
get serializedATN():
|
|
85
|
+
get serializedATN(): number[];
|
|
88
86
|
get channelNames(): string[];
|
|
89
87
|
get modeNames(): string[];
|
|
90
|
-
|
|
91
|
-
private static
|
|
92
|
-
private static readonly _serializedATNSegment1;
|
|
93
|
-
static readonly _serializedATN: string;
|
|
94
|
-
static __ATN: ATN;
|
|
88
|
+
static readonly _serializedATN: number[];
|
|
89
|
+
private static __ATN;
|
|
95
90
|
static get _ATN(): ATN;
|
|
91
|
+
static DecisionsToDFA: DFA[];
|
|
96
92
|
}
|