antlr / antlr/antlr4

lexer grammar, import names very particular

Open
#560 5 comments 0 reactions 0 assignees View on GitHub
type:feature
Dominant language
Java
Stars
19k
Forks
3.5k
PR merge metrics
No merged PRs in 30d

Description

I split a grammer into a parser and a lexer. It appears the runtime package is very particular about the selected names. I had a lexer named 'SomeLex' and a parser 'SomeParser'.

```
$ grun SomeParser r
Exception in thread "main" java.lang.ClassCastException: class SomeParser
at java.lang.Class.asSubclass(Class.java:3126)
at org.antlr.v4.runtime.misc.TestRig.process(TestRig.java:159)
at org.antlr.v4.runtime.misc.TestRig.main(TestRig.java:143)
$ grun Some r
Can't load Some as lexer or parser
```

Changing the lexer to 'SomeLexer' fixed the problem. By the way, I was using antlr4. The parser used tokenVocab to import the lexer. I would attach the files, but I don't see a way to do that in the github error report. The files were trivial: one rule (r) in the parser, three simple token rules in the lexer.

Contributor guide

Open the contributing guide

Research direction

Start with org.antlr.v4.runtime.misc.TestRig.process and reproduce the split-grammar case using the reported SomeLexer/SomeParser names and tokenVocab setup. Done means the runtime handles the naming arrangement consistently, with a regression test covering the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.