SQLite Forum

lemon - optional namespace support
I wanted to follow up on a [previous posting](http://sqlite.1065341.n5.nabble.com/lemon-namespace-support-td110455.html) with some patches [lemon.c.patch](https://develop.openfoam.com/Development/openfoam/blob/develop/wmake/src/lemon.c.patch) and [lempar.c.patch](https://develop.openfoam.com/Development/openfoam/blob/develop/wmake/etc/lempar.c.patch) for helping integrate lemon parsers into larger C++ code bases.
The patches are not overly large or complicated, but most certainly help with avoiding symbol clashes and promote good code encapsulation. We've successfully used lemon in [OpenFOAM](https://www.openfoam.com/) for handling [parsed expressions](https://www.openfoam.com/releases/openfoam-v1912/pre-processing.php#pre-processing-expressions-syntax), to manipulate much larger computational fields.
Code snippets show part of [embedding lemon](https://develop.openfoam.com/Development/openfoam/blob/develop/src/finiteVolume/expressions/volume/volumeExprLemonParser.lyy-m4) with a variety of [m4-macros](https://develop.openfoam.com/Development/openfoam/tree/develop/src/OpenFOAM/include/m4/lemon) to arguably improve maintenance.

As stated in the first post:

> I hope that the changes are useful enough for broader interest and/or
> sufficiently encapsulated that they could be incorporated into the sources.

If the proposed patches need reworking, I would be happy to comply.

Below is some more of the original posting, with the hope that it will garner some interest this time.


/mark (*contact information visible on the corresponding commits*)

> I've fairly recently been using lemon for building several parsers in
> C++ and found what I believe to be a *minimalist* means of avoiding
> symbol clashes without adding bloat, or affecting C code generation.

New `-e` command line option to define the code extension. By default
this is `c`, but can be used to define something like `-ecxx` etc to trigger the correct make rules for a C++ compiler. 

New (*optional*) `%namespace` directive. This can be used to embed the
`Parse*` routines into a C++ namespace. If the `%namespace` is not
defined, there is no change in behaviour.
The namespace can be anonymous or contain multiple nested namespaces.
For example,
    %namespace {}
    %namespace {ns1::ns2::ns3}
This makes it easy to generate lemon parsers for C++ without any
potential symbol clashes, and it imposes no C++ interface on the user.
It does not fundamentally change how lemon works.