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 p[0] = ListFromConcat(Copyright, p[2], p[3]) | |
228 if self.parse_debug: DumpReduction('top', p) | |
229 | |
224 # Build a list of top level items. | 230 # Build a list of top level items. |
225 def p_top_list(self, p): | 231 def p_top_list(self, p): |
226 """top_list : callback_decl top_list | 232 """top_list : callback_decl top_list |
227 | describe_block top_list | 233 | describe_block top_list |
228 | dictionary_block top_list | 234 | dictionary_block top_list |
229 | enum_block top_list | 235 | enum_block top_list |
230 | inline top_list | 236 | inline top_list |
231 | interface_block top_list | 237 | interface_block top_list |
232 | label_block top_list | 238 | label_block top_list |
233 | namespace top_list | 239 | namespace top_list |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 p[0] = "".join(p[1:]) | 292 p[0] = "".join(p[1:]) |
287 | 293 |
288 | 294 |
289 # | 295 # |
290 # Dictionary | 296 # Dictionary |
291 # | 297 # |
292 # A dictionary contains is a named list of optional and required members. | 298 # A dictionary contains is a named list of optional and required members. |
293 # | 299 # |
294 def p_dictionary_block(self, p): | 300 def p_dictionary_block(self, p): |
295 """dictionary_block : modifiers DICTIONARY SYMBOL '{' struct_list '}' ';'""" | 301 """dictionary_block : modifiers DICTIONARY SYMBOL '{' struct_list '}' ';'""" |
296 p[0] = self.BuildNamed('Dictionary', p, 3, ListFromConcat(p[5])) | 302 p[0] = self.BuildNamed('Dictionary', p, 3, ListFromConcat(p[1], p[5])) |
297 | 303 |
298 # | 304 # |
299 # Callback | 305 # Callback |
300 # | 306 # |
301 # A callback is essentially a single function declaration (outside of an | 307 # A callback is essentially a single function declaration (outside of an |
302 # Interface). | 308 # Interface). |
303 # | 309 # |
304 def p_callback_decl(self, p): | 310 def p_callback_decl(self, p): |
305 """callback_decl : modifiers CALLBACK SYMBOL '=' SYMBOL param_list ';'""" | 311 """callback_decl : modifiers CALLBACK SYMBOL '=' SYMBOL param_list ';'""" |
306 children = ListFromConcat(p[1], p[6]) | 312 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 | 369 # If there are 5 tokens plus a return slot, this must be in the form |
364 # SYMBOL = SYMBOL (param_list) ext_attr_cont | 370 # SYMBOL = SYMBOL (param_list) ext_attr_cont |
365 elif len(p) == 6: | 371 elif len(p) == 6: |
366 member = self.BuildNamed('Member', p, 3, [p[4]]) | 372 member = self.BuildNamed('Member', p, 3, [p[4]]) |
367 p[0] = ListFromConcat(self.BuildAttribute(p[1], member), p[5]) | 373 p[0] = ListFromConcat(self.BuildAttribute(p[1], member), p[5]) |
368 # Otherwise, this must be: SYMBOL ext_attr_cont | 374 # Otherwise, this must be: SYMBOL ext_attr_cont |
369 else: | 375 else: |
370 p[0] = ListFromConcat(self.BuildAttribute(p[1], 'True'), p[2]) | 376 p[0] = ListFromConcat(self.BuildAttribute(p[1], 'True'), p[2]) |
371 if self.parse_debug: DumpReduction('ext_attribute_list', p) | 377 if self.parse_debug: DumpReduction('ext_attribute_list', p) |
372 | 378 |
379 def p_ext_attr_list_values(self, p): | |
asargent_no_longer_on_chrome
2012/06/12 19:08:16
I don't see you reference this p_ext_attr_list_val
benjhayden
2012/06/12 20:15:42
p_ext_attr_list_values() extends |ext_attr_list|.
| |
380 """ext_attr_list : SYMBOL '=' '(' values ')' ext_attr_cont | |
381 | SYMBOL '=' '(' symbols ')' ext_attr_cont""" | |
382 p[0] = ListFromConcat(self.BuildAttribute(p[1], p[4]), p[6]) | |
383 | |
384 def p_values(self, p): | |
385 """values : value values_cont""" | |
386 p[0] = ListFromConcat(p[1], p[2]) | |
387 | |
388 def p_symbols(self, p): | |
389 """symbols : SYMBOL symbols_cont""" | |
390 p[0] = ListFromConcat(p[1], p[2]) | |
391 | |
392 def p_symbols_cont(self, p): | |
393 """symbols_cont : ',' SYMBOL symbols_cont | |
394 | """ | |
395 if len(p) > 1: p[0] = ListFromConcat(p[2], p[3]) | |
396 | |
397 def p_values_cont(self, p): | |
398 """values_cont : ',' value values_cont | |
399 | """ | |
400 if len(p) > 1: p[0] = ListFromConcat(p[2], p[3]) | |
401 | |
373 def p_ext_attr_cont(self, p): | 402 def p_ext_attr_cont(self, p): |
374 """ext_attr_cont : ',' ext_attr_list | 403 """ext_attr_cont : ',' ext_attr_list |
375 |""" | 404 |""" |
376 if len(p) > 1: p[0] = p[2] | 405 if len(p) > 1: p[0] = p[2] |
377 if self.parse_debug: DumpReduction('ext_attribute_cont', p) | 406 if self.parse_debug: DumpReduction('ext_attribute_cont', p) |
378 | 407 |
379 def p_ext_attr_func(self, p): | 408 def p_ext_attr_func(self, p): |
380 """ext_attr_list : SYMBOL '(' attr_arg_list ')' ext_attr_cont""" | 409 """ext_attr_list : SYMBOL '(' attr_arg_list ')' ext_attr_cont""" |
381 p[0] = ListFromConcat(self.BuildAttribute(p[1] + '()', p[3]), p[5]) | 410 p[0] = ListFromConcat(self.BuildAttribute(p[1] + '()', p[3]), p[5]) |
382 if self.parse_debug: DumpReduction('attr_arg_func', p) | 411 if self.parse_debug: DumpReduction('attr_arg_func', p) |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 def p_expression_symbol(self, p): | 523 def p_expression_symbol(self, p): |
495 "expression : SYMBOL" | 524 "expression : SYMBOL" |
496 p[0] = p[1] | 525 p[0] = p[1] |
497 if self.parse_debug: DumpReduction('expression_symbol', p) | 526 if self.parse_debug: DumpReduction('expression_symbol', p) |
498 | 527 |
499 def p_expression_integer(self, p): | 528 def p_expression_integer(self, p): |
500 "expression : integer" | 529 "expression : integer" |
501 p[0] = p[1] | 530 p[0] = p[1] |
502 if self.parse_debug: DumpReduction('expression_integer', p) | 531 if self.parse_debug: DumpReduction('expression_integer', p) |
503 | 532 |
533 def p_expression_float(self, p): | |
asargent_no_longer_on_chrome
2012/06/12 19:08:16
Do you still need this? I don't see any literal fl
benjhayden
2012/06/12 20:15:42
Done.
| |
534 "expression : FLOAT" | |
535 p[0] = p[1] | |
536 if self.parse_debug: DumpReduction('expression_float', p) | |
537 | |
504 # | 538 # |
505 # Array List | 539 # Array List |
506 # | 540 # |
507 # Defined a list of array sizes (if any). | 541 # Defined a list of array sizes (if any). |
508 # | 542 # |
509 def p_arrays(self, p): | 543 def p_arrays(self, p): |
510 """arrays : '[' ']' arrays | 544 """arrays : '[' ']' arrays |
511 | '[' integer ']' arrays | 545 | '[' integer ']' arrays |
512 | """ | 546 | """ |
513 # If there are 3 tokens plus a return slot it is an unsized array | 547 # If there are 3 tokens plus a return slot it is an unsized array |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
548 if len(p) > 3: | 582 if len(p) > 3: |
549 args = ListFromConcat(p[2], p[3]) | 583 args = ListFromConcat(p[2], p[3]) |
550 else: | 584 else: |
551 args = [] | 585 args = [] |
552 p[0] = self.BuildProduction('Callspec', p, 1, args) | 586 p[0] = self.BuildProduction('Callspec', p, 1, args) |
553 if self.parse_debug: DumpReduction('param_list', p) | 587 if self.parse_debug: DumpReduction('param_list', p) |
554 | 588 |
555 def p_param_item(self, p): | 589 def p_param_item(self, p): |
556 """param_item : modifiers optional SYMBOL arrays identifier""" | 590 """param_item : modifiers optional SYMBOL arrays identifier""" |
557 typeref = self.BuildAttribute('TYPEREF', p[3]) | 591 typeref = self.BuildAttribute('TYPEREF', p[3]) |
558 children = ListFromConcat(p[1],p[2], typeref, p[4]) | 592 children = ListFromConcat(p[1], p[2], typeref, p[4]) |
559 p[0] = self.BuildNamed('Param', p, 5, children) | 593 p[0] = self.BuildNamed('Param', p, 5, children) |
560 if self.parse_debug: DumpReduction('param_item', p) | 594 if self.parse_debug: DumpReduction('param_item', p) |
561 | 595 |
562 def p_optional(self, p): | 596 def p_optional(self, p): |
563 """optional : OPTIONAL | 597 """optional : OPTIONAL |
564 | """ | 598 | """ |
565 if len(p) == 2: | 599 if len(p) == 2: |
566 p[0] = self.BuildAttribute('OPTIONAL', True) | 600 p[0] = self.BuildAttribute('OPTIONAL', True) |
567 | 601 |
568 | 602 |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1117 ast = ParseFiles(filenames) | 1151 ast = ParseFiles(filenames) |
1118 errs = ast.GetProperty('ERRORS') | 1152 errs = ast.GetProperty('ERRORS') |
1119 if errs: | 1153 if errs: |
1120 ErrOut.Log('Found %d error(s).' % errs); | 1154 ErrOut.Log('Found %d error(s).' % errs); |
1121 InfoOut.Log("%d files processed." % len(filenames)) | 1155 InfoOut.Log("%d files processed." % len(filenames)) |
1122 return errs | 1156 return errs |
1123 | 1157 |
1124 | 1158 |
1125 if __name__ == '__main__': | 1159 if __name__ == '__main__': |
1126 sys.exit(Main(sys.argv[1:])) | 1160 sys.exit(Main(sys.argv[1:])) |
OLD | NEW |