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

Debug antlr in vscode with launch.json #233

Open
Marouns opened this issue Nov 6, 2023 · 10 comments
Open

Debug antlr in vscode with launch.json #233

Marouns opened this issue Nov 6, 2023 · 10 comments

Comments

@Marouns
Copy link

Marouns commented Nov 6, 2023

I'm using vscode 1.84.0 and ANTLR4 grammar syntax support v2.4.2. I also installed Debugger for Java v0.55.0 and I have Java-11 installed.

The tokens, lexer and listener files are created. Now I want to launch a debug session using the launch.json to parse my file and debug. My launch.json looks like this:

`{
"version": "2.0.0",
"configurations":
[

    {
    "name": "mmmTable",
    "type": "antlr-debug",
    "request": "launch",
    "input": "inputs/mmm_Table.txt",
    "grammar": "grammars/mmmTable.g4",
    "startRule": "mmm_table",
    "printParseTree": true,
    "visualParseTree": true
    }
]

}`

I'm getting this error:

image

How should I launch and debug my parser using vscode ?

@mike-lischke
Copy link
Owner

It should start debugging the grammar you have specified in the launch config. Maybe it tries to start with the current grammar instead? You probably still have the launch config active. Try switching to a grammar tab and start again. If that works, there might be a bug in the debugger session creation.

@Marouns
Copy link
Author

Marouns commented Nov 6, 2023

Hello Mike,
I tried debugging both from 'mmmTable.g4' and from 'mmm_Table.txt'.
getting the same result.
What do you mean by "You probably still have the launch config active", as the debugger is active on the background ? restarted vscode and tried again...
OUTPUT: _[debug] No lexer interpreter data found at _

@mike-lischke
Copy link
Owner

If you see that "no interpreter data found" message it means that you should trigger a re-creation of that, by changing your grammar and saving it. You can also try to remove .antlr folder beside your grammar and then do the re-creation.

By "having the config active" I meant that this was your active editor tab. My suggestion was to switch to your grammar tab and try again to start debugging. This shouldn't be necessary as you have given a grammar (double check the path is correct!), but at least is worth a try.

@svee4
Copy link

svee4 commented Nov 7, 2023

I renamed both lexer and grammar files, deleted .antlr, restart VSCode, and it suddenly started working. Next I got an error along the lines of cannot read properties of undefined (reading inputStream), but this was also fixed by restarting VSCode. Now I get an error saying the grammar contains issues, which I assume means that the problem is on my end now.

After typing this, I tabbed back into VSCode and pressed F5, and I got hit with the same debugger creation failed message again. Restarting VSCode fixes it until I open the parser file. After the parser file has been opened once, the error repeats, until VSCode is restarted and parser file is kept unopened.

(By parser and lexer files, I'm referring to files that have parser grammer myp; and lexer grammar myt;, one of each).

Heres my launch.json:

{
	"version": "2.0.0",
	"configurations": [
		{
			"name": "Debug ANTLR4 grammar",
			"type": "antlr-debug",
			"request": "launch",
			"input": "input.txt",
			"grammar": "myp.g4",
			"startRule": "file",
			"printParseTree": true,
			"visualParseTree": true
		}
	]
}

VSCode settings:

{
	"antlr4.generation": {
		"mode": "internal",
		"language": "Java",
		"listeners": true,
		"visitors": false
	}
}

Directory looks like this
image

For the record I'm very new to ANTLR

@Marouns
Copy link
Author

Marouns commented Nov 8, 2023

Hi,
same settings is working on Windows 10.
On windows 11 same settings, got to a point where I trigger the debug and nothing happens, no Error no output. Tried all the above.

@svee4
Copy link

svee4 commented Nov 8, 2023

I also got no output no error, when I pressed F5 in a non-.g4 file. Though this didn't happen always, I dont remember the exact circumstances.

I'm on Windows 11 with WSL2 Ubuntu.

@Marouns
Copy link
Author

Marouns commented Nov 11, 2023

@mike-lischke any insights on differences for win 10 and win 11 ? any clue for what it might be ?

@ToughKnee
Copy link

I also got problems on Windows 11, specifically the error "Could not launch debug session: the grammar contains issues.", I've tried deleting the directory and restarting in a lot of ways vscode but the same error kept appearing, and I know my grammar file and settings for the setup for debugging are fine because they are the literal same in another computer I have which has WInodws 10, and the extension works fine in there, it seems Windows 11 somehow gives problem to this extension

@ToughKnee
Copy link

ToughKnee commented Jan 19, 2024

Ok I've found the solution to it that may work for someone that is struggling with this
Basically the error I got previously was actually happening in my Windows 10 pc too, the thing is that in the launch.json, the "grammar" value had a really long path in my case, but if I copy and pasted the same exact grammar to another file, BUT placed the file in a simpler location like 'C:/Desktop', and specified that location to the launch.json, then the antlr extension started working and printing the parse tree
And now this extension works both in Windows 10 and 11, also the "input" value did not need to relocate the file
I don't know the exact problem, but that is the solution I found

@mike-lischke
Copy link
Owner

Sounds like either a too long path or some special chars in it, that are not visible (e.g. zero width characters, which got removed when you copy/pasted the path around).

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

4 participants