ianh / owl

A parser generator for visibly pushdown languages.
MIT License
741 stars 22 forks source link

Can't include parser.h in C++ project due to "class" keyword #27

Closed falkoschindler closed 2 years ago

falkoschindler commented 2 years ago

I'm trying to use owl in a C++ project. Therefore I need to include parser.h (at least without implementation) in the main.cpp, where I call e.g. owl_tree_create_from_string(). The implementation is included in an almost empty file parser.c. The C++ compiler, however, has trouble parsing parser.h while compiling main.cpp due to the keyword class, which occurs at unexpected places.

I fixed the generated parser.h with the following sed command, appending an underscore after every "class":

sed -i '' 's/class/class_/g' src/parser.h

This is a bit more than necessary, because "class" also occurs as part of longer words. But this fix works.

It might be reasonable to slightly change the naming in 1-parse.h to make it C++ compatible. After all owl works nicely in C as well as C++.

ianh commented 2 years ago

Does your grammar include anything called class in it? Owl will give errors for C keywords used in grammars, but not C++ keywords. I'm reluctant to check for C++ keywords by default, since it would unnecessarily restrict people using only C.

falkoschindler commented 2 years ago

Oh, you're right! I thought the word "class" comes from owl, but it's from my grammar. Then I will fix it on my side. Feel free to close this issue. Thanks!