X3 iterators into the input for a matching rule

Maarten Verhage <[email protected]> Sun, 3 Jun 2018 14:23:21 +0000
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <AM5P192MB0131E43825EA63D2466755C1BA600@AM5P192MB0131.EURP192.PROD.OUTLOOK.COM>
Dear people,

My application goal is as follows:

1) parse an ascii file,
2) modify a few things,
3) write it back.

However the file has portions that I just don’t need to modify. For these 
portions I just want Spirit to provide me two iterators into the original 
input so I can std::copy that portion to a memory area that will become my 
new file. First I was using Spirit 2. Now Spirit X3 because the Context 
object has the _where member function that provide an iterator range into 
the original input. However I was disappointed to learn that it wasn’t the 
range of a rule match but rather from the end of the match to the end of the 
input. So I’m in need for a facility in Spirit that provides me also the 
start of a rule match. From my perspective the use of semantic actions is 
preferred so it will be visible how the parsed results are assigned to the 
data structure. You know for the stuff I do want to modify.

Ok, for an iterator into the input that indicate the start of a rule match 
it seems that the documentation page “Annotations - Decorating the ASTs” 
along with the example code “annotation.cpp” will have this somewhere. But I’m 
lost in the annotation example code. What would be much less frustrating for 
me is when a single topic is introduced at the time and the rest is the same 
as a previous example. Maybe I don’t need annotations to just get an 
iterator range of the match.

If it would be allowed to call something like:

struct position_cache_tag
X3::get<position_cache_tag>( context ).get();

In a semantic action and then some code to get my two iterators of the 
match. That would be so valueable.

If the above piece code would work. I would hope the Spirit experts are 
willing to make example code along with a tutorial documentation page that 
shows all the ways information can be obtained about the parsed result 
through the Context object. Just like actions.cpp did for all the ways 
semantic actions can be provided. I strongly believe this will help people 
to use Spirit the intended way. You know a topic like annotating or 
decorating does not translate to a direct goal for someone who is writing a 
parser with Spirit. While a paragraph title like “getting information about 
a parsed result” would do much better, I believe.

Still in the meantime if someone can show me a way of getting both the start 
and end iterator of a rule match into the input in a semantic action. That 
would be very useful to make progress.

Best regards,
Maarten Verhage 


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