Re: Need to improve syntax error diagnostic message for Spirit grammar
Seth Heeren <[email protected]> Fri, 18 Sep 2020 17:22:55 +0200
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
On vr, 18. sep 12:37, Mccall, Kurt E. (MSFC-EV41) via Spirit-general wrote:
> For a particular syntax error in my input string, Spirit is pointing to a location in the string well
> would point, at the location of the quoted string that is missing the trailing double quote.
It was quite some work to piece together the jig-saw puzzle from your
code. Specifically, you don't show `raise_parser_diagnostic`,
which more or less defines what the output looks like.
So, I arrived at the following simplified take (replacing
`diagnostics` with `map<string_view, string_view>`, using DEBUG macros
to auto-name rules and use those e.g.).
Live On Coliru: http://coliru.stacked-crooked.com/a/beb4cff532a4e15e prints
error: L3:26 quoted C-expression string
liftoff2 = "time > 0.35;
^-- here
error: L2:39 semicolon
liftoff = "time > 0.25",
^-- here
I assume that is _already_ what you wanted. However, if e.g. you meant
to point at the place where the closing quote is considered missing,
you can make that an expectation point, changing:
quoted_str = lexeme['"' >> *~char_('"') >> '"'];
To
quoted_str = lexeme[dquote > *~char_('"') > dquote];
With some more tweaks surrounding lexeme rules and removing the
separation of `d1`,`d2`,`d3`), Live On Coliru
http://coliru.stacked-crooked.com/a/91c2802eeb2a6cd7 prints
error: L4:1 missing closing double quote
^-- here
error: L3:26 quoted C-expression string
liftoff2 = "time > 0.35;
^-- here
error: L2:39 semicolon
liftoff = "time > 0.25",
^-- here