Closed stephenwhittle closed 4 years ago
@stephenwhittle, thanks for the feedback. I am probably not smart enough to understand what you are trying to do. :)
But at least, I implemented the AST support for combinators. You can now declare definitions with AST action handler with AST_DEFINITIONS
macro.
Hope it helps!
This is very helpful, thank you!
I'm evaluating the best way forward with implementing a parser for a family of file formats that has a large number of ordered optional variables that vary according to specific file subtype, so I intend to make heavy use of parameterized rules to specify which variables are acceptable and their ordering at a file level.
As an alternative to abusing your (now fixed, thank you!) macro implementation to specify the file-level schema, I have the following simple DSL that essentially allows me to emulate macros using the parser combinator system:
Omitting the shared_ptrs for brevity,
FlightPathMarkerGauge
expands topeg::Sequence(peg::LiteralString("+Flight Path Marker"), peg::Character(':'), Value, peg::opt(peg::Sequence(peg::LiteralString("$Color"), peg::Character(':'), Value)), ......)
I know I'm going to need to alter ObjectHeader and OptionalVariable etc to use peg::ref to have 1:1 equivalency to macros, but I'd like to verify that the structure is being expressed correctly and matches my input data before I perform that refactoring.
As a result, I'd like to run this against some test input and view the AST of the result, but the enable_ast method is only available on peg::parser, not peg::Definition. Is there a way to do this, or a way to convert a Definition to a grammar string that can be fed to
peg::parser::parse
?