Re: X3 employee example with semantic actions
Larry Evans <[email protected]> Thu, 31 May 2018 13:37:36 -0500
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
On 05/30/2018 12:00 PM, Larry Evans wrote:
> On 05/30/2018 10:16 AM, Maarten Verhage wrote:
[snip]
>> So, I thought how nice it would have been to get a pair
>> of iterators into the “parsed” result once Spirit
>> determined the rule to match. But I couldn’t found this
>> facility in Spirit 2. But Spirit X3 has the Context
>> object to be able to call the _where member function to
>> get this right? And then just copy it to a memory area
>> that will become my new file. For the file contents I do
>> not want to modify this would be a pretty efficient way
>> right?
>> The obstacle I’m facing right now (and hope a list member
>> here would be able to help me on) is this: As I do want
>> manually store stuff using semantic actions how do I need
>> to modify the Spirit X3 employee example code to 1)
>> Prevent spirit to automatically store it. And 2) How do I
>> need to provide the empty employee object to this
>> client::parser namespace area as this is not a class
>> anymore.
Maarten, I apologize for not reading the above more
carefully before posting my reply below. My mind was
focused on your previous post:
https://sourceforge.net/p/spirit/mailman/message/36329960/
where you say:
It was pretty printing I was aiming for. According to
Seth’s suggestion I plan to do it without karma. Once I’ve
a parsed data structure I can manually print it out to a
ostream. And indent based on what I encounter in this
data structure.
However, now that I've more carefully read your above post,
it appears, based on what you say here:
I need to modify the Spirit X3 employee example code to 1)
Prevent spirit to automatically store it. And 2) How do I need to provide
the empty employee object to this client::parser namespace area as
this is not a class anymore.
That:
1) You **don't** want x3 parser to store into any
attribute; hence, you'd pass unused as opposed to emp
as the attribute argument to:
https://github.com/boostorg/spirit/blob/develop/example/x3/employee.cpp#L111
2) Instead of relying on x3 to construct the attributes,
you would define semantic actions which would, **as the
parsing progresses**, write out to some ostream, the
result of the parse. IOW, there would be some
**global** declaration:
std::fostream* out_ptr=0;
which might be initialized in main with something like:
int main
(
.
.
.
std::ofstream
stream_out("some_output_file_name", std::ios_base::out);
std::fostream out_str=&stream_out;
.
.
.
return 0;
}
and there would be semantic actions between out_ptr and
main which write to out_ptr and are used in the x3
grammar somehow.
Is that about what you were aiming for?
>
> Maarten, why couldn't you define:
>
> std::ostream&
> operator<<
> ( std::ostream& sout
> , ast_from_parse_t const& ast
> )
> {
> //then print the ast to sout here using whatever
> //method.
> }
>
> That way you wouldn't have to wrestle with semantic actions at all,
> unless I'm missing something (happens occasionally).
>
> -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
------------------------------------------------------------------------------
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