So, I play with lpeg to replace the boost grammar, I have to say boost :: spirit is much more elegant and natural than lpeg. However, this is a bitch to work due to the limitations of the current C ++ compilation and problems with TMP in C ++. The type mechanism in this case is your enemy, not your friend. Lpeg, on the other hand, while ugly and basic results lead to greater performance.
In any case, I'm distracted, part of my lpeg grammar looks like this:
function get_namespace_parser() local P, R, S, C, V = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.V namespace_parser = lpeg.P{ "NAMESPACE"; NAMESPACE = V("WS") * P("namespace") * V("SPACE_WS") * V("NAMESPACE_IDENTIFIER") * V("WS") * V("NAMESPACE_BODY") * V("WS"), NAMESPACE_IDENTIFIER = V("IDENTIFIER") / print_string , NAMESPACE_BODY = "{" * V("WS") * V("ENTRIES")^0 * V("WS") * "}", WS = S(" \t\n")^0, SPACE_WS = P(" ") * V("WS") } return namespace_parser end
This grammar (although not complete) corresponds to the following namespace foo {} . I would like to get the following semantics (which are common use cases when using boost spirit).
- Create a local variable for the namespace rule.
- Add the namespace data structure to this local variable if
namespace IDENTIFIER { been mapped. - Pass the newly created namespace data structure to
NAMESPACE_BODY for further assembly AST ... so on and so forth.
I am sure that this use case is possible. No example shows. I do not know the language or library to understand how to do this. Can someone show the syntax for it.
edit: After several days of trying to dance with lpeg and my legs will beat me, I decided to get back to the spirit: D itβs clear that lpeg is designed to be woven with lua functions and that such weaving is very free form (while the spirit has a clear very well documented semantics). I just don't have the right lua mental model.
source share