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

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

Issue 2708173002: idl_parser: Add support for the record<K, V> WebIDL type. (Closed)
Patch Set: Created 3 years, 10 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 874 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 885
886 # [78] Moved BYTESTRING, DOMSTRING, OBJECT, DATE, REGEXP to PrimitiveType 886 # [78] Moved BYTESTRING, DOMSTRING, OBJECT, DATE, REGEXP to PrimitiveType
887 # Moving all built-in types into PrimitiveType makes it easier to 887 # Moving all built-in types into PrimitiveType makes it easier to
888 # differentiate between them and 'identifier', since p[1] would be a string in 888 # differentiate between them and 'identifier', since p[1] would be a string in
889 # both cases. 889 # both cases.
890 def p_NonAnyType(self, p): 890 def p_NonAnyType(self, p):
891 """NonAnyType : PrimitiveType TypeSuffix 891 """NonAnyType : PrimitiveType TypeSuffix
892 | PromiseType Null 892 | PromiseType Null
893 | identifier TypeSuffix 893 | identifier TypeSuffix
894 | SEQUENCE '<' Type '>' Null 894 | SEQUENCE '<' Type '>' Null
895 | FROZENARRAY '<' Type '>' Null""" 895 | FROZENARRAY '<' Type '>' Null
896 | RecordType Null"""
896 if len(p) == 3: 897 if len(p) == 3:
897 if type(p[1]) == str: 898 if type(p[1]) == str:
898 typeref = self.BuildNamed('Typeref', p, 1) 899 typeref = self.BuildNamed('Typeref', p, 1)
899 else: 900 else:
900 typeref = p[1] 901 typeref = p[1]
901 p[0] = ListFromConcat(typeref, p[2]) 902 p[0] = ListFromConcat(typeref, p[2])
902 903
903 if len(p) == 6: 904 if len(p) == 6:
904 cls = 'Sequence' if p[1] == 'sequence' else 'FrozenArray' 905 cls = 'Sequence' if p[1] == 'sequence' else 'FrozenArray'
905 p[0] = self.BuildProduction(cls, p, 1, ListFromConcat(p[3], p[5])) 906 p[0] = self.BuildProduction(cls, p, 1, ListFromConcat(p[3], p[5]))
906 907
907 # [79] NOT IMPLEMENTED (BufferRelatedType) 908 # [79] NOT IMPLEMENTED (BufferRelatedType)
908 909
909 # [80] 910 # [80]
910 def p_ConstType(self, p): 911 def p_ConstType(self, p):
911 """ConstType : PrimitiveType Null 912 """ConstType : PrimitiveType Null
912 | identifier Null""" 913 | identifier Null"""
913 if type(p[1]) == str: 914 if type(p[1]) == str:
914 p[0] = self.BuildNamed('Typeref', p, 1, p[2]) 915 p[0] = self.BuildNamed('Typeref', p, 1, p[2])
915 else: 916 else:
916 p[1].AddChildren(p[2]) 917 p[1].AddChildren(p[2])
917 p[0] = p[1] 918 p[0] = p[1]
918 919
919 920
920 # [81] Added BYTESTRING, DOMSTRING, OBJECT, DATE, REGEXP 921 # [81] Added StringType, OBJECT, DATE, REGEXP
921 def p_PrimitiveType(self, p): 922 def p_PrimitiveType(self, p):
922 """PrimitiveType : UnsignedIntegerType 923 """PrimitiveType : UnsignedIntegerType
923 | UnrestrictedFloatType 924 | UnrestrictedFloatType
925 | StringType
924 | BOOLEAN 926 | BOOLEAN
925 | BYTE 927 | BYTE
926 | OCTET 928 | OCTET
927 | BYTESTRING
928 | DOMSTRING
929 | OBJECT 929 | OBJECT
930 | DATE 930 | DATE
931 | REGEXP""" 931 | REGEXP"""
932 if type(p[1]) == str: 932 if type(p[1]) == str:
933 p[0] = self.BuildNamed('PrimitiveType', p, 1) 933 p[0] = self.BuildNamed('PrimitiveType', p, 1)
934 else: 934 else:
935 p[0] = p[1] 935 p[0] = p[1]
936 936
937 937
938 # [82] 938 # [82]
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 value = self.BuildAttribute('VALUE', p[4]) 1069 value = self.BuildAttribute('VALUE', p[4])
1070 p[0] = self.BuildNamed('ExtAttribute', p, 1, value) 1070 p[0] = self.BuildNamed('ExtAttribute', p, 1, value)
1071 1071
1072 # [98] 1072 # [98]
1073 def p_ExtendedAttributeNamedArgList(self, p): 1073 def p_ExtendedAttributeNamedArgList(self, p):
1074 """ExtendedAttributeNamedArgList : identifier '=' identifier '(' ArgumentLis t ')'""" 1074 """ExtendedAttributeNamedArgList : identifier '=' identifier '(' ArgumentLis t ')'"""
1075 args = self.BuildProduction('Arguments', p, 4, p[5]) 1075 args = self.BuildProduction('Arguments', p, 4, p[5])
1076 value = self.BuildNamed('Call', p, 3, args) 1076 value = self.BuildNamed('Call', p, 3, args)
1077 p[0] = self.BuildNamed('ExtAttribute', p, 1, value) 1077 p[0] = self.BuildNamed('ExtAttribute', p, 1, value)
1078 1078
1079 # [99]
1080 def p_StringType(self, p):
1081 """StringType : BYTESTRING
1082 | DOMSTRING
1083 | USVSTRING"""
1084 p[0] = self.BuildNamed('StringType', p, 1)
1085
1086 # [100]
1087 def p_RecordType(self, p):
1088 """RecordType : RECORD '<' StringType ',' Type '>'"""
1089 p[0] = self.BuildProduction('Record', p, 2, ListFromConcat(p[3], p[5]))
1090
1091 # [100.1] Error recovery for RecordType.
1092 def p_RecordTypeError(self, p):
1093 """RecordType : RECORD '<' error ',' Type '>'"""
1094 p[0] = self.BuildError(p, 'RecordType')
1095
1079 # 1096 #
1080 # Parser Errors 1097 # Parser Errors
1081 # 1098 #
1082 # p_error is called whenever the parser can not find a pattern match for 1099 # p_error is called whenever the parser can not find a pattern match for
1083 # a set of items from the current state. The p_error function defined here 1100 # a set of items from the current state. The p_error function defined here
1084 # is triggered logging an error, and parsing recovery happens as the 1101 # is triggered logging an error, and parsing recovery happens as the
1085 # p_<type>_error functions defined above are called. This allows the parser 1102 # p_<type>_error functions defined above are called. This allows the parser
1086 # to continue so as to capture more than one error per file. 1103 # to continue so as to capture more than one error per file.
1087 # 1104 #
1088 def p_error(self, t): 1105 def p_error(self, t):
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 self._last_error_lineno = 0 1148 self._last_error_lineno = 0
1132 self._last_error_pos = 0 1149 self._last_error_pos = 0
1133 1150
1134 1151
1135 # 1152 #
1136 # BuildProduction 1153 # BuildProduction
1137 # 1154 #
1138 # Production is the set of items sent to a grammar rule resulting in a new 1155 # Production is the set of items sent to a grammar rule resulting in a new
1139 # item being returned. 1156 # item being returned.
1140 # 1157 #
1158 # cls - The type of item being producted
1141 # p - Is the Yacc production object containing the stack of items 1159 # p - Is the Yacc production object containing the stack of items
1142 # index - Index into the production of the name for the item being produced. 1160 # index - Index into the production of the name for the item being produced.
1143 # cls - The type of item being producted
1144 # childlist - The children of the new item 1161 # childlist - The children of the new item
1145 def BuildProduction(self, cls, p, index, childlist=None): 1162 def BuildProduction(self, cls, p, index, childlist=None):
1146 try: 1163 try:
1147 if not childlist: 1164 if not childlist:
1148 childlist = [] 1165 childlist = []
1149 1166
1150 filename = self.lexer.Lexer().filename 1167 filename = self.lexer.Lexer().filename
1151 lineno = p.lineno(index) 1168 lineno = p.lineno(index)
1152 pos = p.lexpos(index) 1169 pos = p.lexpos(index)
1153 out = IDLNode(cls, filename, lineno, pos, childlist) 1170 out = IDLNode(cls, filename, lineno, pos, childlist)
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 1305
1289 print '\n'.join(ast.Tree(accept_props=['PROD'])) 1306 print '\n'.join(ast.Tree(accept_props=['PROD']))
1290 if errors: 1307 if errors:
1291 print '\nFound %d errors.\n' % errors 1308 print '\nFound %d errors.\n' % errors
1292 1309
1293 return errors 1310 return errors
1294 1311
1295 1312
1296 if __name__ == '__main__': 1313 if __name__ == '__main__':
1297 sys.exit(main(sys.argv[1:])) 1314 sys.exit(main(sys.argv[1:]))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698