Strumenta / antlr-kotlin

Support for Kotlin as a target for ANTLR 4
Apache License 2.0
221 stars 47 forks source link

Mismatched input is within the set of accepted characters? #180

Closed acrusage-iaik closed 4 months ago

acrusage-iaik commented 4 months ago

Hello,

I am running version 1.0.0-RC2.

I get the following error: line 1:2 mismatched input '*' expecting {'*', NAME_FIRST} with the following input: $.* and the following (truncated)grammar:

grammar JSONPath;

jsonpathQuery
    : rootIdentifier segments
    ;

segments
    : (WHITESPACE? segment)*
    ;

segment
    : childSegment
    | descendantSegment
    ;

childSegment
    : bracketedSelection
    | '.' (wildcardSelector | memberNameShorthand)
    ;

BLANK
    : ' '
    | '\t'
    | '\n'
    | '\r'
    ;

WHITESPACE
    : BLANK+
    ; // optional blank space

wildcardSelector: WILDCARD_SELECTOR;
WILDCARD_SELECTOR
    : '*'
    ;

This doesn't seem right though, the mismatched input is actually within the set of expected characters?

I run the code something like as follows:

        val jsonPath: String = "$.*"
        val lexer = JSONPathLexer(CharStreams.fromString(jsonPath))
        val commonTokenStream = CommonTokenStream(lexer)
        val parser = JSONPathParser(commonTokenStream)

        return object : JSONPathBaseVisitor<Unit>() {}.visit(parser.jsonpathQuery())
lppedd commented 4 months ago

Haven't looked at the grammar in detail, but the first thing to do is verify if this issue has been introduced in this Kotlin port, or if it's in the Java version too.

If the official ANTLR Java version exhibit the same issue, this is most likely a grammar problem.

acrusage-iaik commented 4 months ago

Bug originated from incorrect grammar

lppedd commented 4 months ago

Thanks for the update!