ianh / owl

A parser generator for visibly pushdown languages.
MIT License
746 stars 21 forks source link

Provide a way to include two different parsers without symbol conflicts #19

Closed ianh closed 4 years ago

ianh commented 4 years ago

Owl's generated parsers declare function names with external linkage. This is a problem if you want to include two different parsers in the same program.

ianh commented 4 years ago

One idea is to generate unique names for all the external-linkage functions, then add static inline wrappers around each of them.

struct owl_ref owl_next_797fb01a(struct owl_ref);
static inline owl_ref owl_next(struct owl_ref r) { return owl_next_797fb01a(r); }

This way the function names are only visible within the translation unit where that header file is included.

breeno commented 4 years ago

sounds like a reasonable approach.

We also noticed for our use case that some of our parsed_XXX items shared names for common enough tokens. Perhaps an "API Prefix" (e.g. my_foo_dsl_parsed_XXX) supplied when the parser is generated?

ianh commented 4 years ago

As of e359f9c, you can now specify -p/--prefix on the command line to replace both owl_ and parsed_ with your custom prefix. Let me know if this works for you—I figured it would be better for readability to replace the prefixes rather than tacking more on.

breeno commented 4 years ago

Verified this works for us - thanks!