How to use the antlr4ts/ANTLRInputStream.ANTLRInputStream function in antlr4ts

To help you get started, we’ve selected a few antlr4ts examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / vscode-cosmosdb / src / mongo / commands.ts View on Github external
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)) {
github microsoft / botbuilder-js / libraries / botbuilder-lg / src / lgParser.ts View on Github external
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();
    }
github microsoft / botbuilder-js / libraries / botbuilder-ai / src / lg / templateEngine.ts View on Github external
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) {
github microsoft / botbuilder-js / libraries / botbuilder-ai / src / lg / templateEngine.ts View on Github external
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;
        }
    }