Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public static getCommand(content: string, position?: vscode.Position): MongoCommand {
const lexer = new mongoLexer(new InputStream(content));
lexer.removeErrorListeners();
const parser = new mongoParser.mongoParser(new CommonTokenStream(lexer));
parser.removeErrorListeners();
const commands = new MongoScriptDocumentVisitor().visit(parser.commands());
let lastCommandOnSameLine = null;
let lastCommandBeforePosition = null;
if (position) {
for (const command of commands) {
if (command.range.contains(position)) {
return command;
}
if (command.range.end.line === position.line) {
lastCommandOnSameLine = command;
}
if (command.range.end.isBefore(position)) {
private static getFileContentContext(text: string, source: string): FileContext {
if (text === undefined
|| text === ''
|| text === null) {
return undefined;
}
const input: ANTLRInputStream = new ANTLRInputStream(text);
const lexer: LGFileLexer = new LGFileLexer(input);
const tokens: CommonTokenStream = new CommonTokenStream(lexer);
const parser: LGFileParser = new LGFileParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(new ErrorListener(source));
parser.buildParseTree = true;
return parser.file();
}
public EvaluateInline(inlinsStr: string, scope: any): string {
const fakeTemplateId: string = '__temp__';
const wrappedStr: string = `# ${fakeTemplateId} \r\n - ${inlinsStr}`;
try {
const input: ANTLRInputStream = new ANTLRInputStream(wrappedStr);
const lexer: LGFileLexer = new LGFileLexer(input);
const tokens: CommonTokenStream = new CommonTokenStream(lexer);
const parser: LGFileParser = new LGFileParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(TemplateErrorListener.INSTANCE);
parser.buildParseTree = true;
parser.errorHandler = new BailErrorStrategy();
const context: TemplateDefinitionContext = parser.templateDefinition();
const evaluationContext: EvaluationContext = new EvaluationContext(this.evaluationContext.TemplateContexts,
this.evaluationContext.TemplateParameters);
evaluationContext.TemplateContexts[fakeTemplateId] = context;
const evalutor: Evaluator = new Evaluator(evaluationContext);
return evalutor.EvaluateTemplate(fakeTemplateId, scope);
} catch (error) {
public static FromText(lgFileContent: string): TemplateEngine {
if (lgFileContent === undefined || lgFileContent === '') {
return new TemplateEngine();
}
try {
const input: ANTLRInputStream = new ANTLRInputStream(lgFileContent);
const lexer: LGFileLexer = new LGFileLexer(input);
const tokens: CommonTokenStream = new CommonTokenStream(lexer);
const parser: LGFileParser = new LGFileParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(TemplateErrorListener.INSTANCE);
parser.buildParseTree = true;
parser.errorHandler = new BailErrorStrategy();
const context: FileContext = parser.file();
return new TemplateEngine(context);
} catch (e) {
throw e;
}
}