Note that there are some explanatory texts on larger screens.

plurals
  1. POBoost Spirit - Parser Capturing Unwanted Text
    primarykey
    data
    text
    <p>I have a simple struct </p> <pre><code>// in namespace client struct UnaryExpression { std::string key; SomeEnums::CompareType op; }; </code></pre> <p><code>SomeEnums::CompareType</code> is an enum where I define a symbol table as such:</p> <pre><code>struct UnaryOps : bsq::symbols&lt;char, SomeEnums::CompareType&gt; { UnaryOps() : bsq::symbols&lt;char, SomeEnums::CompareType&gt;(std::string("UnaryOps")) { add("exists", SomeEnums::Exists) ("nexists", SomeEnums::NotExists); } }; </code></pre> <p>I have two different ways I want to parse the struct, which I asked about in <a href="https://stackoverflow.com/questions/14514983/boost-spitirt-single-struct-multiple-rules">another thread</a> and got to work (mostly).</p> <p>My grammar looks as follows:</p> <pre><code>template&lt;typename Iterator&gt; struct test_parser : bsq::grammar&lt;Iterator, client::UnaryExpression(), bsq::ascii::space_type&gt; { test_parser() : test_parser::base_type(unaryExp, std::string("Test")) { using bsq::no_case; key %= bsq::lexeme[bsq::alnum &gt;&gt; +(bsq::alnum | bsq::char_('.'))]; unaryExp %= unaryE | unaryF; unaryE %= key &gt;&gt; no_case[unaryOps]; unaryF %= no_case[unaryOps] &gt;&gt; '(' &gt;&gt; key &gt;&gt; ')'; }; UnaryOps unaryOps; bsq::rule&lt;Iterator, std::string(), bsq::ascii::space_type&gt; key; bsq::rule&lt;Iterator, client::UnaryExpression(), bsq::ascii::space_type&gt; unaryExp; bsq::rule&lt;Iterator, client::UnaryExpression(), bsq::ascii::space_type&gt; unaryE; bsq::rule&lt;Iterator, client::UnaryFunction(), bsq::ascii::space_type&gt; unaryF; }; </code></pre> <p>And I'm parsing the code using the following logic:</p> <pre><code>bool r = phrase_parse(iter, end, parser, bsq::ascii::space, exp); if (r &amp;&amp; iter == end) { std::cout &lt;&lt; "-------------------------\n"; std::cout &lt;&lt; "Parsing succeeded\n"; std::cout &lt;&lt; "key: " &lt;&lt; exp.key &lt;&lt; "\n"; std::cout &lt;&lt; "op : " &lt;&lt; exp.op &lt;&lt; "\n"; std::cout &lt;&lt; "-------------------------\n"; } </code></pre> <p>This all works fine if I do the input like <code>foo exists</code> and exp.key equals "foo" and exp.op equals the corresponding enum value (in this case 0). Something like <code>foo1 nexists</code> also works.</p> <p>However, that second rule doesn't work like I expect. If I give it input of <code>nexists(foo)</code> then I get the following output:</p> <pre><code>------------------------- Parsing succeeded key: nexistsfoo op : 1 ------------------------- </code></pre> <p>It seems that the enum value is getting set appropriately but I can't figure out why the "nexsts" is getting prepended to the key string. Can someone please tell me how I can fix my rule so that the key would equal just 'foo' with the second rule? </p> <p>I have posted a copy of the stripped down code that illustrates my problem here: <a href="http://pastebin.com/402M9iTS" rel="nofollow noreferrer">http://pastebin.com/402M9iTS</a> </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload