Mercurial > lcfOS
comparison python/c3/lexer.py @ 204:de3a68f677a5
Added long comment to c3 parser
author | Windel Bouwman |
---|---|
date | Fri, 21 Jun 2013 15:01:08 +0200 |
parents | b01429a5d695 |
children | d77cb5962cc5 |
comparison
equal
deleted
inserted
replaced
203:ca1ea402f6a1 | 204:de3a68f677a5 |
---|---|
24 ('NUMBER', r'\d+'), | 24 ('NUMBER', r'\d+'), |
25 ('ID', r'[A-Za-z][A-Za-z\d_]*'), | 25 ('ID', r'[A-Za-z][A-Za-z\d_]*'), |
26 ('NEWLINE', r'\n'), | 26 ('NEWLINE', r'\n'), |
27 ('SKIP', r'[ \t]'), | 27 ('SKIP', r'[ \t]'), |
28 ('COMMENTS', r'//.*'), | 28 ('COMMENTS', r'//.*'), |
29 ('LONGCOMMENTBEGIN', r'\/\*'), | |
30 ('LONGCOMMENTEND', r'\*\/'), | |
29 ('LEESTEKEN', r'==|[\.,=:;\-+*\[\]/\(\)]|>=|<=|<>|>|<|{|}'), | 31 ('LEESTEKEN', r'==|[\.,=:;\-+*\[\]/\(\)]|>=|<=|<>|>|<|{|}'), |
30 ('STRING', r"'.*?'") | 32 ('STRING', r"'.*?'") |
31 ] | 33 ] |
32 tok_re = '|'.join('(?P<%s>%s)' % pair for pair in tok_spec) | 34 tok_re = '|'.join('(?P<%s>%s)' % pair for pair in tok_spec) |
33 gettok = re.compile(tok_re).match | 35 gettok = re.compile(tok_re).match |
34 line = 1 | 36 line = 1 |
35 pos = line_start = 0 | 37 pos = line_start = 0 |
36 mo = gettok(s) | 38 mo = gettok(s) |
39 incomment = False | |
37 while mo is not None: | 40 while mo is not None: |
38 typ = mo.lastgroup | 41 typ = mo.lastgroup |
39 val = mo.group(typ) | 42 val = mo.group(typ) |
40 if typ == 'NEWLINE': | 43 if typ == 'NEWLINE': |
41 line_start = pos | 44 line_start = pos |
42 line += 1 | 45 line += 1 |
43 elif typ == 'COMMENTS': | 46 elif typ == 'COMMENT': |
44 pass | 47 pass |
48 elif typ == 'LONGCOMMENTBEGIN': | |
49 incomment = True | |
50 elif typ == 'LONGCOMMENTEND': | |
51 incomment = False | |
45 elif typ == 'SKIP': | 52 elif typ == 'SKIP': |
46 pass | 53 pass |
54 elif incomment: | |
55 pass # Wait until we are not in a comment section | |
47 else: | 56 else: |
48 if typ == 'ID': | 57 if typ == 'ID': |
49 if val in keywords: | 58 if val in keywords: |
50 typ = val | 59 typ = val |
51 elif typ == 'LEESTEKEN': | 60 elif typ == 'LEESTEKEN': |