Mercurial > lcfOS
comparison python/baselex.py @ 357:818be710e13d
Added acceptance function to burg
author | Windel Bouwman |
---|---|
date | Fri, 14 Mar 2014 15:14:29 +0100 |
parents | 8d07a4254f04 |
children | 0c44e494ef58 |
comparison
equal
deleted
inserted
replaced
356:52492b304adf | 357:818be710e13d |
---|---|
1 | 1 |
2 import re | 2 import re |
3 from ppci import Token | 3 from ppci import Token, CompilerError |
4 | 4 |
5 def tokenize(tok_spec, txt): | 5 def tokenize(tok_spec, txt): |
6 tok_re = '|'.join('(?P<{}>{})'.format(pair[0], pair[1]) for pair in tok_spec) | 6 tok_re = '|'.join('(?P<{}>{})'.format(pair[0], pair[1]) for pair in tok_spec) |
7 gettok = re.compile(tok_re).match | 7 gettok = re.compile(tok_re).match |
8 func_map = {pair[0]: pair[2] for pair in tok_spec} | 8 func_map = {pair[0]: pair[2] for pair in tok_spec} |
19 typ, val = func(typ, val) | 19 typ, val = func(typ, val) |
20 yield Token(typ, val) | 20 yield Token(typ, val) |
21 pos = mo.end() | 21 pos = mo.end() |
22 mo = gettok(line, pos) | 22 mo = gettok(line, pos) |
23 if len(line) != pos: | 23 if len(line) != pos: |
24 raise ParserException('Lex fault at {}'.format(line[pos:])) | 24 raise CompilerError('Lex fault at {}'.format(line[pos:])) |