Code: Alles auswählen
def Scanner(s):
for m in re.finditer(r"(\d+)|'((?:\\.|[^'])+)'|(\w+:?)|([-+*/=<>~]+)|([()|:.])|\s+", s):
if m.lastindex:
t = m.group(m.lastindex)
if m.lastindex == 1:
yield 1, int(t)
elif m.lastindex == 2:
yield 2, t.decode("string_escape")
elif m.lastindex == 3:
yield 3 if t[-1] != ':' else 5, t
elif m.lastindex == 4:
yield 4, t
elif m.lastindex == 5:
yield "()|:.".find(t) + 6, t
Stefan