diff options
author | Raymond Hettinger <python@rcn.com> | 2010-12-07 09:44:21 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2010-12-07 09:44:21 (GMT) |
commit | c2c7c373778967c084a060c4e313cff04146db66 (patch) | |
tree | 7567f93898dd27090cea4ba9f8148341f3569439 /Doc | |
parent | 673ccf20dcb3956474e24094c756b2043c3e57da (diff) | |
download | cpython-c2c7c373778967c084a060c4e313cff04146db66.zip cpython-c2c7c373778967c084a060c4e313cff04146db66.tar.gz cpython-c2c7c373778967c084a060c4e313cff04146db66.tar.bz2 |
Make the example a little more interesting and useful.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/re.rst | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/Doc/library/re.rst b/Doc/library/re.rst index c627f1a..423540c 100644 --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -1300,6 +1300,7 @@ successive matches:: Token = collections.namedtuple('Token', 'typ value line column') def tokenize(s): + keywords = {'IF', 'THEN', 'FOR', 'NEXT', 'GOSUB', 'RETURN'} tok_spec = [ ('NUMBER', r'\d+(\.\d*)?'), # Integer or decimal number ('ASSIGN', r':='), # Assignment operator @@ -1320,6 +1321,8 @@ successive matches:: line_start = pos line += 1 elif typ != 'SKIP': + if typ == 'ID' and val in keywords: + typ = val yield Token(typ, mo.group(typ), line, mo.start()-line_start) pos = mo.end() mo = gettok(s, pos) |