mirror of https://github.com/python/cpython
- fixed "{ in any other context" bug
- minor comment touchups in the C module
This commit is contained in:
parent
0cebe439ce
commit
c13222cdff
|
@ -142,12 +142,13 @@ class SubPattern:
|
||||||
|
|
||||||
class Tokenizer:
|
class Tokenizer:
|
||||||
def __init__(self, string):
|
def __init__(self, string):
|
||||||
self.index = 0
|
|
||||||
self.string = string
|
self.string = string
|
||||||
self.next = self.__next()
|
self.index = 0
|
||||||
|
self.__next()
|
||||||
def __next(self):
|
def __next(self):
|
||||||
if self.index >= len(self.string):
|
if self.index >= len(self.string):
|
||||||
return None
|
self.next = None
|
||||||
|
return
|
||||||
char = self.string[self.index]
|
char = self.string[self.index]
|
||||||
if char[0] == "\\":
|
if char[0] == "\\":
|
||||||
try:
|
try:
|
||||||
|
@ -156,21 +157,20 @@ class Tokenizer:
|
||||||
raise error, "bogus escape"
|
raise error, "bogus escape"
|
||||||
char = char + c
|
char = char + c
|
||||||
self.index = self.index + len(char)
|
self.index = self.index + len(char)
|
||||||
return char
|
self.next = char
|
||||||
def match(self, char):
|
def match(self, char):
|
||||||
if char == self.next:
|
if char == self.next:
|
||||||
self.next = self.__next()
|
self.__next()
|
||||||
return 1
|
|
||||||
return 0
|
|
||||||
def match_set(self, set):
|
|
||||||
if self.next and self.next in set:
|
|
||||||
self.next = self.__next()
|
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
def get(self):
|
def get(self):
|
||||||
this = self.next
|
this = self.next
|
||||||
self.next = self.__next()
|
self.__next()
|
||||||
return this
|
return this
|
||||||
|
def tell(self):
|
||||||
|
return self.index, self.next
|
||||||
|
def seek(self, index):
|
||||||
|
self.index, self.next = index
|
||||||
|
|
||||||
def isident(char):
|
def isident(char):
|
||||||
return "a" <= char <= "z" or "A" <= char <= "Z" or char == "_"
|
return "a" <= char <= "z" or "A" <= char <= "Z" or char == "_"
|
||||||
|
@ -381,6 +381,7 @@ def _parse(source, state):
|
||||||
elif this == "+":
|
elif this == "+":
|
||||||
min, max = 1, MAXREPEAT
|
min, max = 1, MAXREPEAT
|
||||||
elif this == "{":
|
elif this == "{":
|
||||||
|
here = source.tell()
|
||||||
min, max = 0, MAXREPEAT
|
min, max = 0, MAXREPEAT
|
||||||
lo = hi = ""
|
lo = hi = ""
|
||||||
while source.next in DIGITS:
|
while source.next in DIGITS:
|
||||||
|
@ -391,7 +392,9 @@ def _parse(source, state):
|
||||||
else:
|
else:
|
||||||
hi = lo
|
hi = lo
|
||||||
if not source.match("}"):
|
if not source.match("}"):
|
||||||
raise error, "bogus range"
|
subpattern.append((LITERAL, ord(this)))
|
||||||
|
source.seek(here)
|
||||||
|
continue
|
||||||
if lo:
|
if lo:
|
||||||
min = int(lo)
|
min = int(lo)
|
||||||
if hi:
|
if hi:
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
* 00-06-25 fl major changes to better deal with nested repeats (0.9)
|
* 00-06-25 fl major changes to better deal with nested repeats (0.9)
|
||||||
* 00-06-28 fl fixed findall (0.9.1)
|
* 00-06-28 fl fixed findall (0.9.1)
|
||||||
* 00-06-29 fl fixed split, added more scanner features (0.9.2)
|
* 00-06-29 fl fixed split, added more scanner features (0.9.2)
|
||||||
* 00-06-30 fl tuning, fast search (0.9.3)
|
* 00-06-30 fl added fast search optimization (0.9.3)
|
||||||
* 00-06-30 fl added assert (lookahead) primitives, etc (0.9.4)
|
* 00-06-30 fl added assert (lookahead) primitives, etc (0.9.4)
|
||||||
*
|
*
|
||||||
* Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
|
* Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
|
||||||
|
@ -365,18 +365,21 @@ SRE_MEMBER(SRE_CODE* set, SRE_CODE ch)
|
||||||
return !ok;
|
return !ok;
|
||||||
|
|
||||||
case SRE_OP_LITERAL:
|
case SRE_OP_LITERAL:
|
||||||
|
/* args: <literal> */
|
||||||
if (ch == set[0])
|
if (ch == set[0])
|
||||||
return ok;
|
return ok;
|
||||||
set++;
|
set++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SRE_OP_RANGE:
|
case SRE_OP_RANGE:
|
||||||
|
/* args: <lower> <upper> */
|
||||||
if (set[0] <= ch && ch <= set[1])
|
if (set[0] <= ch && ch <= set[1])
|
||||||
return ok;
|
return ok;
|
||||||
set += 2;
|
set += 2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SRE_OP_CATEGORY:
|
case SRE_OP_CATEGORY:
|
||||||
|
/* args: <category> */
|
||||||
if (sre_category(set[0], (int) ch))
|
if (sre_category(set[0], (int) ch))
|
||||||
return ok;
|
return ok;
|
||||||
set += 1;
|
set += 1;
|
||||||
|
|
Loading…
Reference in New Issue