| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # | 2 # |
| 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """ Lexer for PPAPI IDL """ | 7 """ Lexer for PPAPI IDL """ |
| 8 | 8 |
| 9 # | 9 # |
| 10 # IDL Lexer | 10 # IDL Lexer |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 'TYPEDEF', | 57 'TYPEDEF', |
| 58 | 58 |
| 59 # Data types | 59 # Data types |
| 60 'FLOAT', | 60 'FLOAT', |
| 61 'OCT', | 61 'OCT', |
| 62 'INT', | 62 'INT', |
| 63 'HEX', | 63 'HEX', |
| 64 'STRING', | 64 'STRING', |
| 65 | 65 |
| 66 # Operators | 66 # Operators |
| 67 'LSHIFT' | 67 'LSHIFT', |
| 68 'RSHIFT' |
| 68 ] | 69 ] |
| 69 | 70 |
| 70 # 'keywords' is a map of string to token type. All SYMBOL tokens are | 71 # 'keywords' is a map of string to token type. All SYMBOL tokens are |
| 71 # matched against keywords, to determine if the token is actually a keyword. | 72 # matched against keywords, to determine if the token is actually a keyword. |
| 72 keywords = { | 73 keywords = { |
| 73 'attribute' : 'ATTRIBUTE', | 74 'attribute' : 'ATTRIBUTE', |
| 74 'describe' : 'DESCRIBE', | 75 'describe' : 'DESCRIBE', |
| 75 'enum' : 'ENUM', | 76 'enum' : 'ENUM', |
| 76 'label' : 'LABEL', | 77 'label' : 'LABEL', |
| 77 'interface' : 'INTERFACE', | 78 'interface' : 'INTERFACE', |
| 78 'readonly' : 'READONLY', | 79 'readonly' : 'READONLY', |
| 79 'struct' : 'STRUCT', | 80 'struct' : 'STRUCT', |
| 80 'typedef' : 'TYPEDEF', | 81 'typedef' : 'TYPEDEF', |
| 81 } | 82 } |
| 82 | 83 |
| 83 # 'literals' is a value expected by lex which specifies a list of valid | 84 # 'literals' is a value expected by lex which specifies a list of valid |
| 84 # literal tokens, meaning the token type and token value are identical. | 85 # literal tokens, meaning the token type and token value are identical. |
| 85 literals = '"*.(){}[],;:=+-' | 86 literals = '"*.(){}[],;:=+-/~|&^' |
| 86 | 87 |
| 87 # Token definitions | 88 # Token definitions |
| 88 # | 89 # |
| 89 # Lex assumes any value or function in the form of 't_<TYPE>' represents a | 90 # Lex assumes any value or function in the form of 't_<TYPE>' represents a |
| 90 # regular expression where a match will emit a token of type <TYPE>. In the | 91 # regular expression where a match will emit a token of type <TYPE>. In the |
| 91 # case of a function, the function is called when a match is made. These | 92 # case of a function, the function is called when a match is made. These |
| 92 # definitions come from WebIDL. | 93 # definitions come from WebIDL. |
| 93 | 94 |
| 94 # 't_ignore' is a special match of items to ignore | 95 # 't_ignore' is a special match of items to ignore |
| 95 t_ignore = ' \t' | 96 t_ignore = ' \t' |
| 96 | 97 |
| 97 # Constant values | 98 # Constant values |
| 98 t_FLOAT = r'-?(\d+\.\d*|\d*\.\d+)([Ee][+-]?\d+)?|-?\d+[Ee][+-]?\d+' | 99 t_FLOAT = r'-?(\d+\.\d*|\d*\.\d+)([Ee][+-]?\d+)?|-?\d+[Ee][+-]?\d+' |
| 99 t_INT = r'-?[0-9]+' | 100 t_INT = r'-?[0-9]+' |
| 100 t_OCT = r'-?0[0-7]+' | 101 t_OCT = r'-?0[0-7]+' |
| 101 t_HEX = r'-?0[Xx][0-9A-Fa-f]+' | 102 t_HEX = r'-?0[Xx][0-9A-Fa-f]+' |
| 102 t_LSHIFT = r'<<' | 103 t_LSHIFT = r'<<' |
| 104 t_RSHIFT = r'>>' |
| 103 | 105 |
| 104 # A line ending '\n', we use this to increment the line number | 106 # A line ending '\n', we use this to increment the line number |
| 105 def t_LINE_END(self, t): | 107 def t_LINE_END(self, t): |
| 106 r'\n+' | 108 r'\n+' |
| 107 self.AddLines(len(t.value)) | 109 self.AddLines(len(t.value)) |
| 108 | 110 |
| 109 # We do not process escapes in the IDL strings. Strings are exclusively | 111 # We do not process escapes in the IDL strings. Strings are exclusively |
| 110 # used for attributes, and not used as typical 'C' constants. | 112 # used for attributes, and not used as typical 'C' constants. |
| 111 def t_STRING(self, t): | 113 def t_STRING(self, t): |
| 112 r'"[^"]*"' | 114 r'"[^"]*"' |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 return -1 | 324 return -1 |
| 323 return 0 | 325 return 0 |
| 324 | 326 |
| 325 except lex.LexError as le: | 327 except lex.LexError as le: |
| 326 sys.stderr.write('%s\n' % str(le)) | 328 sys.stderr.write('%s\n' % str(le)) |
| 327 return -1 | 329 return -1 |
| 328 | 330 |
| 329 if __name__ == '__main__': | 331 if __name__ == '__main__': |
| 330 sys.exit(Main(sys.argv[1:])) | 332 sys.exit(Main(sys.argv[1:])) |
| 331 | 333 |
| OLD | NEW |