Skip to content

Commit 693a7fa

Browse files
committed
Update grammar files and move from antlr4ts to antlr4
1 parent 97c55ce commit 693a7fa

12 files changed

Lines changed: 1963 additions & 2000 deletions

package-lock.json

Lines changed: 51 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@
7373
]
7474
},
7575
"dependencies": {
76-
"antlr4ts": "^0.5.0-alpha.4",
76+
"antlr4": "^4.13.1-patch-1",
7777
"vsce": "^2.15.0",
7878
"vscode-languageclient": "^7.0.0",
7979
"vscode-languageserver": "^7.0.0",
8080
"vscode-languageserver-textdocument": "^1.0.4",
8181
"vscode-test": "^1.6.1"
8282
},
8383
"devDependencies": {
84-
"@types/node": "^20.3.3",
84+
"@types/node": "^18.7.23",
8585
"@types/vscode": "^1.83.0",
8686
"esbuild": "^0.12.29",
87-
"typescript": "^4.5.5"
87+
"typescript": "^5.5.4"
8888
}
8989
}
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
1-
import { ANTLRInputStream, CommonTokenStream } from 'antlr4ts';
1+
import { CharStream, CommonTokenStream } from 'antlr4';
22
import { Diagnostic } from 'vscode-languageserver';
33
import { SafeErrorListener, SafeErrorStrategy } from './ErrorListeners';
4-
import { CashScriptLexer } from './grammar/CashScriptLexer';
5-
import { CashScriptParser } from './grammar/CashScriptParser';
4+
import CashScriptLexer from './grammar/CashScriptLexer';
5+
import CashScriptParser from './grammar/CashScriptParser';
66

77
export default class CashscriptLinter {
8-
9-
static getDiagnostics(code:string):Diagnostic[]{
10-
8+
static getDiagnostics(code: string): Diagnostic[] {
119
const errListener = new SafeErrorListener();
1210

13-
const inputStream = new ANTLRInputStream(code);
11+
const inputStream = new CharStream(code);
1412
const lexer = new CashScriptLexer(inputStream);
1513
lexer.removeErrorListeners();
1614
lexer.addErrorListener(errListener);
1715

1816
const tokenStream = new CommonTokenStream(lexer);
1917
const parser = new CashScriptParser(tokenStream);
20-
parser.errorHandler = new SafeErrorStrategy();
18+
parser._errHandler = new SafeErrorStrategy();
2119
parser.removeErrorListeners();
2220
parser.addErrorListener(errListener);
2321
const parseTree = parser.sourceFile();
24-
22+
2523
return errListener.getErrs()
2624
}
2725

2826
}
29-
30-

src/CashscriptLinter/ErrorListeners.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { ANTLRErrorListener, DefaultErrorStrategy, Parser, RecognitionException, Recognizer } from 'antlr4ts';
1+
import { ErrorListener, DefaultErrorStrategy, Parser, RecognitionException, Recognizer } from 'antlr4';
22
import { Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver';
33

4-
export class SafeErrorListener implements ANTLRErrorListener<any> {
4+
export class SafeErrorListener extends ErrorListener<any> {
55
static readonly INSTANCE = new SafeErrorListener();
66

77
errs:Diagnostic[] = []
@@ -11,7 +11,7 @@ export class SafeErrorListener implements ANTLRErrorListener<any> {
1111
}
1212

1313
syntaxError<T>(
14-
recognizer: Recognizer<T, any>,
14+
recognizer: Recognizer<T>,
1515
offendingSymbol: T,
1616
line: number,
1717
charPositionInLine: number,
@@ -42,4 +42,4 @@ export class SafeErrorStrategy extends DefaultErrorStrategy{
4242
sync(recognizer: Parser): void {
4343
return
4444
}
45-
}
45+
}

src/CashscriptLinter/grammar/CashScript.g4

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ assignStatement
6868
;
6969

7070
timeOpStatement
71-
: 'require' '(' TxVar '>=' expression (',' StringLiteral)? ')' ';'
71+
: 'require' '(' TxVar '>=' expression (',' requireMessage)? ')' ';'
7272
;
7373

7474
requireStatement
75-
: 'require' '(' expression (',' StringLiteral)? ')' ';'
75+
: 'require' '(' expression (',' requireMessage)? ')' ';'
7676
;
7777

7878
ifStatement
@@ -83,12 +83,13 @@ consoleStatement
8383
: 'console.log' consoleParameterList ';'
8484
;
8585

86+
requireMessage
87+
: StringLiteral
88+
;
89+
8690
consoleParameter
8791
: Identifier
88-
| StringLiteral
89-
| NumberLiteral
90-
| HexLiteral
91-
| BooleanLiteral
92+
| literal
9293
;
9394

9495
consoleParameterList
@@ -164,7 +165,15 @@ NumberUnit
164165
;
165166

166167
NumberLiteral
167-
: [-]?[0-9]+ ([eE] [0-9]+)?
168+
: '-'? NumberPart ExponentPart?
169+
;
170+
171+
NumberPart
172+
: [0-9]+ ('_' [0-9]+)*
173+
;
174+
175+
ExponentPart
176+
: [eE] NumberPart
168177
;
169178

170179
Bytes

0 commit comments

Comments
 (0)