solidity-antlr4
Version:
Solidity Lang Lexer and Parser by official ANTLR4 grammar
24 lines (23 loc) • 680 B
JavaScript
import { Position } from "../ast/base.js";
import {
BaseErrorListener
} from "../antlr4/index.js";
export class ParseError extends Error {
constructor(message, position) {
super(message, { cause: null });
this.message = message;
this.position = position;
}
}
export class SolidityErrorListener extends BaseErrorListener {
errors = [];
syntaxError(_recognizer, _offendingSymbol, line, column, message, _exception) {
this.errors.push(new ParseError(message, Position.create(line, column)));
}
throws = () => {
if (!this.errors.length)
return;
throw this.errors[0];
};
}
export const solidityErrorListener = new SolidityErrorListener();