Tags

, ,

This example uses boost spirit to parse a simple colon-delimited grammar.

The grammar we want to recognize is:

identifier := [a-z]+
 separator := ':'
 path := (identifier separator path) | identifier

From the boost spirit perspective this example shows a few things that I found difficult to figure out when building my first parser.

  1. How to flag an incomplete token at the end of input as an error. (use of boost::spirit::eoi)
  2. How to bind an action on an instance of an object that is taken as input to the parser.
  3. Use of std::wstring.

Here’s the code for the example. I also posted a subset of it as an answer to the  StackOverflow question I asked on the 12th of October, 2012.

Advertisements