2

I'm writing a parser for a little language similar to GLSL. I was just working on parsing "in" and "out" variables, and noticed that my rule broke parsing of "int x;" presumably because "int" begins with "in". "float x;" parsed fine. The relevant rule is:

decl = -(lexeme["in"] | lexeme["out"]) >> type >> var >> (('(' >> arglist >> ')' >> block)
                                                          | ('=' >> expr >> ';')
                                                          | ';');

So do I need to tokenize first using lex? Or can I get away with just using Qi somehow?

Taylor
  • 5,871
  • 2
  • 30
  • 64

1 Answers1

1

You don't.

You can manually assert keyword boundaries:

 in_kw = "in" >> !char_("A-Za-z_");

But that's tedious. You can also use distinct[] from the Spirit Repository: http://www.boost.org/doc/libs/1_55_0/libs/spirit/repository/example/qi/distinct.cpp

sehe
  • 374,641
  • 47
  • 450
  • 633
  • I'm having trouble getting that working (does't parse "in float x;"). Could it be that I can no longer use ascii::space as the skip parser? – Taylor Aug 07 '14 at 01:13
  • @Taylor You didn't show enough code for me to assume skippers. Of course, you will need to lexemes as necessary. See also [this backgrounder](http://stackoverflow.com/questions/17072987/boost-spirit-skipper-issues/17073965#17073965) – sehe Aug 07 '14 at 12:24