Code Monkey home page Code Monkey logo

vscode-antlr4's Introduction

Build & Test

logo VS Code Extension for ANTLR4 Grammars

The extension for ANTLR4 support in Visual Studio Code.

What's New

Externalized the formatter into an own Node.js package for broader use.

How To Contribute

If you want to create your own version of this extension or plan to contribute to its development then follow the steps outlined in the contribute.md document.

Features

Feature Overview

Syntax Coloring

  • Syntax coloring for ANTLR grammars (.g and .g4 files)

Syntax Coloring

  • Comes with an own beautiful color theme, which not only includes all the recommended groups, but also some special rules for grammar elements that you won't find in other themes (e.g. alt labels and options). They are, immodestly, named Complete Dark and Complete Light.

Code Completion + Symbol Information

  • Code suggestions for all rule + token names, channels, modes etc. (including built-in ones).
  • Symbol type + location are shown on mouse hover. Navigate to any symbol with Ctrl/Cmd + Click. This works even for nested grammars (token vocabulary + imports).

  • Symbol list for quick navigation (via Shift + Ctrl/Cmd + O).

Grammar Validations

  • In the background syntax checking takes place, while typing. Also some semantic checks are done, e.g. for duplicate or unknown symbols.

  • When parser generation is enabled (at least for internal use) ANTLR4 itself is used to check for errors and warnings. These are then reported instead of the internally found problems and give you so the full validation power of ANTLR4.

More Information

There are a number of documentation files for specific topics:

Miscellaneous

  • There is an option to switch on rule reference counts via Code Lens. This feature is switchable independent of the vscode Code Lens setting.

  • For each grammar its dependencies are shown in a sidebar view (i.e. token vocabulary and imports).

Known Issues

See the Git issue tracker.

What's planned next?

Bug fixing and what feels appealing to hack on.

Release Notes

2.4.5 - 2.4.6

  • Upgraded dependencies.
  • Fixed bug #242 Visual parse tree not showing for version 2.4.5

2.4.4

  • Upgraded to the latest formatter package to fix a number of issues.

2.4.3

  • Updated 3rd party dependencies.
  • Extracted the formatter into an own Node.js package for broader use.
  • Added new animation to call graphs, which highlights (in steps) which rule calls another rule. This is an implementation from Garry Miller.
  • Fixed bug #134 alignColons formatting setting affects semicolon on first line
  • Fixed bug #151: Formatting comments adds empty lines in some situations
  • Fixed bug #150: Language server fails to accept 'fail' option after semantic predicate.
  • Added support for predicate options.
  • Fixed bug #180: How to pass multi CLI arguments to antlr?
  • Fixed bug #182: Setting no generation language should not automatically apply Java as default
  • Fixed bug #210: RangeError: Maximum call stack size exceeded
  • Added a check to avoid endless recursion if a grammar uses itself as token vocabulary.
  • Added a new semantic check for this (erroneous situation).
  • Interpreter data is now also regenerated on start of the extension, if the grammar is newer than existing data and diagnostic checks are executed on startup.
  • Fixed bug #235: Extension does not work on Windows

2.4.0 - 2.4.2

  • Switched to a new TypeScript runtime (antlr4ng), which supports the latest features from ANTLR4 (e.g. case sensitive identifiers).
  • Fixed bug #195: Extension breaks if filename ends with Parser
  • Fixed bug #197: Use lexer token labels when generating tokens in debug console
  • Fixed bug #218: Activation fails with TypeError: Invalid host defined options
  • Fixed bugs in the formatter (last token removal and wrong action with copy/paste).
  • Fixed a bug in the ATN graph renderer, where rule name + index were not properly updated, when navigating between rules.
  • Railroad diagrams received a big overhaul:
    • Updated to latest version of the generation script.
    • Added a button for exporting all diagrams in the all-rules list to individual SVG files.
    • Added a new option to specify a character length in a line, after which an path is wrapped. This is useful for long alternatives.
    • All CSS rules (including custom ones) are now inlined into exported SVG files, to avoid CSP problems.
    • The all-rules list can now be filtered by typing a regular expression and only the visible diagrams are exported.
    • A new option allows to strip out a part of rule names (e.g. a common _SYMBOL suffix), while rendering the SVG.

2.3.1

A bug fix release for even stricter content security policies in VS Code starting at version 1.73.

  • Fixed bug #192: Broken Parse Tree Window on VSCode v1.73

2.3.0

  • Now using ANTLR 4.9. Cannot use the just released 4.10 because of TS runtime incompatibilities.
  • Fixed bug #104: Cannot read property 'document' of undefined error being thrown
  • Fixed bug #120: "antlr4.customcss": probably wrong type configuration.
  • Improved ATN diagrams:
    • Unused ATN states are no longer visible in the graph.
    • Initial rendering of the graph is now much faster, by doing the initial element position computation as a separate step, instead of animating that.
    • Transitions for actions, predicates and precedence predicates now show a label that indicates their type.
    • The action transitions now show their action (or predicate) in the ATN graph as additional label.
    • The custom CSS setting name has been changed to cause no spelling trouble (from customcss to customCSS). Documentation was updated as well.
  • Improved predicate execution:
    • Simplified the required JS code for predicate simulation in the debugger, sentence generation and test execution. See Grammar Debugging for details.
    • Labels for links now rotate sooner to horizontal position (45° instead of 75° of link angle), which makes for a nicer display.
  • Improved sentence generation:
    • Sentence generation is now available in grammar files. See Sentence Generation for details.
    • Show a special char if no printable char could be generated (due to filtering).
    • For virtual tokens the name is now printed instead of nothing (as they have no attached label), if no mapping is specified for them.
    • Inclusion of Unicode line terminators can now be enabled, to allow generating them where possible.
    • Sentence generation can now be configured per grammar. See the documentation for that.
  • Improved action and predicate handling/display:
    • Named actions, standard actions and predicates now have hover information.
    • Action types are now grouped for more details in the "Actions & Predicates" section. This also is part of better predicate handling (correct action index).
    • There are now separate entries for local and global named actions.
    • Exception blocks, lexer actions (more, pushMode etc.) and similar action blocks are tagged properly in the symbol table now and show as such in the actions section.
    • Action transitions in the ATN graph now show their type + index.
  • Elements in railroad diagrams now have a CSS class, to make them better customizable.
  • D3.js is a dependency of the extension and hence shipped with it. But the webviews downloaded an own copy of that lib for their work. Now they use the shipped D3.js code.
  • There is now a language injection definition for Markdown files, to syntax highlight ANTLR4 code in these files. Just specify antlr as language for triple-backtick code blocks to see it.
  • Improved the file generation process:
    • Generation continues if multiple files take part (e.g. those imported) and one of them has an error.
    • Errors coming up while running Java are now reported to the frontend. Also shows a hint if no Java is installed.

2.2.4

  • You can now specify an alternative ANTLR4 jar file for parser generation and also use custom parameters. Both values can be set in the generation settings of the extension.
  • Handling of debug configuration has been changed to what is the preferred way by the vscode team, supporting so variables there now.
  • Further work has been done on the sentence generation feature, but it is still not enabled in the extension, due to a number of issues. Help is welcome to finished that, if someone has a rather urgent need for this.
  • The extension view for ANTLR4 grammars now shows only relevant views for a specific grammar (e.g. no lexer modes, if a parser grammar is active).
  • Code evaluation for grammar predicates has been changed to use an own VM for isolation. Plays now better with vscode (no need anymore to manually modify the imports cache).
  • Updated ANTLR4 jar to latest version (4.8.0). It's no longer a custom build, but the official release.
  • ESList has been enabled and the entire code base has been overhauled to fix any linter error/warning.

2.2.0

  • Update to latest antlr4ts version.
  • Added a new view container with sidebar icon for ANTLR4 files.
  • Added lists of actions and predicates in a grammar to the sidebar.
  • Added support for predicates in grammars. Code must be written in Javascript.
  • Improved stack trace display in debug view.
  • Reorganized documentation, with individual documents for specific aspects like debugging.
  • Enhanced parsing support for tests, with an overhaul of the lexer and parser interpreters.
  • Textual parse trees now include a list of recognized tokens.
  • Improved sentence generation, using weight based ATN graph traveling. Added full Unicode support for identifier generation and a dedicated test for this. Still, the sentence generator is not yet available in the editor.
  • Overhaul of most of the used extension icons (with support for light + dark themes).
  • Added a reference provider.
  • Fixed Bug #87: Omitting start rule doesn't fallback to first parser rule (when debugging)
  • Graphs no longer need an internet connection (to load D3.js). Instead it's taken from the D3 node module.
  • Added content security policies to all graphs, as required by vscode.

2.1.0

  • Fixed Bug #41: Plugin Internal Error on EOF
  • Fixed Bug #48: Not possible to use ${} macros in launch.json
  • Merged PR #59: Fix CodeLens positions being off by one while editing and reference count being wrong
  • Fixed re-use of graphical tabs (web views), to avoid multiple tabs of the same type for a single grammar. Also, parse tree tabs now include the grammar's name in the title, just like it is done for all other tabs.
  • Added live visual parse trees and improved their handling + usability. No more jumping and zooming to default values on each debugger run.
  • Fixed a number of TS warnings.
  • Added two parse tree related settings (allowing to specify the initial layout + orientation).
  • Improved handling of certain ANTLR4 errors.
  • Re-enabled the accidentally disabled code completion feature.

2.0.4

  • Fixed Bug #36: "$antlr-format off" removes remaining lines in file
  • Fixed Bug #37: Debugging gets stuck with visualParseTree set to true

2.0.3

  • Updated tests to compile with the latest backend changes.
  • Fixed a bug when setting up a debugger, after switching grammars. Only the first used grammar did work.

2.0.2

  • Fixed Bug #28: ATN graph cannot be drawn even after code generation.
  • Fixed another bug in interpreter data file names construction.

2.0.1

  • Bug fix for wrong interpreter data paths.
  • Implicit lexer tokens are now properly handled.
  • Fixed a bug in the formatter.

2.0.0

  • The extension and its backend module (formerly known as antlr4-graps) have now been combined. This went along with a reorganization of the code.
  • A rename provider has been added to allow renaming symbols across files.

1.3.0

  • Added grammar debugger.
  • Added graphical and textual parse tree display.

1.2.5

  • Added dependency graph.
  • Added call graph.

1.1.5

  • Added ATN graphs.
  • Added SVG export for ATN graphs + railroad diagrams.
  • Now showing a progress indicator for background tasks (parser generation).

1.0.4

  • Added code lens support.
  • Added code completion support.
  • Finished the light theme.

1.0.0

  • Rework of the code - now using Typescript.
  • Adjustments for reworked antlr4-graps nodejs module.
  • Native code compilation is a matter of the past, so problems on e.g. Windows are gone now.
  • No longer considered a preview.

0.4.0

  • Updated the symbol handling for the latest change in the antlr4-graps module. We now also show different icons depending on the type of the symbol.
  • Updated prebuilt antlr4-graps binaries for all platforms.
  • Quick navigation has been extended to imports/token vocabularies and lexer modes.
  • The symbols list now contains some markup to show where a section with a specific lexer mode starts.
  • Fixed also a little mis-highlighting in the language syntax file.
  • Added a license file.

0.3.4

Marked the extension as preview and added prebuilt binaries.

0.2.0

  • full setup of the project
  • added most of the required settings etc.
  • included dark theme is complete

For further details see the Git commit history.

Other Notes

The dependencies view icons have been taken from the vscode tree view example.

vscode-antlr4's People

Contributors

adhirramjiawan avatar arlm avatar chris-miner avatar dependabot[bot] avatar drkv333 avatar emiliosheinz avatar ghost4man avatar hazer-hazer avatar hazmat345 avatar joinedsenses avatar lublak avatar mike-lischke avatar millergarym avatar mjbvz avatar mrd1996 avatar oab avatar racz16 avatar ralfhandl avatar serras avatar uwx avatar wopss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vscode-antlr4's Issues

Export Call Tree also with "interactive highlights" not only as static SVG

Hello Mike,

I was wandering if there is any way how to export Parse Tree with that "interactive highlights" (when hovering above categories nodes) as now if I am correct it "only" (very impressive and cool regardless) as static SVG. Is there at least any way how to hack it in any way or form into at least half decent format (I assume combination of js and html is in place right now)

Thanks for any help!

antlr4.generation.outputDir doesn't seem to be working

I'm trying to use antlr4.generation.outputDir to prevent the plugin from making a .antlr directory relative to my antlr files but changing it doesn't seem to work. I've restarted VSCode after updating the config and I'm still getting the .antlr directory.

For what it is worth I think creating a directory next to the source code isn't a great default either, but I'm happy to use the setting to move it. I just can't figure out how to get it working.

Lexer grammar ignored + debug not working

ctdLexer.g4

lexer grammar ctdLexer;
DOT: '.';

ctdParser.g4

parser grammar ctdParser;
main: DOT;

it always says:

warning(125): c:\Users\*******\test\grammar\ctdParser.g4:2:6: implicit definition of token DOT in parser

{
    "version": "2.0.0",
    "configurations": [
        {
            "name": "test",
            "type": "antlr-debug",
            "request": "launch",
            "input": "input.txt",
            "grammar": "grammar/ctdParser.g4",
            "startRule": "main",
            "printParseTree": false,
            "visualParseTree": false,
            "windows": {
                "trace": false
            }
        }
    ]
}

debugging throws this error:

Error while launching debug session: TypeError: Cannot set property 'inputStream' of undefined

Am i missing something?

Format incorrect when columnLimit is set to 0

When setting antlr4.format.columnLimit to 0, the format becomes weird:

image

comparing to what I expect:

image

My configuration is like below:

{
    "antlr4.format.alignColons": "hanging",
    "antlr4.format.alignSemicolons": "ownLine",
    "antlr4.format.allowShortRulesOnASingleLine": false,
    //"antlr4.format.columnLimit": 0,
    "antlr4.format.columnLimit": 10000,
    "antlr4.format.useTab": false,
    "antlr4.generation.mode": "external",
    "antlr4.generation.outputDir": "/.antlr",
}

We need a "for dummies" Quickstart Guide

I really appreciate this great project but there is a need for a quickstart: ok, I installed the extension, I see the syntax highlight but where is the other stuff? Do I need ANTLR preinstalled? If so, how can I reference the ANTLR installation to this extension?

With just a few steps in a numbered list and prerequisites the experience would be greater and the audience can grow even more! I think this saves neuron energy consumption where there is no need to think.

Thank you.

parse tree

I really liked this plugin but I really miss the parseTree view I had back in IntelliJ and Eclipse.
Basically given a grammar and example source input it display the AST graphically.
ideally, the example source input could be a file or a text area + with live update over the AST graph view.

If this feature is already in please let me know who to fire it up.

Many Thanks
Felipe

Issue using C#

Hi,
I'm having an issue using the nuget Antlr4 version 4.6.5-beta002 with the extension. I think it's due to a version mismatch. The extension seems to be generating code for antlr 4.7.2.

image

How to configure the output folder of generated parser code?

I just updated to 2.0.0. But I see no more setting entry to configure the output folder for generated parser.

Did I miss something? I only see below config entries:

  // Max number of labels displayed on a transition in an ATN graph
  "antlr4.atn.maxLabelCount": 3,

  // Default export target folder for ATN SVG files
  "antlr4.atn.saveDir": "",

  // Default export target folder for call graphs
  "antlr4.call-graph.saveDir": "",

  // List of custom CSS URIs for diagram SVG files
  "antlr4.customcss": [],

  // Debugging related settings
  "antlr4.debug": {},

  // Settings related to parser generation
  "antlr4.format": {
    "alignTrailingComments": false,
    "allowShortBlocksOnASingleLine": true,
    "breakBeforeBraces": false,
    "columnLimit": 100,
    "continuationIndentWidth": 4,
    "indentWidth": 4,
    "keepEmptyLinesAtTheStartOfBlocks": false,
    "maxEmptyLinesToKeep": 1,
    "reflowComments": true,
    "spaceBeforeAssignmentOperators": true,
    "tabWidth": 4,
    "useTab": true,
    "alignColons": "none",
    "singleLineOverrulesHangingColon": true,
    "allowShortRulesOnASingleLine": true,
    "alignSemicolons": "none",
    "breakBeforeParens": false,
    "ruleInternalsOnSingleLine": false,
    "minEmptyLines": 0,
    "groupedAlignments": true,
    "alignFirstTokens": false,
    "alignLexerCommands": false,
    "alignActions": false,
    "alignLabels": true,
    "alignTrailers": false
  },

  // Settings related to parser generation
  "antlr4.generation": {
    "mode": "internal",
    "language": "Java",
    "listeners": true,
    "visitors": false
  },

  // Enable/disable the references code lens
  "antlr4.referencesCodeLens.enabled": false,

  // Default export target folder for railroad diagrams
  "antlr4.rrd.saveDir": ""

Parse Tree Visualization not showing

Hello Mike,

I love your extension and its absolutely genius, however I already struggled a bit with making it work even on a dummy test project and I cannot get a graph visualization or cannot find the way how to invoke / trigger it in VS.

Took mi already few hours to translate "open via context menu of IDE" to 3 dots in the end of open files tab, there I found the Railroad diagram, but not the ParseTree Graph.

Also I am getting print tree correctly in Debug Console so probably only the case of finding how to show it in VS Code?

Config should be alright:
{
"name": "antlr4",
"type": "antlr-debug",
"request": "launch",
//"input": "${workspaceFolder}/${command:AskForTestInput}",
"input": "input.txt",
"grammar": "Expression.g4",
"startRule": "startWithEOF",
"visualParseTree": true,
"printParseTree": true
}

Best regards,
Simon

Add debug output for the extension in vscode

When dealing with separate lexer and parser grammar, tokens added to lexer file after tokenVocab in parser file is specified will cause "Unknown token reference" error, even after regeneration (clean .antlr folder and save lexer/parser files again, or manually call antlr4 from terminal, anyway).

Language Server Implementation fro ANTLR4

I was developing ANTLR4 Grammar projects, however, came up with the question of whether it was possible to create a Language Server for an ANTLR4-based language that I've created. If so, what is the procedure to do that?
I'm still very new to ANTLR4. Your help is greatly appreciated!

Generate visitors

Plugin looks great.

How do I

  1. Set the output path? The ".antlr" directory doesn't work well with my webpack setup, I need to place the sources under "../src"

  2. How do I configure it to generate Visitor and Listener interfaces?

Thanks!

Interactive Debugger view

Having a textbox in where you can type and see the parsing results while typing could be very helpful.
Also the other way around, in where the input text gets parsed while the grammar is being updated.

Not sure if it can be done, but it could be helpful.

Not generating the code

Hello,

I'm using the extension with 2 computers using Windows 10 Pro 64 bits. On my Surface pro, it's working fine generating the sources. But on my desktop computer, I have ANTRL in the status bar with the progress indicator but it doesn't generate the sources.

In the output console, I have this error:
[2018-02-17 08:58:19.214] [renderer1] [error] spawn java ENOENT : Error: spawn java ENOENT
at exports._errnoException (util.js:1050:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:367:16)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)

I'm using Java 8 on both computer.

Regards,
Stef

Actions containing curly braces not recognized correctly

I have javascript actions that look like this:

element_modification returns [v]
   : name { $v = { name: $name.text }; } (modification { $v.modification = $modification.v; } )? string_comment { $v.comment = $string_comment.v; }
   ;

The nested object literals with curly braces cause the above line to be highlighted incorrectly.

If I modify antlr.json to make "action" recursive it fixes it:

"action": {
  "name": "entity.other.block.antlr",
  "begin": "\\{",
  "end": "\\}",
  "patterns" : [
    { "include" : "#action" }
  ]
},

Not sure if this is the best thing to do though? I've never really messed with these textmate files before.

Problems disappear (or change) after saving

The visual example (sry the quality is suck):

screenshot

Well, I can't tell whether this is a bug of the extension or vsc itself. Anyway, please try to reproduce this to figure out.

Parse tree rendering fails in the presence of rules matching an empty string

I have the issue mentioned in the title in the current version in the VS Marketplace (2.0.4).

MCVE:

grammar:

grammar TreeVisualizationFail;

LETTER : [a-zA-Z];
DIGIT : [0-9];

 
startRule : digits letters EOF;

letters : LETTER+;

digits : DIGIT*;

input:

foo

Note that for the given input the mandatory rule digits in startRule matches no tokens, i.e. an empty string.

After making digits optional in startRule and forcing digits to match at least one digit, the parse tree visualization gets generated.

Originally, I encountered this problem with a grammar used to parse VBA.

Debug visualization improvements

When debugging, the graph nodes cover lines and the tokens (see image).

It would be good to be able to have settings in the configuration to:

  1. increase the separation
  2. choose straight lines or the current ones
  3. colors for lines, tokens and nodes
  4. collapse rules

capture

Semantic predicates are not behaving correctly

This is a weird issue, when using semantic predicates, the generated grammar behaves incorrectly in debugging mode, a good example from the ANTLR4 book:

grammar Data;

file: group+;
group: INT sequence[$INT.int];

sequence[int n]
	locals[int i = 1;]: ( {$i<=$n}? INT {$i++;})*;

INT: [0-9]+;
WS: [ \t\n\r]+ -> skip;

Running against this sample data:

1 23 3 6 8 4

Against antlr4 tools (4.7.1) returns correctly:

antlr4_parse_tree

But the same parse tree is incorrect in VSCode ANTLR4:

screen shot 2018-09-21 at 17 24 36

I think it has something to do with ANTLR binaries, because if I try the same in latest IntelliJ ANTLR4 plugin (version 1.8.4) I see the same invalid tree:

screen shot 2018-09-21 at 17 29 01

Suggestion: allow expanding / collapsing nodes in railroad diagram view

For example, in the following railroad diagram:
image
there should be some way to expand the LineContinuation node to its full definition, in-place:
image
One issue: how should the expand be triggered? If this was the only possible interaction, then I would suggest clicking on the node should expand (what about collapse). However, perhaps clicking should be reserved for navigation within the railroad diagram view (#25); this would require some kind of additional UI.

How to show ATN Graph?

On Windows 10 I selected a rule from a parser g4 file, and right click to fire "Show ATN ...", but got "No ATN data found (code generation must run at least once in internal or external mode)"

I do understand this message, but how do I run the code gen?

Debugger won't work when using 'external' mode

When I set mode to 'external' to generate JavaScript output I have to manually copy the .interp files into the .antlr folder to get the debugger to run. Without the the files in the .antlr folder I get the following error message when trying to run the debugger.
errormessage
I'm using version 2.0.2.

Extra final newlines after formatting

When file contains final newline, formatting will increase the number of final newlines to min(antlr4.format.minEmptyLines, antlr4.format.maxEmptyLinesToKeep) + 1. It won't happen if there's no final newline in the file.
Maybe an upstream bug?

Files generated in `.antlr` directory

I haven't looked closely at vscode-antlr4, but I am using it. Thanks Mike.

I noticed generated files getting added to a .antlr directory under where my .g4 files are located. I'm guessing this came from vscode-antlr4, right?

I'm not saying that is a bug, in fact I was thinking about doing something similar in antlr4ts-cli, though I considered putting it in a temp directory outside the source tree. Is there some reason you chose to put it into the source directory? Any related thoughts?

I'm also interested in the ".interp" file format generated in this directory. Can you point me at anything about this format?

How to display graphs?

I’ve created a .g file which contains grammar rules but I don’t know how to parse input file and display graphs.
I would be really great full if you could you help me.

"$antlr-format off" removes remaining lines in file

  1. Put the following in a .g4 file
  2. Open in vscode
  3. format doc (SHIFT+ALT+F, or save if auto format is on)
    !) Everything from the antlr-format line and on is deleted
grammar mongo;

// $antlr-format off

@lexer::members {
	private isExternalIdentifierText(text) {
		return text === 'db';
	}
}

mongoCommands: EOF;

Suggestion: allow navigation via railroad diagram view

Allow navigating to a child node in the railroad diagram view, from the railroad diagram view.

I think the natural interaction choice would be to click on the node.

Perhaps this could be implemented by passing some sort of dummy URL as the second parameter to the JS library used to generate the diagrams, and registering a global handler for this dummy URL to navigate to the appropriate node.

How to configure language generation settings

Trying to learn ANTLR and enjoying this extension greatly for debugging grammar. I'm getting to the point I'm wanting to start integrating the grammar into a project and while I see settings for configuring the language output, from the sparse documentation it is unclear to me how to configure the extension to output additional grammars (where should the setting file be placed in the folder & how . Is this possible or do I need to run the grammar through the command line?

It would be nice if the builds were in the same project so that I can iterate between the without moving back & forth.

Parse tree in same window as input file

When debugging an input file, the parse tree is written to files that all have the same name "Parse Tree". This makes it very difficult to keep track of which file goes with which run. As an example, if I want to compare the results of parsing 2 separate input files, it quickly becomes unmanageable and significantly interrupts the typical workflow.

Instead of displaying the parse tree in a separate file, is it possible to:

  1. Create a split pane within the input file window itself to display the parse tree for that file? or
  2. Rename the parse tree file to match that of the input file (e.g. "Parse Tree - My Input File")?

Graphs not rendering

None of the graphs are rendering (parse tree, rule, call graph). Just a grey box is shown.

image

Grammar (datadef.g4)

grammar datadef;

file: tabledef*;
tabledef: ID '{' ('types' '{' typedef (',' typedef)* '}')? memdef (',' memdef)* '}' ';';
typedef: ID ':' typeref;
memdef: ID ':' typeref;
typeref: (ID | PRIMITIVE)+;

PRIMITIVE: 'str' | 'num';
ID: [a-zA-Z_][a-zA-Z0-9_-]*;
BLOCK_COMMENT: '/*' .*? '*/' -> skip;
LINE_COMMENT: '//' ~[\r\n]* -> skip;
WHITESPACE: [ \t\f\r\n] -> channel(HIDDEN);
INVALID_INPUT: [\u0001-\u0008] | '\u000B' | '\u000C' | [\u000E-\u001F];

Test input (input.def)

MyTable {
    types {
        type1 : num str num,   // comment 1
        type2 : num type1 str
    }
    mem1: num str type1,
    mem2: num,
    mem3: type1 type1 type2
};

// comment 2

Debug configuration

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "antlr4-datadef",
            "type": "antlr-debug",
            "request": "launch",
            "input": "input.def",
            "grammar": "datadef.g4",
            "startRule": "file",
            "printParseTree": true,
            "visualParseTree": true
        }
    ]
}

Debugging gets stuck with visualParseTree set to true

Hi,

up front let me say thank you very much for this fantastic extension!

I have configured the launch task according to documentation, and it prints correctly to the debug console, visual Parse Tree does not work though:

    "version": "2.0.0",
    "configurations": [        
        {
            "name": "antlr4-flow",
            "type": "antlr-debug",
            "request": "launch",
            //"input": "${workspaceFolder}/${command:AskForTestInput}",
            "input": "test.flow",
            "grammar": "flow.g4",
            "startRule": "file",
            "printParseTree": true,
            "visualParseTree": true
        }
    ]

If I set "visualParseTree" to false the debugger will start, print results to debug console and exit.

If it is set to true the debugger will start, print results to the debug console and then apparently get stuck (the toolbar with pause, restart, stop buttons is displayed but no visual parse tree appears).

Best regards,
Robert.

Change in Lexer Rules is not applied when debuging

When using 2 separate files for Parser and Lexer, after the Lexer rule is changed, the IDE picks up on the change but the debugger doesn't. It displays the diagram with the old Lexer rules. Deleting the generated .antlr folder makes no difference, the only thing that helps is re-starting VS Code.

VS Code 1.26.1

> java -version
java version "10.0.2" 2018-07-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)

antlr-4.7.1-complete

Windows 8.1

Error while launching debug session: start rule "undefined" not found

Hi,
I'm getting some troubles when I try to launch a debug session.
Launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "antlr-debug",
            "request": "launch",
            "name": "Run Parser2",
            "input": "Samples/TestAssignment.ls",
            "visualParseTree": true
        },
        {
            "name": "Run Parser",
            "type": "antlr-debug",
            "request": "launch",
            "grammar": "AntlrFanuc.g4",
            //"startRule": "0",
            "startRule": "moduleDeclaration",
            //"input": "${workspaceFolder}/${command:AskForTestInput}",
            "input": "Samples/TestAssignment.ls",
            "stopOnEntry"  : true,

            "printParseTree": true,
            "visualParseTree": true,
            "trace": true
        }
    ]
}

Look's like the grammar is not compiling.
I both cases no start rule is found.
Am I missing something?

Debug adapter process has terminated unexpectedly

Hi! Thanks for nice extension. But I have some issues with it. The most important for me now is not working debugger. It worked earlier, but I edited launch configuration and VS showed me the error: "Debug adapter process has terminated unexpectedly". I returned my launch configuration back, but it didn't help. My current launch configuration is:

        {
            "name": "ANTLR",
            "type": "antlr-debug",
            "request": "launch",
            //"input": "${workspaceFolder}/${command:AskForTestInput}",
            "input": "tests/input.qs",
            "grammar": "QaterParser.g4",
            "startRule": "program",
            "printParseTree": true, // I removed this line when I got the error in first time
            "visualParseTree": true
        },

My workspace config is the following:

    "antlr4.generation": {
        "mode": "internal",
        "outputDir": "generated",
        "language": "Cpp", // I know this is not used when mode is 'internal'
        "listeners": false,
        "visitors": true
    },

Validation errors/warnings not visible to VS Code

VS Code version: 1.21.0
Architecture: x64
Extension version: 1.3.0

I've opened the VB.NET grammar (from here -- link at the bottom of the page). The ANTLR Exception output pane shows errors:

warning(184): d:\Zev\Projects\vbnet-grammer\vb.g4:2274:0: One of the token XMLNameStartCharacter values unreachable. _ is always overlapped by token XMLNameCharacter
warning(184): d:\Zev\Projects\vbnet-grammer\vb.g4:2274:0: One of the token XMLNameStartCharacter values unreachable. : is always overlapped by token XMLNameCharacter
warning(184): d:\Zev\Projects\vbnet-grammer\vb.g4:2496:0: One of the token XMLNamespaceNameCharacter values unreachable. _ is always overlapped by token XMLNameCharacter
warning(184): d:\Zev\Projects\vbnet-grammer\vb.g4:2496:0: One of the token XMLNamespaceNameCharacter values unreachable. _ is always overlapped by token XMLNameStartCharacter
error(119): d:\Zev\Projects\vbnet-grammer\vb.g4::: The following sets of rules are mutually left-recursive [CCExpression, CCOperatorExpression] and [Expression, IsExpression, MemberAccessBase, DictionaryAccessExpression, InvocationExpression, IndexExpression, AdditionOperatorExpression, SubtractionOperatorExpression, MultiplicationOperatorExpression, FPDivisionOperatorExpression, IntegerDivisionOperatorExpression, ModuloOperatorExpression, ExponentOperatorExpression, RelationalOperatorExpression, LikeOperatorExpression, ConcatenationOperatorExpression, ShortCircuitLogicalOperatorExpression, LogicalOperatorExpression, ShiftOperatorExpression, XMLMemberAccessExpression, TypeExpression, MemberAccessExpression, OperatorExpression, ArithmeticOperatorExpression, DivisionOperatorExpression]

However, I don't see any of these errors in the Problems view, or inline in the editor.

Add parse tree settings

I prefer to view the parse tree vertically, but there doesn't seem to be a setting that specifies the default orientation. Consequently I have to manually switch to vertical for every run.

Similarly, it would be useful to specify a default "Tree/Cluster" setting.

Plugin Internal Error on EOF

Hi,

I'm getting the following error

[Internal Error] Unhandled error message (code 50, message: syntax error: mismatched character '<EOF>' expecting '"'

on this grammar


program 
    : (description NL+)? stmts* EOF
    ;

description
    : 'desc' WS+ string NL*
    ;

stmts
    : stmt NL*
    | stmts NL+ stmt NL+
    ;

stmt
    : assignment
    | return
    | expr
    ;

expr
    : number
    | identifier
    | fapply
    | addexpr
    ;

addexpr
    : mulexpr
    | addexpr WS* '+' WS* mulexpr
    | addexpr WS* '-' WS* mulexpr
    ;

mulexpr
    : unary
    | mulexpr WS* '*' WS* unary
    | mulexpr WS* '/' WS* unary
    ;

fapply
    : identifier '(' ( ')' | arglist ')' )
    ;

assignment
    : identifier WS* '=' WS* expr
    ;
return
    : 'return' WS* expr
    ;

arglist
    : expr
    | arglist WS* ',' WS* expr
    ;

unary
    : number
    | identifier
    ;

primary
    : number
    | string
    | identifier
    ;

string
    : '"' [a-zA-Z-_ ()']+ '"'
    ;

number
    : [+-]?([1-9][0-9]+|[0-9])
    ;

identifier
    : [a-zA-Z_][a-zA-Z0-9_]+
    ;

NL  : '\r'? '\n' -> skip
    ;

WS  : [ \t\r\u000C]+ -> skip
    ;

I ported this grammar from an instaparse source grammar file, so it may be broken in a number of ways.
Let me know if you need help/more info.

Regards,
Michelangelo

Not possible to use ${} macros in launch.json

Currently, with input and grammar entries in launch.json you cannot use ${} variables, for example, the following sample:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "antlr4",
      "input": "${workspaceFolder}/${command:AskForTestInput}",
      "type": "antlr-debug",
      "request": "launch",
      "grammar": "Data.g4",
      "startRule": "${command:AskForTestInput}",
      "printParseTree": true,
      "visualParseTree": true
    }
  ]
}

will fail with:

Cannot read test input file:
[some directory]/${workspaceFolder}/${command:AskForTestInput}

The same is for grammar while startRule works perfectly, for example, this launch configuration will work:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "antlr4",
      "input": "test.data",
      "type": "antlr-debug",
      "request": "launch",
      "grammar": "Data.g4",
      "startRule": "${command:AskForTestInput}",
      "printParseTree": true,
      "visualParseTree": true
    }
  ]
}

I tried with ${file} and similar, but it looks like grammar and input are not preprocessing macros.

Tested in version v2.0.4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.