简体   繁体   中英

Different Newline Recognition in JavaScript ANTLR4 Target

This is a portion of my island grammar:

listing
    : LISTING (newlines listingPath)? (newlines label)? newlines caption
    ;

newlines
    : NL+
    ;

And for example some input text:

~~~~~

Listing 1 content...

~~~~~
{#lst:listing-1#}
##### Explanation for listing 1. #####

This gets recognized very well. Both in the IntelliJ prototype project (I think Java runs in the background) as well as in my application with a JavaScript target.

When I replace the "newlines" rule within the "listing" rule with "NL+" or "NL" I receive a parsing error that the first \\r\\n after the closing listing tag "~~~~~" is a bad token. The newline doesn't get recognized.

Both versions working well with IntelliJ in the prototype project. I tested the grammars with the ANTLR preview feature.

Am I missing something or is this a possible JavaScript target bug in ANTLR4?

It was just a small mistake within my parser grammar file.

Of course no bug within the ANTLR4 code generation. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM