diff --git a/README.md b/README.md index d49d14a..f177f4e 100644 --- a/README.md +++ b/README.md @@ -241,10 +241,10 @@ The following are available operators: | cap | Capture character | | usr | User defiend parser | -Hybrid Parser -------------- +Adjust definitions +------------------ -It's even possible to mix parser grammar with parser operaters. +It's possible to add and override definitions with parser operaters. ```c++ auto syntax = R"( diff --git a/example/calc.cc b/example/calc.cc index 4f81de5..3166274 100644 --- a/example/calc.cc +++ b/example/calc.cc @@ -15,12 +15,13 @@ using namespace std; // // PEG syntax: // -// EXPRESSION <- TERM (TERM_OPERATOR TERM)* +// EXPRESSION <- _ TERM (TERM_OPERATOR TERM)* // TERM <- FACTOR (FACTOR_OPERATOR FACTOR)* -// FACTOR <- NUMBER / '(' EXPRESSION ')' -// TERM_OPERATOR <- [-+] -// FACTOR_OPERATOR <- [/*] -// NUMBER <- [0-9]+ +// FACTOR <- NUMBER / '(' _ EXPRESSION ')' _ +// TERM_OPERATOR <- < [-+] > _ +// FACTOR_OPERATOR <- < [/*] > _ +// NUMBER <- < [0-9]+ > _ +// ~_ <- [ \t\r\n]* // int main(int argc, const char** argv) { @@ -47,12 +48,13 @@ int main(int argc, const char** argv) }; const char* syntax = - " EXPRESSION <- TERM (TERM_OPERATOR TERM)* " + " EXPRESSION <- _ TERM (TERM_OPERATOR TERM)* " " TERM <- FACTOR (FACTOR_OPERATOR FACTOR)* " - " FACTOR <- NUMBER / '(' EXPRESSION ')' " - " TERM_OPERATOR <- [-+] " - " FACTOR_OPERATOR <- [/*] " - " NUMBER <- [0-9]+ " + " FACTOR <- NUMBER / '(' _ EXPRESSION ')' _ " + " TERM_OPERATOR <- < [-+] > _ " + " FACTOR_OPERATOR <- < [/*] > _ " + " NUMBER <- < [0-9]+ > _ " + " ~_ <- [ \t\r\n]* " ; peg parser(syntax);