开发者

How to associate Boost Spirit parsed entities with their location in input stream?

Boost Spirit library permits to Track the Input Position While Pa开发者_运维问答rsing. This mechanism allows informing about location of a parser error during parsing.

I'd like to preserve original location for all parsed entities together with them for future use. (For example, AST semantic verification.) What would be the recommended way to do so?

Thank you!


If you need the position of all entities you might be better off using a lexer, which produces tokens optionally carrying positional information about the matched input (see here). If a lexer is not an option you might utilize the new on_success() construct (available in SVN or starting with Boost V1.47), which works similarily to on_error(), except that your supplied handler will be invoked on a successful parse of the rule it is associated with. The the conjure example to see how it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜