Merge pull request #55 from tree-sitter/nonwhitespace-character-class-regex

Allow \S for negated whitespace regex shorthand
This commit is contained in:
Max Brunsfeld 2017-01-31 15:18:23 -08:00 committed by GitHub
commit 85e6d7ffad
2 changed files with 30 additions and 2 deletions

View file

@ -30,7 +30,7 @@ describe("parse_regex", []() {
{
"character classes",
"\\w-\\d-\\s",
"\\w-\\d-\\s-\\W-\\D-\\S",
seq({
character({
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
@ -41,7 +41,19 @@ describe("parse_regex", []() {
character({ '-' }),
character({ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }),
character({ '-' }),
character({ ' ', '\t', '\r', '\n' }) })
character({ ' ', '\t', '\r', '\n' }),
character({ '-' }),
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,11 +187,27 @@ 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');
case 'S':
return CharacterSet()
.include_all()
.exclude(' ')
.exclude('\t')
.exclude('\n')
.exclude('\r');
case 't':
return CharacterSet().include('\t');
case 'n':