Skip to content
Permalink
Browse files

Start implementing posix classes.

  • Loading branch information
alex committed Jul 7, 2013
1 parent 4108429 commit 61ba7f87f17bc9bc93e10024af763cf209e556cd
Showing with 28 additions and 14 deletions.
  1. +5 −0 tests/objects/test_regexpobject.py
  2. +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):

0 comments on commit 61ba7f8

Please sign in to comment.
You can’t perform that action at this time.