Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Start implementing posix classes.
- Loading branch information
Showing
with
28 additions
and
14 deletions.
-
+5
−0
tests/objects/test_regexpobject.py
-
+23
−14
topaz/utils/regexp.py
|
@@ -51,6 +51,7 @@ def test_compile_regexps(self, space): |
|
|
/(.*|.+)/ |
|
|
/(?<=b)/ |
|
|
/\\A|\\z/ |
|
|
/[[:alnum:]]/ |
|
|
""") |
|
|
|
|
|
def test_regexp_syntax_errors(self, space): |
|
@@ -204,6 +205,10 @@ def test_quantify_set(self, space): |
|
|
w_res = space.execute("return /([0-9]){3,5}?/ =~ 'ab12345'") |
|
|
assert space.int_w(w_res) == 2 |
|
|
|
|
|
def test_posix_class(self, space): |
|
|
w_res = space.execute("return /[[:digit:]]/ =~ 'abc2'") |
|
|
assert space.int_w(w_res) == 3 |
|
|
|
|
|
def test_quantify(self, space): |
|
|
w_res = space.execute("return /a{2,4}/.match('aaaaaa').to_a") |
|
|
assert self.unwrap(space, w_res) == ["aaaa"] |
|
|
|
@@ -836,6 +836,7 @@ def compile(self, ctx): |
|
|
} |
|
|
PROPERTIES = { |
|
|
"digit": CATEGORY_DIGIT, |
|
|
"alnum": CATEGORY_WORD, |
|
|
} |
|
|
|
|
|
|
|
@@ -1247,31 +1248,39 @@ def _parse_property(source, info, positive, in_set): |
|
|
here = source.pos |
|
|
if source.match("{"): |
|
|
negate = source.match("^") |
|
|
b = StringBuilder(5) |
|
|
found = False |
|
|
while True: |
|
|
ch = source.get() |
|
|
if ch == "}": |
|
|
found = True |
|
|
break |
|
|
elif not ch: |
|
|
break |
|
|
else: |
|
|
b.append(ch) |
|
|
if found: |
|
|
name = b.build() |
|
|
prop_name, name = _parse_property_name(source) |
|
|
if source.match("}"): |
|
|
if name in PROPERTIES: |
|
|
return Property(PROPERTIES[name], positive != negate) |
|
|
source.pos = here |
|
|
return make_character(info, ord("p" if positive else "P"), in_set) |
|
|
|
|
|
|
|
|
def _parse_property_name(source): |
|
|
b = StringBuilder(5) |
|
|
here = source.pos |
|
|
while True: |
|
|
pos2 = source.pos |
|
|
ch = source.get() |
|
|
if ch.isalnum(): |
|
|
b.append(ch) |
|
|
else: |
|
|
source.pos = pos2 |
|
|
break |
|
|
name = b.build() |
|
|
return name, name |
|
|
|
|
|
|
|
|
def _parse_numeric_escape(source, info, ch, in_set): |
|
|
raise NotImplementedError("_parse_numeric_escape") |
|
|
|
|
|
|
|
|
def _parse_posix_class(source, info): |
|
|
raise NotImplementedError("_parse_posix_class") |
|
|
negate = source.match("^") |
|
|
prop_name, name = _parse_property_name(source) |
|
|
if not source.match(":]"): |
|
|
raise ParseError |
|
|
return Property(PROPERTIES[name], negate) |
|
|
|
|
|
|
|
|
def _compile_no_cache(pattern, flags): |
|
|