FindTest{`(([^xyz]*)(d))`, "abcd", build(1, 0, 4, 0, 4, 0, 3, 3, 4)},
FindTest{`((a|b|c)*(d))`, "abcd", build(1, 0, 4, 0, 4, 2, 3, 3, 4)},
FindTest{`(((a|b|c)*)(d))`, "abcd", build(1, 0, 4, 0, 4, 0, 3, 2, 3, 3, 4)},
+ FindTest{`\a\b\f\n\r\t\v`, "\a\b\f\n\r\t\v", build(1, 0, 7)},
+ FindTest{`[\a\b\f\n\r\t\v]+`, "\a\b\f\n\r\t\v", build(1, 0, 7)},
FindTest{`a*(|(b))c*`, "aacc", build(1, 0, 4, 2, 2, -1, -1)},
FindTest{`(.*).*`, "ab", build(1, 0, 2, 0, 2)},
// character [ '-' character ]
//
// All characters are UTF-8-encoded code points. Backslashes escape special
-// characters, including inside character classes.
+// characters, including inside character classes. The standard Go character
+// escapes are also recognized: \a \b \f \n \r \t \v.
//
// There are 16 methods of Regexp that match a regular expression and identify
// the matched text. Their names are matched by this regular expression:
return false
}
+var escapes = []byte("abfnrtv")
+var escaped = []byte("\a\b\f\n\r\t\v")
+
+func escape(c int) int {
+ for i, b := range escapes {
+ if int(b) == c {
+ return i
+ }
+ }
+ return -1
+}
+
func (p *parser) charClass() instr {
cc := newCharClass()
if p.c() == '^' {
switch {
case c == endOfFile:
p.error(ErrExtraneousBackslash)
- case c == 'n':
- c = '\n'
case ispunct(c):
// c is as delivered
+ case escape(c) >= 0:
+ c = int(escaped[escape(c)])
default:
p.error(ErrBadBackslash)
}
switch {
case c == endOfFile:
p.error(ErrExtraneousBackslash)
- case c == 'n':
- c = '\n'
case ispunct(c):
// c is as delivered
+ case escape(c) >= 0:
+ c = int(escaped[escape(c)])
default:
p.error(ErrBadBackslash)
}