| 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 """ Parser for PPAPI IDL """ | 6 """ Parser for PPAPI IDL """ |
| 7 | 7 |
| 8 # | 8 # |
| 9 # IDL Parser | 9 # IDL Parser |
| 10 # | 10 # |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 # in turn are children of the file object created from the results of top. | 214 # in turn are children of the file object created from the results of top. |
| 215 def p_top(self, p): | 215 def p_top(self, p): |
| 216 """top : COMMENT COMMENT ext_attr_block top_list""" | 216 """top : COMMENT COMMENT ext_attr_block top_list""" |
| 217 | 217 |
| 218 Copyright = self.BuildComment('Copyright', p, 1) | 218 Copyright = self.BuildComment('Copyright', p, 1) |
| 219 Filedoc = self.BuildComment('Comment', p, 2) | 219 Filedoc = self.BuildComment('Comment', p, 2) |
| 220 | 220 |
| 221 p[0] = ListFromConcat(Copyright, Filedoc, p[3], p[4]) | 221 p[0] = ListFromConcat(Copyright, Filedoc, p[3], p[4]) |
| 222 if self.parse_debug: DumpReduction('top', p) | 222 if self.parse_debug: DumpReduction('top', p) |
| 223 | 223 |
| 224 def p_top_short(self, p): |
| 225 """top : COMMENT ext_attr_block top_list""" |
| 226 Copyright = self.BuildComment('Copyright', p, 1) |
| 227 Filedoc = IDLNode('Comment', self.lexobj.filename, p.lineno(2)-1, |
| 228 p.lexpos(2)-1, [self.BuildAttribute('NAME', ''), |
| 229 self.BuildAttribute('FORM', 'cc')]) |
| 230 p[0] = ListFromConcat(Copyright, Filedoc, p[2], p[3]) |
| 231 if self.parse_debug: DumpReduction('top', p) |
| 232 |
| 224 # Build a list of top level items. | 233 # Build a list of top level items. |
| 225 def p_top_list(self, p): | 234 def p_top_list(self, p): |
| 226 """top_list : callback_decl top_list | 235 """top_list : callback_decl top_list |
| 227 | describe_block top_list | 236 | describe_block top_list |
| 228 | dictionary_block top_list | 237 | dictionary_block top_list |
| 229 | enum_block top_list | 238 | enum_block top_list |
| 230 | inline top_list | 239 | inline top_list |
| 231 | interface_block top_list | 240 | interface_block top_list |
| 232 | label_block top_list | 241 | label_block top_list |
| 233 | namespace top_list | 242 | namespace top_list |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 # We allow namespace names of the form foo.bar.baz. | 291 # We allow namespace names of the form foo.bar.baz. |
| 283 def p_namespace_name(self, p): | 292 def p_namespace_name(self, p): |
| 284 """namespace_name : SYMBOL | 293 """namespace_name : SYMBOL |
| 285 | SYMBOL '.' namespace_name""" | 294 | SYMBOL '.' namespace_name""" |
| 286 p[0] = "".join(p[1:]) | 295 p[0] = "".join(p[1:]) |
| 287 | 296 |
| 288 | 297 |
| 289 # | 298 # |
| 290 # Dictionary | 299 # Dictionary |
| 291 # | 300 # |
| 292 # A dictionary contains is a named list of optional and required members. | 301 # A dictionary is a named list of optional and required members. |
| 293 # | 302 # |
| 294 def p_dictionary_block(self, p): | 303 def p_dictionary_block(self, p): |
| 295 """dictionary_block : modifiers DICTIONARY SYMBOL '{' struct_list '}' ';'""" | 304 """dictionary_block : modifiers DICTIONARY SYMBOL '{' struct_list '}' ';'""" |
| 296 p[0] = self.BuildNamed('Dictionary', p, 3, ListFromConcat(p[5])) | 305 p[0] = self.BuildNamed('Dictionary', p, 3, ListFromConcat(p[1], p[5])) |
| 297 | 306 |
| 298 # | 307 # |
| 299 # Callback | 308 # Callback |
| 300 # | 309 # |
| 301 # A callback is essentially a single function declaration (outside of an | 310 # A callback is essentially a single function declaration (outside of an |
| 302 # Interface). | 311 # Interface). |
| 303 # | 312 # |
| 304 def p_callback_decl(self, p): | 313 def p_callback_decl(self, p): |
| 305 """callback_decl : modifiers CALLBACK SYMBOL '=' SYMBOL param_list ';'""" | 314 """callback_decl : modifiers CALLBACK SYMBOL '=' SYMBOL param_list ';'""" |
| 306 children = ListFromConcat(p[1], p[6]) | 315 children = ListFromConcat(p[1], p[6]) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 # If there are 5 tokens plus a return slot, this must be in the form | 372 # If there are 5 tokens plus a return slot, this must be in the form |
| 364 # SYMBOL = SYMBOL (param_list) ext_attr_cont | 373 # SYMBOL = SYMBOL (param_list) ext_attr_cont |
| 365 elif len(p) == 6: | 374 elif len(p) == 6: |
| 366 member = self.BuildNamed('Member', p, 3, [p[4]]) | 375 member = self.BuildNamed('Member', p, 3, [p[4]]) |
| 367 p[0] = ListFromConcat(self.BuildAttribute(p[1], member), p[5]) | 376 p[0] = ListFromConcat(self.BuildAttribute(p[1], member), p[5]) |
| 368 # Otherwise, this must be: SYMBOL ext_attr_cont | 377 # Otherwise, this must be: SYMBOL ext_attr_cont |
| 369 else: | 378 else: |
| 370 p[0] = ListFromConcat(self.BuildAttribute(p[1], 'True'), p[2]) | 379 p[0] = ListFromConcat(self.BuildAttribute(p[1], 'True'), p[2]) |
| 371 if self.parse_debug: DumpReduction('ext_attribute_list', p) | 380 if self.parse_debug: DumpReduction('ext_attribute_list', p) |
| 372 | 381 |
| 382 def p_ext_attr_list_values(self, p): |
| 383 """ext_attr_list : SYMBOL '=' '(' values ')' ext_attr_cont |
| 384 | SYMBOL '=' '(' symbols ')' ext_attr_cont""" |
| 385 p[0] = ListFromConcat(self.BuildAttribute(p[1], p[4]), p[6]) |
| 386 |
| 387 def p_values(self, p): |
| 388 """values : value values_cont""" |
| 389 p[0] = ListFromConcat(p[1], p[2]) |
| 390 |
| 391 def p_symbols(self, p): |
| 392 """symbols : SYMBOL symbols_cont""" |
| 393 p[0] = ListFromConcat(p[1], p[2]) |
| 394 |
| 395 def p_symbols_cont(self, p): |
| 396 """symbols_cont : ',' SYMBOL symbols_cont |
| 397 | """ |
| 398 if len(p) > 1: p[0] = ListFromConcat(p[2], p[3]) |
| 399 |
| 400 def p_values_cont(self, p): |
| 401 """values_cont : ',' value values_cont |
| 402 | """ |
| 403 if len(p) > 1: p[0] = ListFromConcat(p[2], p[3]) |
| 404 |
| 373 def p_ext_attr_cont(self, p): | 405 def p_ext_attr_cont(self, p): |
| 374 """ext_attr_cont : ',' ext_attr_list | 406 """ext_attr_cont : ',' ext_attr_list |
| 375 |""" | 407 |""" |
| 376 if len(p) > 1: p[0] = p[2] | 408 if len(p) > 1: p[0] = p[2] |
| 377 if self.parse_debug: DumpReduction('ext_attribute_cont', p) | 409 if self.parse_debug: DumpReduction('ext_attribute_cont', p) |
| 378 | 410 |
| 379 def p_ext_attr_func(self, p): | 411 def p_ext_attr_func(self, p): |
| 380 """ext_attr_list : SYMBOL '(' attr_arg_list ')' ext_attr_cont""" | 412 """ext_attr_list : SYMBOL '(' attr_arg_list ')' ext_attr_cont""" |
| 381 p[0] = ListFromConcat(self.BuildAttribute(p[1] + '()', p[3]), p[5]) | 413 p[0] = ListFromConcat(self.BuildAttribute(p[1] + '()', p[3]), p[5]) |
| 382 if self.parse_debug: DumpReduction('attr_arg_func', p) | 414 if self.parse_debug: DumpReduction('attr_arg_func', p) |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 if len(p) > 3: | 580 if len(p) > 3: |
| 549 args = ListFromConcat(p[2], p[3]) | 581 args = ListFromConcat(p[2], p[3]) |
| 550 else: | 582 else: |
| 551 args = [] | 583 args = [] |
| 552 p[0] = self.BuildProduction('Callspec', p, 1, args) | 584 p[0] = self.BuildProduction('Callspec', p, 1, args) |
| 553 if self.parse_debug: DumpReduction('param_list', p) | 585 if self.parse_debug: DumpReduction('param_list', p) |
| 554 | 586 |
| 555 def p_param_item(self, p): | 587 def p_param_item(self, p): |
| 556 """param_item : modifiers optional SYMBOL arrays identifier""" | 588 """param_item : modifiers optional SYMBOL arrays identifier""" |
| 557 typeref = self.BuildAttribute('TYPEREF', p[3]) | 589 typeref = self.BuildAttribute('TYPEREF', p[3]) |
| 558 children = ListFromConcat(p[1],p[2], typeref, p[4]) | 590 children = ListFromConcat(p[1], p[2], typeref, p[4]) |
| 559 p[0] = self.BuildNamed('Param', p, 5, children) | 591 p[0] = self.BuildNamed('Param', p, 5, children) |
| 560 if self.parse_debug: DumpReduction('param_item', p) | 592 if self.parse_debug: DumpReduction('param_item', p) |
| 561 | 593 |
| 562 def p_optional(self, p): | 594 def p_optional(self, p): |
| 563 """optional : OPTIONAL | 595 """optional : OPTIONAL |
| 564 | """ | 596 | """ |
| 565 if len(p) == 2: | 597 if len(p) == 2: |
| 566 p[0] = self.BuildAttribute('OPTIONAL', True) | 598 p[0] = self.BuildAttribute('OPTIONAL', True) |
| 567 | 599 |
| 568 | 600 |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 ast = ParseFiles(filenames) | 1149 ast = ParseFiles(filenames) |
| 1118 errs = ast.GetProperty('ERRORS') | 1150 errs = ast.GetProperty('ERRORS') |
| 1119 if errs: | 1151 if errs: |
| 1120 ErrOut.Log('Found %d error(s).' % errs); | 1152 ErrOut.Log('Found %d error(s).' % errs); |
| 1121 InfoOut.Log("%d files processed." % len(filenames)) | 1153 InfoOut.Log("%d files processed." % len(filenames)) |
| 1122 return errs | 1154 return errs |
| 1123 | 1155 |
| 1124 | 1156 |
| 1125 if __name__ == '__main__': | 1157 if __name__ == '__main__': |
| 1126 sys.exit(Main(sys.argv[1:])) | 1158 sys.exit(Main(sys.argv[1:])) |
| OLD | NEW |