Modified documentation and the calc sample.

This commit is contained in:
yhirose 2015-02-19 22:51:04 -05:00
parent 681c754302
commit cf574074c4
2 changed files with 15 additions and 13 deletions

View File

@ -241,10 +241,10 @@ The following are available operators:
| cap | Capture character | | cap | Capture character |
| usr | User defiend parser | | 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++ ```c++
auto syntax = R"( auto syntax = R"(

View File

@ -15,12 +15,13 @@ using namespace std;
// //
// PEG syntax: // PEG syntax:
// //
// EXPRESSION <- TERM (TERM_OPERATOR TERM)* // EXPRESSION <- _ TERM (TERM_OPERATOR TERM)*
// TERM <- FACTOR (FACTOR_OPERATOR FACTOR)* // TERM <- FACTOR (FACTOR_OPERATOR FACTOR)*
// FACTOR <- NUMBER / '(' EXPRESSION ')' // FACTOR <- NUMBER / '(' _ EXPRESSION ')' _
// TERM_OPERATOR <- [-+] // TERM_OPERATOR <- < [-+] > _
// FACTOR_OPERATOR <- [/*] // FACTOR_OPERATOR <- < [/*] > _
// NUMBER <- [0-9]+ // NUMBER <- < [0-9]+ > _
// ~_ <- [ \t\r\n]*
// //
int main(int argc, const char** argv) int main(int argc, const char** argv)
{ {
@ -47,12 +48,13 @@ int main(int argc, const char** argv)
}; };
const char* syntax = const char* syntax =
" EXPRESSION <- TERM (TERM_OPERATOR TERM)* " " EXPRESSION <- _ TERM (TERM_OPERATOR TERM)* "
" TERM <- FACTOR (FACTOR_OPERATOR FACTOR)* " " TERM <- FACTOR (FACTOR_OPERATOR FACTOR)* "
" FACTOR <- NUMBER / '(' EXPRESSION ')' " " FACTOR <- NUMBER / '(' _ EXPRESSION ')' _ "
" TERM_OPERATOR <- [-+] " " TERM_OPERATOR <- < [-+] > _ "
" FACTOR_OPERATOR <- [/*] " " FACTOR_OPERATOR <- < [/*] > _ "
" NUMBER <- [0-9]+ " " NUMBER <- < [0-9]+ > _ "
" ~_ <- [ \t\r\n]* "
; ;
peg parser(syntax); peg parser(syntax);