I know there has been an old question How can a PetitParser parse rule signal an error?. Lukas Renggli has written it is:
in general this is not good style (mixes syntactic and semantic
analysis)
My question is how to do it with more complex example correctly?
Here is my example:
I want to parse the following term:
(0.53,00)
^
I want to tell the user the error is where the ^
points. Something like “please remove the extra comma from your input”
The grammar is:
^ openParenthesis, number, closeParenthesis
The tokens:
openParenthesis
^ $( asPParser
number
^ wholeNumber plus, dot optional, wholeNumber optional
closeParenthesis
^ $) asPParser
wholeNumber
^#digit asPParser plus trim
How would you write a code to detect such (additional comma) kind of error?