Add support for \W and \D negated character classes too

This commit is contained in:
Timothy Clem 2017-01-31 15:03:48 -08:00
parent 902b7f9745
commit ab00f1b0da
2 changed files with 20 additions and 2 deletions

View file

@ -30,7 +30,7 @@ describe("parse_regex", []() {
{
"character classes",
"\\w-\\d-\\s-\\S",
"\\w-\\d-\\s-\\W-\\D-\\S",
seq({
character({
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
@ -43,7 +43,16 @@ describe("parse_regex", []() {
character({ '-' }),
character({ ' ', '\t', '\r', '\n' }),
character({ '-' }),
character({ ' ', '\t', '\r', '\n' }, false)
character({
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_' }, false),
character({ '-' }),
character({ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }, false),
character({ '-' }),
character({ ' ', '\t', '\r', '\n' }, false),
})
},

View file

@ -187,8 +187,17 @@ class PatternParser {
.include('A', 'Z')
.include('0', '9')
.include('_');
case 'W':
return CharacterSet()
.include_all()
.exclude('a', 'z')
.exclude('A', 'Z')
.exclude('0', '9')
.exclude('_');
case 'd':
return CharacterSet().include('0', '9');
case 'D':
return CharacterSet().include_all().exclude('0', '9');
case 's':
return CharacterSet().include(' ').include('\t').include('\n').include(
'\r');