Handle more escaped characters in regexps

This commit is contained in:
Max Brunsfeld 2014-08-03 21:57:21 -07:00
parent 4720672cfb
commit 01571da30d
2 changed files with 16 additions and 0 deletions

View file

@ -126,6 +126,16 @@ describe("parsing regex patterns", []() {
})
},
{
"escaped characters",
"\\t\\n\\r",
seq({
character({ '\t' }),
character({ '\n' }),
character({ '\r' }),
})
},
{
"plus repeats",
"(ab)+(cd)+",

View file

@ -174,6 +174,12 @@ class PatternParser {
return CharacterSet({ { 'a', 'z' }, { 'A', 'Z' }, { '0', '9' } });
case 'd':
return CharacterSet({ { '0', '9' } });
case 't':
return CharacterSet({ '\t' });
case 'n':
return CharacterSet({ '\n' });
case 'r':
return CharacterSet({ '\r' });
default:
return CharacterSet({ value });
}