2

In its answer to this question, hkaiser said he would write an example of a token type which carries code position information. I really cannot find anything about this.

Can anyone point me to such an example ?

ZeeByeZon
  • 112
  • 8

1 Answers1

3

He was probably referring to position_token, which did in fact get released, although there's little documentation. This SO question has good coverage of its usage.

Community
  • 1
  • 1
Jeff Trull
  • 1,236
  • 11
  • 16
  • OK thanks. Do you know if there is an example or a tutorial for how to use it somewhere ? – ZeeByeZon Aug 19 '15 at 07:01
  • Hartmut gives further details in his answer here: http://stackoverflow.com/questions/5964228/boost-spirit-lex-qi-error-reporting – Jeff Trull Aug 19 '15 at 07:16
  • 2
    Within the Boost sources you can find it at libs/spirit/example/qi/compiler_tutorial/conjure3/lexer.hpp – Jeff Trull Aug 19 '15 at 07:17
  • This source code is quite complex! I cannot figure out what information is stored into the tokens, and how you read it... – ZeeByeZon Aug 19 '15 at 15:28
  • 1
    `position_token` has methods `begin()` and `end()` which return iterators to the start and end of the underlying input that they matched. You could use this, for example, to determine the byte offset, within a file, of the matched input. – Jeff Trull Aug 19 '15 at 18:00
  • I don't see any sign that it tracks line and column information, though. – Jeff Trull Aug 19 '15 at 18:03
  • 1
    @JeffTrull for that I think you'll need to use the [`line_pos_iterator`](http://www.boost.org/libs/spirit/doc/html/spirit/support/line_pos_iterator.html). – llonesmiz Aug 27 '15 at 12:16
  • @cv_and_he that sounds great. Care to make it an answer? I think it's probably what OP is looking for. – Jeff Trull Aug 27 '15 at 20:58
  • @cv_and_he hm actually I think he needed a lex-compatible iterator. `line_pos_iterator` seems to be for character-based input – Jeff Trull Aug 27 '15 at 21:02
  • @JeffTrull It is. I think what the OP needs is a combination of both `position_token` and `line_pos_iterator`. – llonesmiz Aug 27 '15 at 21:10