[Python-Dev] Scanner
Paul Prescod
paulp@ActiveState.com
Sat, 26 May 2001 08:02:08 -0700
What ever happened to the sre Scanner? It seemed like a good idea but it
was not documented and it doesn't work for me. Is it just a case of
nobody got around to the documentation or have we decided against it?
Here's the code that doesn't work for me:
from sre import Scanner
scanner = Scanner([
(r"[a-zA-Z_]\w*", None),
(r"\d+\.\d*", None),
(r"\d+", None),
(r"=|\+|-|\*|/", None),
(r"\s+", None),
])
tokens, tail = scanner.scan("sum = 3*foo + 312.50 + bar")
Traceback (most recent call last):
File "junk.py", line 11, in ?
tokens, tail = scanner.scan("sum = 3*foo + 312.50 + bar")
File "c:\program files\python21\lib\sre.py", line 254, in scan
action = self.lexicon[m.lastindex][1]
TypeError: sequence index must be integer
m.lastindex is None
--
Take a recipe. Leave a recipe.
Python Cookbook! http://www.ActiveState.com/pythoncookbook