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

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

Issue 2048613002: Upstream the grammer for union types to idl_parser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
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 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 """SingleType : NonAnyType 863 """SingleType : NonAnyType
864 | ANY TypeSuffixStartingWithArray""" 864 | ANY TypeSuffixStartingWithArray"""
865 if len(p) == 2: 865 if len(p) == 2:
866 p[0] = p[1] 866 p[0] = p[1]
867 else: 867 else:
868 p[0] = ListFromConcat(self.BuildProduction('Any', p, 1), p[2]) 868 p[0] = ListFromConcat(self.BuildProduction('Any', p, 1), p[2])
869 869
870 # [75] 870 # [75]
871 def p_UnionType(self, p): 871 def p_UnionType(self, p):
872 """UnionType : '(' UnionMemberType OR UnionMemberType UnionMemberTypes ')'"" " 872 """UnionType : '(' UnionMemberType OR UnionMemberType UnionMemberTypes ')'"" "
873 members = ListFromConcat(p[2], p[4], p[5])
874 p[0] = self.BuildProduction('UnionType', p, 1, members)
873 875
874 # [76] 876 # [76]
875 def p_UnionMemberType(self, p): 877 def p_UnionMemberType(self, p):
876 """UnionMemberType : NonAnyType 878 """UnionMemberType : NonAnyType
877 | UnionType TypeSuffix 879 | UnionType TypeSuffix
878 | ANY '[' ']' TypeSuffix""" 880 | ANY '[' ']' TypeSuffix"""
881 if len(p) == 2:
882 p[0] = self.BuildProduction('Type', p, 1, p[1])
883 elif len(p) == 3:
884 p[0] = self.BuildProduction('Type', p, 1, ListFromConcat(p[1], p[2]))
885 else:
886 any_node = ListFromConcat(self.BuildProduction('Any', p, 1), p[4])
887 p[0] = self.BuildProduction('Type', p, 1, any_node)
888
879 # [77] 889 # [77]
880 def p_UnionMemberTypes(self, p): 890 def p_UnionMemberTypes(self, p):
881 """UnionMemberTypes : OR UnionMemberType UnionMemberTypes 891 """UnionMemberTypes : OR UnionMemberType UnionMemberTypes
882 |""" 892 |"""
893 if len(p) > 2:
894 p[0] = ListFromConcat(p[2], p[3])
883 895
884 # [78] Moved BYTESTRING, DOMSTRING, OBJECT, DATE, REGEXP to PrimitiveType 896 # [78] Moved BYTESTRING, DOMSTRING, OBJECT, DATE, REGEXP to PrimitiveType
885 # Moving all built-in types into PrimitiveType makes it easier to 897 # Moving all built-in types into PrimitiveType makes it easier to
886 # differentiate between them and 'identifier', since p[1] would be a string in 898 # differentiate between them and 'identifier', since p[1] would be a string in
887 # both cases. 899 # both cases.
888 def p_NonAnyType(self, p): 900 def p_NonAnyType(self, p):
889 """NonAnyType : PrimitiveType TypeSuffix 901 """NonAnyType : PrimitiveType TypeSuffix
890 | PromiseType Null 902 | PromiseType Null
891 | identifier TypeSuffix 903 | identifier TypeSuffix
892 | SEQUENCE '<' Type '>' Null 904 | SEQUENCE '<' Type '>' Null
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 1298
1287 print '\n'.join(ast.Tree(accept_props=['PROD'])) 1299 print '\n'.join(ast.Tree(accept_props=['PROD']))
1288 if errors: 1300 if errors:
1289 print '\nFound %d errors.\n' % errors 1301 print '\nFound %d errors.\n' % errors
1290 1302
1291 return errors 1303 return errors
1292 1304
1293 1305
1294 if __name__ == '__main__': 1306 if __name__ == '__main__':
1295 sys.exit(main(sys.argv[1:])) 1307 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/scripts/blink_idl_parser.py ('k') | tools/idl_parser/test_parser/interface_web.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698