Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private static antlrParse(pattern: string): ParseTree {
const inputStream: ANTLRInputStream = new ANTLRInputStream(pattern);
const lexer: CommonRegexLexer = new CommonRegexLexer(inputStream);
const tokenStream: CommonTokenStream = new CommonTokenStream(lexer);
const parser: CommonRegexParser = new CommonRegexParser(tokenStream);
parser.removeErrorListeners();
// tslint:disable-next-line: no-use-before-declare
parser.addErrorListener(ErrorListener.Instance);
parser.buildParseTree = true;
return parser.parse();
}
}
export function parse(
lexerConstructor: new (inputStream: antlr.ANTLRInputStream) => L,
parserConstructor: new (tokenStream: antlr.TokenStream) => P,
rootNode: (parser: P) => antlr.ParserRuleContext,
code: string
): Node {
let inputStream = new antlr.ANTLRInputStream(code);
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);
export function ParsePlainSelectQueryAst(code: string) {
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.selectQuery();
let visitor = new Visitor();
let ast = visitor.visit(tree) as RelationSelection;
return ast;
}
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);
}
constructor(source: string) {
this.parser = new Parser.TomParser(new CommonTokenStream(
new Lexer.TomLexer(
new ANTLRInputStream(source)
)
));
}
parse() {
export function getVanillaSelectionUnitAst(code: string) {
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.selectUnitQuery();
let visitor = new Visitor();
let selectionUnitAst = visitor.visitSelectUnitQuery(tree);
return selectionUnitAst;
}
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;
}
export function parse(code: string) {
const inputStream = new ANTLRInputStream(code);
const l = new lexer.DIELLexer(inputStream);
const tokenStream = new CommonTokenStream(l);
return new parser.DIELParser(tokenStream);
}