Re: Need to improve syntax error diagnostic message for Spirit grammar

"Mccall, Kurt E. \(MSFC-EV41\) via Spirit-general" <[email protected]> Mon, 21 Sep 2020 21:28:09 +0000
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <SA9PR09MB580809F25900099C6FEB34D9C63A0@SA9PR09MB5808.namprd09.prod.outlook.com>
Sorry that my post was unclear, and thanks for putting in the work to decipher it.   You've given me a bunch of ways to improve my code.

Kurt

-----Original Message-----
From: Seth Heeren <[email protected]> 
Sent: Friday, September 18, 2020 10:23 AM
To: [email protected]
Subject: [EXTERNAL] Re: [Spirit-general] Need to improve syntax error diagnostic message for Spirit grammar

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: https://urldefense.proofpoint.com/v2/url?u=http-3A__coliru.stacked-2Dcrooked.com_a_beb4cff532a4e15e&d=DwICAg&c=ApwzowJNAKKw3xye91w7BE1XMRKi2LN9kiMk5Csz9Zk&r=6cP1IfXu3IZOHSDh_vBqciYiIh4uuVgs1MSi5K7l5fQ&m=JQv3mClgVZPLRAmss85i3oF_jcnuGGJhiPqwdIMlHkk&s=kmGIvoDHzLK7W75mtMK6rQlgbbMpZMt-gzpN4rru_YE&e=  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 https://urldefense.proofpoint.com/v2/url?u=http-3A__coliru.stacked-2Dcrooked.com_a_91c2802eeb2a6cd7&d=DwICAg&c=ApwzowJNAKKw3xye91w7BE1XMRKi2LN9kiMk5Csz9Zk&r=6cP1IfXu3IZOHSDh_vBqciYiIh4uuVgs1MSi5K7l5fQ&m=JQv3mClgVZPLRAmss85i3oF_jcnuGGJhiPqwdIMlHkk&s=B4gnsHt6e8PqsIp22x-ULzyyyLD-ltvGoaNUlEaAA0s&e=  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




_______________________________________________
Spirit-general mailing list
[email protected]
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.sourceforge.net_lists_listinfo_spirit-2Dgeneral&d=DwICAg&c=ApwzowJNAKKw3xye91w7BE1XMRKi2LN9kiMk5Csz9Zk&r=6cP1IfXu3IZOHSDh_vBqciYiIh4uuVgs1MSi5K7l5fQ&m=JQv3mClgVZPLRAmss85i3oF_jcnuGGJhiPqwdIMlHkk&s=_bKJ982Q1OiWqSD7sijWnuzIZN0HoBj2AinndrUuMLw&e=