diff options
| -rw-r--r-- | compiler.c | 13 | ||||
| -rw-r--r-- | grammars/bpeg.bpeg | 12 |
2 files changed, 16 insertions, 9 deletions
@@ -96,9 +96,12 @@ vm_op_t *bpeg_simplepattern(file_t *f, const char *str) switch (c) { // Any char (dot) ($. is multiline anychar) case '.': { - if (matchchar(&str, '.')) { // ".." - if (matchchar(&str, '.')) // "..." + if (*str == '.') { // ".." + ++str; + if (*str == '.') { // "..." + ++str; op->multiline = 1; + } vm_op_t *till = bpeg_simplepattern(f, str); op->op = VM_UPTO_AND; op->len = -1; @@ -135,7 +138,7 @@ vm_op_t *bpeg_simplepattern(file_t *f, const char *str) } // Escapes case '\\': { - check(*str, "Expected escape after '\\'"); + check(*str && *str != '\n', "Expected escape after '\\'"); op->len = 1; char e = unescapechar(str, &str); if (*str == '-') { // Escape range (e.g. \x00-\xFF) @@ -392,6 +395,10 @@ vm_op_t *bpeg_stringpattern(file_t *f, const char *str) for (; *str; str++) { if (*str == '\\') { check(str[1], "Expected more string contents after backslash"); + if (str[1] == '\\') { + ++str; + continue; + } interp = bpeg_simplepattern(f, str + 1); check(interp != NULL, "No valid BPEG pattern detected after backslash"); break; diff --git a/grammars/bpeg.bpeg b/grammars/bpeg.bpeg index 43d6834..4c46c6b 100644 --- a/grammars/bpeg.bpeg +++ b/grammars/bpeg.bpeg @@ -17,7 +17,6 @@ suffixed-pat: Eq-pat / simple-pat 0-1( @[!]{`* => "'*' is not a BPEG operator. Use 0+<pat> instead of <pat>*"} / @[!]{`+ => "'+' is not a BPEG operator. Use 1+<pat> instead of <pat>+"} / @[!]{`? => "'?' is not a BPEG operator. Use 0-1<pat> instead of <pat>?"} - / @[!]{`= => "'=' is not valid here. Perhaps you meant '==' or ':'"} ) Eq-pat: @[first]simple-pat "==" @[second]pat @@ -38,27 +37,28 @@ escape-sequence: ( `n/`t/`r/`e/`b/`a/`v / 1-3 `0-7 / `x 2 (`0-9/`a-f/`A-F) + / . ) No: `! (_@pat / @[!]{=>"Expected a pattern after the exclamation mark"}) Nodent: `| -Upto-and: 2-3`. 0-1(_@pat) +Upto-and: 2-3`. 0-1(_@simple-pat) Repeat: ( @[min]int _ `- _ @[max]int / @[min]int _ `+ @[max]'' / @[min]@[max]int - ) _ @[repeat-pat]pat 0-1( _ `% _ @[sep]pat) + ) __ @[repeat-pat]pat 0-1(__`%__@[sep]pat) After: `< _ pat Before: `> _ pat Capture: `@ 0-1(_ `[ @[capture-name](...>(`]/$$)) (`] / @[!]{=>"Expected closing bracket here"})) _ @[capture]pat Replace: `{ __ ( 0-1(@[replace-pat]extended-pat __) "=>" 0-1(__ @[replacement]String) ) __ (`} / @[!]{=> "Expected closing brace here"}) -Ref: @[name]id !>(_`:) +Ref: @[name]id !(_`:) parens: `( __ extended-pat (__ `) / @[!]{=> "Expected closing parenthesis here"}) -Chain: 2+@pat % __ -Otherwise: 2+@(Chain/pat) % (__`/__) +Chain: 2+@pat%__ +Otherwise: 2+@(Chain/pat)%(__`/__) extended-pat: Otherwise / Chain / pat # Special-symbol rules: |
