Eto
Eto

Reputation: 37

JAVA CC Pattern Throws an Error on an Expected Token

I have defined the following pattern in JAVACC:

| < CONFIGURATION_PATTERN: "(" ("\n")* (" ")* ((<LETTER>)+ " = " (<LETTER> | <DIGIT>)+ ("\n") (" ")*)+  (" ") ")" >
| < CONFIGURATION_SUB_PATTERN: "(" ("\n")* (" ")* ((<LETTER>)+ " = " (<LETTER> | <DIGIT> | <BOOLEAN>)+ ("\n") (" ")*)+  (" ") ")" >

Then, I have a file which gets parsed as expected but when it gets to the following lines it throws me an error:

*The lines

CONFIGURATION (
    INSERTVALUE = 200
    PROPERTIES ( 
        MOVETABLE = false,
        DOWRITE = true
    )
)

throwing the error:

Parse error: Encountered " "(" "( "" at line 25, column 29.
Was expecting one of:
    "SOMETOKEN" ...
    "SOMETOKEN2" ...
    "SOMETOKEN3" ...
    <SOME_PATTERN> ...
    <SOME_PATTERN2> ...

I have another file where the PROPERTIES part is not part of the file and the CONFIGURATION_PATTERN and CONFIGURATION_SUB_PATTERN are applied without errors.

I tried to debug this but I do not get behind the error because I do not understand why it complains about the first "(" after CONFIGURATION.

I have tried removing the CONFIGURATION part and then the whole file gets parsed as expected. I tried to set the "(" and ")" explicitly but then it complains that it expected the pattern which is correct.

I chatgpted the problem and ChatGPT tells me to apply a recursive pattern which I tried with the CONFIGURATION_SUB_PATTERN, so I put (<CONFIGURATION_PATTERN> | <CONFIGURATION_SUB_PATTERN>)*.

Before, I tried to set the pattern like below which looks ugly to me but should be correct:

"(" ("\n")* (" ")* ((<LETTER>)+ ("(" | " = ") ((<LETTER> | <DIGIT>)+ | ((<LETTER>)+ "=" (<BOOLEAN>)? (",")*)+ (")"))* ("\n") (" ")*)+ (" ") ")"

Thanks and appreciate your help!

Upvotes: 0

Views: 471

Answers (0)

Related Questions