Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: tools/idl_parser/idl_parser.py

Issue 1031593003: IDL: Add support for serializer definitions (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/idl_parser/test_parser/interface_web.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2013 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 266
267 # [9.1] Error recovery for InterfaceMembers 267 # [9.1] Error recovery for InterfaceMembers
268 def p_InterfaceMembersError(self, p): 268 def p_InterfaceMembersError(self, p):
269 """InterfaceMembers : error""" 269 """InterfaceMembers : error"""
270 p[0] = self.BuildError(p, 'InterfaceMembers') 270 p[0] = self.BuildError(p, 'InterfaceMembers')
271 271
272 # [10] Removed unsupported: Serializer 272 # [10] Removed unsupported: Serializer
273 def p_InterfaceMember(self, p): 273 def p_InterfaceMember(self, p):
274 """InterfaceMember : Const 274 """InterfaceMember : Const
275 | Operation 275 | Operation
276 | Serializer
276 | Stringifier 277 | Stringifier
277 | StaticMember 278 | StaticMember
278 | Iterable 279 | Iterable
279 | ReadonlyMember 280 | ReadonlyMember
280 | ReadWriteAttribute 281 | ReadWriteAttribute
281 | ReadWriteMaplike 282 | ReadWriteMaplike
282 | ReadWriteSetlike""" 283 | ReadWriteSetlike"""
283 p[0] = p[1] 284 p[0] = p[1]
284 285
285 # [11] 286 # [11]
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 | '-' INFINITY 461 | '-' INFINITY
461 | INFINITY 462 | INFINITY
462 | NAN """ 463 | NAN """
463 if len(p) > 2: 464 if len(p) > 2:
464 val = '-Infinity' 465 val = '-Infinity'
465 else: 466 else:
466 val = p[1] 467 val = p[1]
467 p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'float'), 468 p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'float'),
468 self.BuildAttribute('VALUE', val)) 469 self.BuildAttribute('VALUE', val))
469 470
470 # [30-34] NOT IMPLEMENTED (Serializer) 471 # [30]
472 def p_Serializer(self, p):
473 """Serializer : SERIALIZER SerializerRest"""
474 p[0] = self.BuildProduction('Serializer', p, 1, p[2])
475
476 # [31]
477 # TODO(jl): This adds ReturnType and ';', missing from the spec's grammar.
478 # https://www.w3.org/Bugs/Public/show_bug.cgi?id=20361
479 def p_SerializerRest(self, p):
480 """SerializerRest : ReturnType OperationRest
481 | '=' SerializationPattern ';'
482 | ';'"""
483 if len(p) == 3:
484 p[2].AddChildren(p[1])
485 p[0] = p[2]
486 elif len(p) == 4:
487 p[0] = p[2]
488
489 # [32]
490 def p_SerializationPattern(self, p):
491 """SerializationPattern : '{' SerializationPatternMap '}'
492 | '[' SerializationPatternList ']'
493 | identifier"""
494 if len(p) > 2:
495 p[0] = p[2]
496 else:
497 p[0] = self.BuildAttribute('ATTRIBUTE', p[1])
498
499 # [33]
500 # TODO(jl): This adds the "ATTRIBUTE" and "INHERIT ',' ATTRIBUTE" variants,
501 # missing from the spec's grammar.
502 # https://www.w3.org/Bugs/Public/show_bug.cgi?id=20361
503 def p_SerializationPatternMap(self, p):
504 """SerializationPatternMap : GETTER
505 | ATTRIBUTE
506 | INHERIT ',' ATTRIBUTE
507 | INHERIT Identifiers
508 | identifier Identifiers
509 |"""
510 p[0] = self.BuildProduction('Map', p, 0)
511 if len(p) == 4:
512 p[0].AddChildren(self.BuildTrue('INHERIT'))
513 p[0].AddChildren(self.BuildTrue('ATTRIBUTE'))
514 elif len(p) > 1:
515 if p[1] == 'getter':
516 p[0].AddChildren(self.BuildTrue('GETTER'))
517 elif p[1] == 'attribute':
518 p[0].AddChildren(self.BuildTrue('ATTRIBUTE'))
519 else:
520 if p[1] == 'inherit':
521 p[0].AddChildren(self.BuildTrue('INHERIT'))
522 attributes = p[2]
523 else:
524 attributes = ListFromConcat(p[1], p[2])
525 p[0].AddChildren(self.BuildAttribute('ATTRIBUTES', attributes))
526
527 # [34]
528 def p_SerializationPatternList(self, p):
529 """SerializationPatternList : GETTER
530 | identifier Identifiers
531 |"""
532 p[0] = self.BuildProduction('List', p, 0)
533 if len(p) > 1:
534 if p[1] == 'getter':
535 p[0].AddChildren(self.BuildTrue('GETTER'))
536 else:
537 attributes = ListFromConcat(p[1], p[2])
538 p[0].AddChildren(self.BuildAttribute('ATTRIBUTES', attributes))
471 539
472 # [35] 540 # [35]
473 def p_Stringifier(self, p): 541 def p_Stringifier(self, p):
474 """Stringifier : STRINGIFIER StringifierRest""" 542 """Stringifier : STRINGIFIER StringifierRest"""
475 p[0] = self.BuildProduction('Stringifier', p, 1, p[2]) 543 p[0] = self.BuildProduction('Stringifier', p, 1, p[2])
476 544
477 # [36] 545 # [36]
478 def p_StringifierRest(self, p): 546 def p_StringifierRest(self, p):
479 """StringifierRest : AttributeRest 547 """StringifierRest : AttributeRest
480 | ReturnType OperationRest 548 | ReturnType OperationRest
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 1276
1209 print '\n'.join(ast.Tree(accept_props=['PROD'])) 1277 print '\n'.join(ast.Tree(accept_props=['PROD']))
1210 if errors: 1278 if errors:
1211 print '\nFound %d errors.\n' % errors 1279 print '\nFound %d errors.\n' % errors
1212 1280
1213 return errors 1281 return errors
1214 1282
1215 1283
1216 if __name__ == '__main__': 1284 if __name__ == '__main__':
1217 sys.exit(main(sys.argv[1:])) 1285 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | tools/idl_parser/test_parser/interface_web.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698