intellij-plugin-v4 icon indicating copy to clipboard operation
intellij-plugin-v4 copied to clipboard

Testing rules that needs different lexer modes

Open omry opened this issue 5 years ago • 9 comments

Is there a way to test a rule that needs a different lexer mode?

As far as I can tell, there is no way to change the lexer mode from the plugin.

omry avatar Aug 21 '20 23:08 omry

Hi, it's not supported in the current version. I'll see if the interpreter used by the plugin supports this.

bjansen avatar Aug 30 '20 12:08 bjansen

Thanks. Can you point you to the interpreter used? In Python, there is a mode() function you can use on the Lexer:

istream = InputStream(s)
lexer = OverrideLexer(istream)
lexer.mode(OverrideLexer.VALUE_MODE)

Related to this: While working with modes (and having a customized output directory), the plugin left a tokens file (OverrideLexer.tokens) next to the lexer g4 file instead of in the output directory.

omry avatar Aug 30 '20 14:08 omry

The plugin is using a subclass of org.antlr.v4.tool.GrammarParserInterpreter.

The tokens file is probably a bug, the plugin is not always aware of the correct output directory (e.g. in Maven/Gradle projects). If the output directory was set manually in the settings dialog, then it's definitely a bug :)

bjansen avatar Aug 30 '20 18:08 bjansen

Woops sorry we're talking about a org.antlr.v4.runtime.LexerInterpreter, which extends org.antlr.v4.runtime.Lexer so it should be possible to change the mode. I just have to figure out the best way to integrate this in the current UI.

bjansen avatar Aug 30 '20 18:08 bjansen

Awesome. Once you figured out a good UI for it: I think something really nice to support is also making the mode sticky per rule. Once I change the mode for a rule, it should stay like this until I change it back.

omry avatar Aug 30 '20 18:08 omry

re: output directory: yes, it was set in the plugin settings.

omry avatar Aug 30 '20 18:08 omry

While working with modes (and having a customized output directory), the plugin left a tokens file (OverrideLexer.tokens) next to the lexer g4 file instead of in the output directory.

Investigating. Looks like a bug actually where are you can set the gen during the parser but it's ignored by the separate lexer. https://github.com/antlr/intellij-plugin-v4/issues/548

parrt avatar Apr 29 '22 20:04 parrt

Are we talking about setting just the starting mode for lexing? I think it would get very confusing if there's some state indicating which mode we are lexing in.

parrt avatar Apr 29 '22 20:04 parrt

I see this is still and open issue - What would be nice is to flag the starting mode (either from the Test Rule xxx ) by using a nest popup of the lexar modes or maybe by using an option on the rule to state the preferred starting mode for testing.

ferret1964 avatar Dec 15 '23 23:12 ferret1964