I am currently attempting to incorporate the antlr4 parser into an angular project.
Within a dataservice class, there is a function being called that appears as follows:
parseRule() {
const ruleString = ' STRING TO PARSE';
const inputStream = new ANTLRInputStream(ruleString);
const lexObject = new lexer.scopeLexer(inputStream);
const tokenStream = new CommonTokenStream(lexObject);
const parseObject = new parser.scopeParser(tokenStream);
const result = parseObject.file();
const evaluator = new ScopeEvaluator();
const walker = new ParseTreeWalker();
walker.walk(evaluator, result);
console.log('result:', result.text);
}
A customer listener is implementing the interface, exported with just one method - enterNonGraphScope.
import { scopeListener } from './antlrscope/scopeListener';
import { NonGraphScopeContext, NamesetSimpleContext } from './antlrscope/scopeParser';
export class ScopeEvaluator implements scopeListener {
constructor() {
console.log('constructed the asdfasf');
}
enterNonGraphScope = function (ctx: NonGraphScopeContext) {
console.log('Tis', ctx.text);
};
}
Included below is an excerpt from the scopeListener.ts file for clarifying the interface:
export interface scopeListener extends ParseTreeListener {
/**
* Enter a parse tree produced by the `NonGraphScope` labeled alternative in `scopeParser.scope`.
* @param ctx the parse tree
*/
enterNonGraphScope?: (ctx: NonGraphScopeContext) => void;
While running the Angular's ng serve command (which compiles TypeScript code), I encounter the following error:
ERROR in src/app/rule-parser.service.ts(31,17): error TS2559: Type 'ScopeEvaluator' has no properties in common with type 'ParseTreeListener'.
Displayed below is the listener generated in TypeScript. (Excluding contents and comments generated by Antlr)
export interface scopeListener extends ParseTreeListener {
...
}
It seems like there might be some issues related to the interpretation or typing of TypeScript. As I am relatively new to JavaScript/TypeScript, any assistance would be greatly appreciated.
The webpack/generated JavaScript code works without any problems, but this particular error stands in the way of successfully generating the build.
Thank you!
-Vinayak