tunnelvisionlabs / antlr4ts

Optimized TypeScript target for ANTLR 4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generated Parser refers to C++ Classes (std::set<std::string>), unable to compile TS

bskp opened this issue · comments

commented

I am using antlr4ts 0.5.0-alpha.4 to generate a parser for the SQL dialect ClickHouse with the following Grammar:

While the lexer is fine, to my surprise, the generated ClickHouseParser.ts (link to Gist) contains type references which look like C++-Sets to me (excerp from row 13035):

(...)
export class EngineClauseContext extends ParserRuleContext {
	public clauses: std::set<std::string>;
	public engineExpr(): EngineExprContext {
		return this.getRuleContext(0, EngineExprContext);
	}
	public orderByClause(): OrderByClauseContext[];
	public orderByClause(i: number): OrderByClauseContext;
	public orderByClause(i?: number): OrderByClauseContext | OrderByClauseContext[] {
(...)

This line up with the used methods on clauses,

  • count() and
  • insert()

which are both present in the C++ standard libraries' Set implementation, but not in the JavaScript built-in Set implementation, which uses size/add.

For comparison, I also generated a parser using the "standard" antlr, v. 4.9.3 which was able to produce a functioning Javascript parser. Is this issue linked to a bug in antlr4ts, or a problem with the grammar?
Thank you for any pointers!

Those types come from the grammar, e.g. https://github.com/ClickHouse/ClickHouse/blob/d4a1b71b184a06f515fb3d8bb23f4c315528d815/utils/antlr/ClickHouseParser.g4#L127
Maybe the JS target works because it omits types altogether?