| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """ Lexer for PPAPI IDL """ | 6 """ Lexer for PPAPI IDL """ |
| 7 | 7 |
| 8 # | 8 # |
| 9 # IDL Lexer | 9 # IDL Lexer |
| 10 # | 10 # |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 # Extra WebIDL keywords | 58 # Extra WebIDL keywords |
| 59 'CALLBACK', | 59 'CALLBACK', |
| 60 'DICTIONARY', | 60 'DICTIONARY', |
| 61 'OPTIONAL', | 61 'OPTIONAL', |
| 62 'STATIC', | 62 'STATIC', |
| 63 | 63 |
| 64 # Invented for apps use | 64 # Invented for apps use |
| 65 'NAMESPACE', | 65 'NAMESPACE', |
| 66 | 66 |
| 67 | |
| 68 # Data types | 67 # Data types |
| 69 'FLOAT', | 68 'FLOAT', |
| 70 'OCT', | 69 'OCT', |
| 71 'INT', | 70 'INT', |
| 72 'HEX', | 71 'HEX', |
| 73 'STRING', | 72 'STRING', |
| 74 | 73 |
| 75 # Operators | 74 # Operators |
| 76 'LSHIFT', | 75 'LSHIFT', |
| 77 'RSHIFT' | 76 'RSHIFT' |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 return t | 136 return t |
| 138 | 137 |
| 139 # Return a "preprocessor" inline block | 138 # Return a "preprocessor" inline block |
| 140 def t_INLINE(self, t): | 139 def t_INLINE(self, t): |
| 141 r'\#inline (.|\n)*?\#endinl.*' | 140 r'\#inline (.|\n)*?\#endinl.*' |
| 142 self.AddLines(t.value.count('\n')) | 141 self.AddLines(t.value.count('\n')) |
| 143 return t | 142 return t |
| 144 | 143 |
| 145 # A symbol or keyword. | 144 # A symbol or keyword. |
| 146 def t_KEYWORD_SYMBOL(self, t): | 145 def t_KEYWORD_SYMBOL(self, t): |
| 147 r'[A-Za-z][A-Za-z_0-9]*' | 146 r'_?[A-Za-z][A-Za-z_0-9]*' |
| 148 | 147 |
| 149 #All non-keywords are assumed to be symbols | 148 # All non-keywords are assumed to be symbols |
| 150 t.type = self.keywords.get(t.value, 'SYMBOL') | 149 t.type = self.keywords.get(t.value, 'SYMBOL') |
| 150 |
| 151 # We strip leading underscores so that you can specify symbols with the same |
| 152 # value as a keywords (E.g. a dictionary named 'interface'). |
| 153 if t.value[0] == '_': |
| 154 t.value = t.value[1:] |
| 151 return t | 155 return t |
| 152 | 156 |
| 153 def t_ANY_error(self, t): | 157 def t_ANY_error(self, t): |
| 154 msg = "Unrecognized input" | 158 msg = "Unrecognized input" |
| 155 line = self.lexobj.lineno | 159 line = self.lexobj.lineno |
| 156 | 160 |
| 157 # If that line has not been accounted for, then we must have hit | 161 # If that line has not been accounted for, then we must have hit |
| 158 # EoF, so compute the beginning of the line that caused the problem. | 162 # EoF, so compute the beginning of the line that caused the problem. |
| 159 if line >= len(self.index): | 163 if line >= len(self.index): |
| 160 # Find the offset in the line of the first word causing the issue | 164 # Find the offset in the line of the first word causing the issue |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 return -1 | 340 return -1 |
| 337 return 0 | 341 return 0 |
| 338 | 342 |
| 339 except lex.LexError as le: | 343 except lex.LexError as le: |
| 340 sys.stderr.write('%s\n' % str(le)) | 344 sys.stderr.write('%s\n' % str(le)) |
| 341 return -1 | 345 return -1 |
| 342 | 346 |
| 343 | 347 |
| 344 if __name__ == '__main__': | 348 if __name__ == '__main__': |
| 345 sys.exit(Main(sys.argv[1:])) | 349 sys.exit(Main(sys.argv[1:])) |
| OLD | NEW |