Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let lexer = new lexerConstructor(inputStream);
lexer.removeErrorListeners();
lexer.addErrorListener({
syntaxError(
// tslint:disable-next-line no-any
recognizer: antlr.Recognizer,
offendingSymbol: number | undefined,
line: number,
charPositionInLine: number,
msg: string,
e: antlr.RecognitionException | undefined
) {
throw new Error(msg + " at " + line + ":" + charPositionInLine);
}
});
let tokenStream = new antlr.CommonTokenStream(lexer);
let parser = new parserConstructor(tokenStream);
parser.removeErrorListeners();
parser.addErrorListener({
syntaxError(
// tslint:disable-next-line no-any
recognizer: antlr.Recognizer,
offendingSymbol: antlr.Token | undefined,
line: number,
charPositionInLine: number,
msg: string,
e: antlr.RecognitionException | undefined
) {
throw new Error(msg + " at " + line + ":" + charPositionInLine);
}
});
let node = rootNode(parser);
if (!isSystemVerilogDocument(document) && !isVerilogDocument(document)) {
reject("The document is not a SystemVerilog/Verilog file.");
return;
}
let visitedDocuments = new Map();
let diagnosticCollection: Map = new Map();
// Get document text
let text = document.getText();
// Perform macro replacements
let new_text = this.macroReplace(text);
// Create the lexer and parser
let inputStream = new ANTLRInputStream(new_text);
let lexer = new SystemVerilogLexer(inputStream);
let tokenStream = new CommonTokenStream(lexer);
let parser = new SystemVerilogParser(tokenStream);
//Use syntaxError to collect a list of errors found by the parser
let syntaxError = new SyntaxErrorListener();
parser.addErrorListener(syntaxError);
// Parse the input
let tree = parser.system_verilog_text();
//place errors in the diagnostic list
let diagnosticList = new Array();
for (let i = 0; i < syntaxError.error_list.length; i++) {
let range: Range = getLineRange(
syntaxError.error_list[i].line,
syntaxError.error_list[i].offendingSymbol.text,
syntaxError.error_list[i].charPositionInLine);
if (!isSystemVerilogDocument(document) && !isVerilogDocument(document)) {
reject("The document is not a SystemVerilog/Verilog file.");
return;
}
let visitedDocuments = new Map();
let diagnosticCollection: Map = new Map();
// Get document text
let text = document.getText();
// Perform macro replacements
let new_text = this.macroReplace(text);
// Create the lexer and parser
let inputStream = new ANTLRInputStream(new_text);
let lexer = new SystemVerilogLexer(inputStream);
let tokenStream = new CommonTokenStream(lexer);
let parser = new SystemVerilogParser(tokenStream);
let syntaxError = new SyntaxErrorListener();
parser.addErrorListener(syntaxError);
// Parse the input, where `compilationUnit` is whatever entry point you defined
let tree = parser.system_verilog_text();
for (let i = 0; i < syntaxError.error_list.length; i++) {
let diagnosticData: DiagnosticData = new DiagnosticData();
diagnosticData.filePath = document.uri;
diagnosticData.line = syntaxError.error_list[i].line;
diagnosticData.diagnosticSeverity = DiagnosticSeverity.Error;
diagnosticData.problem = this.getImprovedMessage(syntaxError.error_list[i],document.uri);
diagnosticData.offendingSymbol = syntaxError.error_list[i].offendingSymbol.text;
export function ParsePlainDielAst(code: string) {
// PrintCode(code);
const inputStream = new ANTLRInputStream(code);
const l = new lexer.DIELLexer(inputStream);
const tokenStream = new CommonTokenStream(l);
const p = new parser.DIELParser(tokenStream);
const tree = p.queries();
let visitor = new Visitor();
let ast = visitor.visitQueries(tree);
return ast;
}
export function parse(path: string): YAJSPath {
const inputStream = new ANTLRInputStream(path);
const lexer = new YAJSLexer(inputStream);
const tokenStream = new CommonTokenStream(lexer);
const parser = new YAJSParser(tokenStream);
return new Visitor().
visit(parser.path()).
build();
}
constructor(source: string) {
this.parser = new Parser.TomParser(new CommonTokenStream(
new Lexer.TomLexer(
new ANTLRInputStream(source)
)
));
}
parse() {
function _parse(query: string) {
const inputStream = new ANTLRInputStream(query);
const l = new lexer.DIELLexer(inputStream);
const tokenStream = new CommonTokenStream(l);
return new parser.DIELParser(tokenStream);
}
protected static antlrParse(expression: string): ParseTree {
const inputStream: ANTLRInputStream = new ANTLRInputStream(expression);
const lexer: ExpressionLexer = new ExpressionLexer(inputStream);
const tokenStream: CommonTokenStream = new CommonTokenStream(lexer);
const parser: ExpressionParser = new ExpressionParser(tokenStream);
parser.removeErrorListeners();
parser.addErrorListener(ParseErrorListener.Instance);
parser.buildParseTree = true;
const file: ep.FileContext = parser.file();
if (file !== undefined) {
return file.expression();
}
return undefined;
}
function checkValidView(query: string): DielAst {
const inputStream = new ANTLRInputStream(query);
const l = new lexer.DIELLexer(inputStream);
const tokenStream = new CommonTokenStream(l);
const p = new parser.DIELParser(tokenStream);
const tree = p.queries();
let visitor = new Visitor();
let ast = visitor.visitQueries(tree);
if (ast.relations.length > 0) {
return ast;
}
return null;
}
constructor(source) {
this.parser = new Parser.TomParser(new antlr4ts_1.CommonTokenStream(new Lexer.TomLexer(new antlr4ts_1.ANTLRInputStream(source))));
}
parse() {