Chromium Code Reviews| Index: ppapi/generators/idl_lexer.py |
| =================================================================== |
| --- ppapi/generators/idl_lexer.py (revision 90352) |
| +++ ppapi/generators/idl_lexer.py (working copy) |
| @@ -49,7 +49,9 @@ |
| 'COMMENT', |
|
sehr (please use chromium)
2011/06/29 16:43:06
should 'ATTRIBUTE' be here also?
noelallen1
2011/06/29 18:59:01
An extended attribute is a grammar component consi
|
| 'DESCRIBE', |
| 'ENUM', |
| + 'LABEL', |
| 'SYMBOL', |
| + 'INLINE', |
| 'INTERFACE', |
| 'STRUCT', |
| 'TYPEDEF', |
| @@ -68,8 +70,10 @@ |
| # 'keywords' is a map of string to token type. All SYMBOL tokens are |
| # matched against keywords, to determine if the token is actually a keyword. |
| keywords = { |
| + 'attribute' : 'ATTRIBUTE', |
| 'describe' : 'DESCRIBE', |
| 'enum' : 'ENUM', |
| + 'label' : 'LABEL', |
| 'interface' : 'INTERFACE', |
| 'readonly' : 'READONLY', |
| 'struct' : 'STRUCT', |
| @@ -115,10 +119,31 @@ |
| r'(/\*(.|\n)*?\*/)|(//.*)' |
| self.AddLines(t.value.count('\n')) |
| - # C++ comments should keep the newline |
| - if t.value[:2] == '//': t.value += '\n' |
| + # Remove comment markers |
| + if t.value[:2] == '//': |
| + # For C++ style, remove the preceeding '//' |
|
sehr (please use chromium)
2011/06/29 16:43:06
s/preceeding/preceding/
noelallen1
2011/06/29 18:59:01
Done.
|
| + t.value = t.value[2:].rstrip() |
| + else: |
| + # For C style, remove ending '*/'' |
| + lines = [] |
| + for line in t.value[:-2].split('\n'): |
| + # Remove characters until start marker for this line '*' if found |
| + # otherwise it should be blank. |
| + offs = line.find('*') |
| + if offs >= 0: |
| + line = line[offs + 1:].rstrip() |
| + else: |
| + line = '' |
| + lines.append(line) |
| + t.value = '\n'.join(lines) |
| return t |
| + # Return a "preprocessor" inline block |
| + def t_INLINE(self, t): |
| + r'\#inline (.|\n)*\#endinl.*' |
| + self.AddLines(t.value.count('\n')) |
| + return t |
| + |
| # A symbol or keyword. |
| def t_KEYWORD_SYMBOL(self, t): |
| r'[A-Za-z][A-Za-z_0-9]*' |
| @@ -128,10 +153,22 @@ |
| return t |
| def t_ANY_error(self, t): |
| + msg = "Unrecognized intput" |
|
sehr (please use chromium)
2011/06/29 16:43:06
s/intput/input/
noelallen1
2011/06/29 18:59:01
Done.
|
| line = self.lexobj.lineno |
| + |
| + # If that line has not been accounted for, then we must have hit |
| + # EoF, so compute the beginning of the that caused the problem. |
|
sehr (please use chromium)
2011/06/29 16:43:06
the what that?
noelallen1
2011/06/29 18:59:01
Done.
|
| + if line >= len(self.index): |
| + # Find the offset in the line of the first word causing the issue |
| + word = t.value.split()[0] |
| + offs = self.lines[line - 1].find(word) |
| + # Add the computed line's starting possition |
|
sehr (please use chromium)
2011/06/29 16:43:06
s/possition/position/
noelallen1
2011/06/29 18:59:01
Done.
|
| + self.index.append(self.lexobj.lexpos - offs) |
| + msg = "Unexpected EoF reached after" |
| + |
| pos = self.lexobj.lexpos - self.index[line] |
| file = self.lexobj.filename |
| - out = self.ErrorMessage(file, line, pos, "Unrecognized input") |
| + out = self.ErrorMessage(file, line, pos, msg) |
| sys.stderr.write(out + '\n') |
| def AddLines(self, count): |
| @@ -214,8 +251,13 @@ |
| # |
| def TestSame(values): |
| src1 = ' '.join(values) |
| - src2 = ' '.join(TextToTokens(src1)) |
| + values2 = TextToTokens(src1) |
| + src2 = ' '.join(values2) |
| + for i in range(len(values)): |
| + if values[i] != values2[i]: |
| + print "%d >>%s<< >>%s<<" % (i, values[i], values2[i]) |
| + |
| if GetOption('output'): |
| sys.stdout.write('Generating original.txt and tokenized.txt\n') |
| open('original.txt', 'w').write(src1) |
| @@ -225,6 +267,7 @@ |
| sys.stdout.write('Same: Pass\n') |
| return 0 |
| + print "****************\n%s\n%s***************\n" % (src1, src2) |
| sys.stdout.write('Same: Failed\n') |
| return -1 |