More intuitive escape sequences for string patterns

This commit is contained in:
Bruce Hill 2020-09-28 15:13:54 -07:00
parent 344c1b1709
commit 88571d7639
3 changed files with 11 additions and 6 deletions

View File

@ -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;

View File

@ -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: `|

View File

@ -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