Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

antlr4-tool can't handle superClass #32

Open
jgellin-sf opened this issue Jul 14, 2020 · 0 comments
Open

antlr4-tool can't handle superClass #32

jgellin-sf opened this issue Jul 14, 2020 · 0 comments

Comments

@jgellin-sf
Copy link
Contributor

This is a super useful tool. I am trying to generate my grammar to multiple target languages (Typescript/Javascript and Java). Since I have some predicates, I have written a base parser class with the same name in each target language and referring to it with the superClass option. This problem/approach are similar to those described here: https://stackoverflow.com/questions/45196413/ways-of-keeping-antlr4-grammar-target-independent.

When I use antlr4-tool on this grammar I get the following:

Compiling src/json.g4...
evalmachine.<anonymous>:74
jsonParser.prototype = Object.create(BaseParser.prototype);
                                                ^

TypeError: Cannot read property 'prototype' of undefined
    at evalmachine.<anonymous>:74:49
    at Script.runInContext (vm.js:127:20)
    at Object.runInContext (vm.js:290:6)
    at Object.readParser (/issue/node_modules/antlr4-tool/dist/antlr-core/parser-util.js:34:8)
    at AntlrCompiler.compileTypeScript (/issue/node_modules/antlr4-tool/dist/antlr-core/antlr-compiler.js:66:37)
    at /issue/node_modules/antlr4-tool/dist/antlr-core/index.js:40:78
    at /issue/node_modules/antlr4-tool/dist/antlr-core/index.js:17:23
    at arrayEach (/issue/node_modules/lodash/lodash.js:516:11)
    at Function.forEach (/issue/node_modules/lodash/lodash.js:9342:14)
    at compileWithFunction (/issue/node_modules/antlr4-tool/dist/antlr-core/index.js:9:7)

The Javascript seems to generate OK, it's just the Typescript declarations that fail. I created the simplest base parser class I could in Typescript:

import { CommonTokenStream, Parser } from "antlr4";

export class BaseParser extends Parser {
  constructor(input: CommonTokenStream) {
    super(input);
  }
}

I compiled this code to ES5, then ran antlr4-tool and got the above error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant