Re: X3 employee example with semantic actions

Larry Evans <[email protected]> Fri, 1 Jun 2018 18:32:48 -0500
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
On 06/01/2018 05:54 PM, Larry Evans wrote:
> On 06/01/2018 05:09 PM, Larry Evans wrote:
>> On 06/01/2018 01:31 PM, Larry Evans wrote:
>> [snip]
>>>  > I'm also experimenting with the _where iterator range attribute of 
>>> Context.
>>>  > But I've a problem with this. Maybe I did something wrong but what 
>>> I get is
>>>  > an iterator range from the end of the match to the end of input 
>>> stream
>>>  > (std::string storage). The program output is my attachment 
>>> result.txt. Is
>>>  > this intended behavior, a bug or did I something wrong?
>>>
>>> It looks like the intended behaviour to me.  The iterator
>>> begin and end are to the **remaining** input.  The attribute
>>> for the just parsed input is accessed with _attr as shown in
>>> the attached modification to the code you posted.
>>>
>> OOPS :(
>> I failed to notice the printout of the attribute after parse
>> did not reflect the input to the parse.
>>
>> I'm now trying to figure out why that's so.
>>
>> I guess that was your main concern.
>> [snip]
> 
> Specifying the rule default attribute, force_attribute=true, changed the 
> output so that it reflected the input for me.  IOW:
> 
>          x3::rule<employee_id, ast::employee, true> const
>         employee = "employee";
> 
> See if that doesn't get you better results.
> 
OOPS.  And also be sure and pass the attribute to the parser:

     client::ast::employee attr_emp;
     bool r = phrase_parse( iter, end, employee, space, attr_emp );

With these changes, output is as in attached.

-regards,
Larry

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general
test.out (text/plain, 339 B)
/////////////////////////////////////////////////////////

		An employee parser for Spirit...

/////////////////////////////////////////////////////////

call 1
attr=(Putin)
,
"Vladimir",
306000
}

call 1
attr=(Vladimir)
,
306000
}

-------------------------
Parsing succeeded
got: [66, Putin, Vladimir, 306000]

-------------------------