Dynamic rules
{my %braces = qw /{ } < > ( ) [ ]/;
$braces {'\\'} = '\\\\';}
start: string /^\Z/ {"That's a string!"}
| <error: That's not a string!>
string: /["']/ <skip: ""> /(?:[^$item[1]\\]+|\\.)*/ "$item[1]"
| /qq?/ /./ <skip: ""> {$braces {$item [2]} || $item [2]}
/(?:[^$item[4]\\]+|\\.)*/ /[$item[4]]/
In [1] := q [foo bar]
Out [1] = That's a string!
In [2] := q {foo bar}
Out [2] = That's a string!
In [3] := q =foo bar=
Out [3] = That's a string!
In [4] := "foo bar"
Out [4] = That's a string!
In [5] := q [foo \]bar]
Out [5] = That's a string!
In [6] := q \foo bar\
Out [6] = That's a string!
In [7] := q !foo bar!
Out [7] = That's a string!
In [8] := 'foo \'bar ""'
Out [8] = That's a string!
In [9] := 'foo bar"
ERROR (line 1): That's not a string!
Out [9] = <<UNDEF>>
In [10] :=
[Prev]
[Next]
[Index]