aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler.c6
-rw-r--r--grammars/bpeg.bpeg3
-rw-r--r--grammars/builtins.bpeg8
3 files changed, 11 insertions, 6 deletions
diff --git a/compiler.c b/compiler.c
index a0ff087..60da7d8 100644
--- a/compiler.c
+++ b/compiler.c
@@ -395,6 +395,12 @@ 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");
+ const char *after_escape;
+ char e = unescapechar(&str[1], &after_escape);
+ if (e != str[1]) {
+ str = after_escape - 1;
+ continue;
+ }
if (str[1] == '\\') {
++str;
continue;
diff --git a/grammars/bpeg.bpeg b/grammars/bpeg.bpeg
index 4c46c6b..f3e2f48 100644
--- a/grammars/bpeg.bpeg
+++ b/grammars/bpeg.bpeg
@@ -7,7 +7,7 @@ Def: @[name]id _ `: __ (
/ @[!]{...>(`;/id_`:/$) => "Invalid definition: @0"})
# This is used for command line arguments:
-String-pattern: 0+(`\ pat 0-1`; / .)
+String-pattern: 0+(`\ (escape-sequence / pat 0-1`;) / .)
pat: suffixed-pat / simple-pat
simple-pat: Upto-and / Dot / String / Char-range / Char / Escape-range / Escape / No
@@ -37,7 +37,6 @@ 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: `|
diff --git a/grammars/builtins.bpeg b/grammars/builtins.bpeg
index fd17b79..72da396 100644
--- a/grammars/builtins.bpeg
+++ b/grammars/builtins.bpeg
@@ -49,7 +49,7 @@ utf8-codepoint: (
/ \xf0-xf7 3\x80-xbf
)
crlf: \r\n
-cr: \r; r: \r
+cr: \r
anglebraces: `< 0+(anglebraces / !`>$.) `>
brackets: `[ 0+(brackets / !`]$.) `]
braces: `{ 0+(braces / !`}$.) `}
@@ -66,9 +66,9 @@ digit: `0-9
Abc: `a-z/`A-Z
ABC: `A-Z
abc: `a-z
-esc: \e; e: \e
-tab: \t; t: \t
-nl: \n; lf: \n; n: \n
+esc: \e
+tab: \t
+nl: \n; lf: \n
c-block-comment: '/*' ... '*/'
c-line-comment: '//' ..$
c-comment: c-line-comment / c-block-comment