Skip to content

Add subscript operator to Expression to access sub-expressions by name

Latest
Compare
Choose a tag to compare
@TheLartians TheLartians released this 05 Feb 15:35
99ea226

Now allows querying expressions by rule names. When passing a string to the subscript operator, the first subexpression parsed with the matching rule name is returned. Thanks to @jteuber for the idea and PR #60!

Example

ParserGenerator<bool> program;
program["Word"] << "[a-z]+";
program["Yell"] << "[A-Z]+";
program["Start"] << "Word | Yell" >> [](auto e){ return bool(e["Yell"]); }
REQUIRE(!program.run("hello"));
REQUIRE(program.run("HELLO"));