How to test rule for input text?
minesunny opened this issue · 8 comments
Can you add more details to your question? I have no idea what you mean.
Can you add more details to your question? I have no idea what you mean.
I want to test the rule for input text like idea antlr plugin which can test input the text for the rule in real time; I know vscode-antlr4's debug is powerful than that,but I want to have a easy and fast way to show the result of input text;
That's covered in the debugger documentation. You specify an input file in the launch options and whether you want to see textual and/or graphical parse trees.
That's covered in the debugger documentation. You specify an input file in the launch options and whether you want to see textual and/or graphical parse trees.
I know that; I thank that is not a simple way to view the result of the input text quickly
launch options only for one input text and one start rule at once;
Ah, it wasn't clear from your question how far you looked for a solution. Unfortunately, there's no other way to test a grammar with specific input.
Ah, it wasn't clear from your question how far you looked for a solution. Unfortunately, there's no other way to test a grammar with specific input.
I use debug with input text,it need some steps to configure;
- create a launch.json, specify a test,and start rule
{
"version": "2.0.0",
"configurations": [
{
"name": "Debug ANTLR4 grammar",
"type": "antlr-debug",
"request": "launch",
"input": "${fileDirname}/${fileBasenameNoExtension}.test.txt",
"grammar": "${file}",
"startRule": "startRule",
"printParseTree": true,
"visualParseTree": true,
}
]
}
- write text in test.txt file;
- click debug button;
what if I want to change start rule right now, I need to change startRule in lanunch.json, but I find a way like this using 'extension.commandvariable.selectedText'
{
"version": "2.0.0",
"configurations": [
{
"name": "Debug ANTLR4 grammar",
"type": "antlr-debug",
"request": "launch",
"input": "${fileDirname}/${fileBasenameNoExtension}.test.txt",
"grammar": "${file}",
"startRule": "${input:startRule}",
"printParseTree": true,
"visualParseTree": true,
}
],
"inputs": [
{
"id": "fileBasenameNoExtensionLowerCase",
"type": "command",
"command": "extension.commandvariable.transform",
"args": {
"text": "${fileBasenameNoExtension|lowerCase}"
}
},
{
"id": "startRule",
"type": "command",
"command": "extension.commandvariable.selectedText",
"args": {
"separator": "@--@"
}
}
]
}
only I put cursor on ruleName and click debug button, it will auto change start rule;
but if I want to test another text ,I need to repeat step 2 and 3; step 2 is needed but no step 3;
would it be a feature in the futher which can provide a way to test a rule with given text or input file;
That's a pretty clever solution, thanks for sharing it!
I was thinking in the past if somehow the rule with the cursor in it could be used as start rule. Unfortunately, VS Code doesn't allow to add controls to an editor window, like a drop down that allows to select a rule. Also the sidebar doesn't help here, because it stays in sync with the caret.