1

I'm trying to parse a custom language (not too dissimilar to JSON), and I decided to try using boost expressive, as it looked fun.

However, when an xpressive match fails, it simply fails. Is there any way I can implement some kind of error reporting? Like 'the expression matched up until the 47th character (I can get the line numbers from that).

I can sort of see how one could tailor each sub expression to look for other tokens or matches after looking for the one it wants, and reporting an error in this case, but it seems that would be a very complex way of doing it.

Is there any functionality in expressive (or can anyone suggest an approach) that would allow me to do this?

Thanks.

icktoofay
  • 126,289
  • 21
  • 250
  • 231
DaedalusFall
  • 8,335
  • 6
  • 30
  • 43

1 Answers1

0

I suggest using ANTLR instead. It is a good compromise between cool, bleeding-edge stuff like Boost Spirit/Qi and stalwart tools like lex and yacc. It can do some amount of smarter error reporting like you want without too much effort.

Note that there are currently ANTLR versions 2 and 3 are both in common usage; 2 includes C++ code generation whereas 3 does not, so you might want to stick with the "older" version for now (porting should be fairly straightforward if v3 eventually has a C++ target).

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • Thanks. I've used flex/bison in the past, which was good in its way, and I'm aware of the other parser generators like ANTLR (I've even written one in python). For that matter the simplicity of the language means its no trouble to write a recursive descent parser by hand and have that report errors (which I may do). But XPressive is in C++ with no extra build step (which can be a pain when building on multiple Operating systems) and I'd like to use it if possible. I tried boost::spirit but the the extra complexity and length/illegibility of compiler errors put me off. – DaedalusFall Feb 14 '11 at 13:12
  • Boost itself is a pain for some users on some systems. For example people with older versions of compilers (e.g. OS-vendor provided ones) may not be able to build your code. I would argue that while your build script may need a couple special lines for ANTLR, using ANTLR instead of Xpressive may end up making your overall project more portable, not less. Certainly what you say about Spirit agrees with my experience--that thing at first appears to be production-ready, but I'm not so sure. – John Zwinck Feb 15 '11 at 14:12
  • All fair points! My worry was not so much portability, more laziness! When I say 'a pain building on multiple operating systems', I of course mean windows. It always seems five times the work/testing to add something into a windows build chain. Also I will probably end up depending on boost for one or two other things. As I suspected I've ended up hand crafting one (which probably took less time than reading the ANTLR manual, or re-reading the flex/bison manuals for that matter). Just wanted to know if i could do it with XPressive, even if its not the *best* way to do it. – DaedalusFall Feb 18 '11 at 14:39