| OLD | NEW |
| 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 # |
| 11 # The parser is uses the PLY yacc library to build a set of parsing rules based | 11 # The parser is uses the PLY yacc library to build a set of parsing rules based |
| 12 # on WebIDL. | 12 # on WebIDL. |
| 13 # | 13 # |
| 14 # WebIDL, and WebIDL grammar can be found at: | 14 # WebIDL, and WebIDL grammar can be found at: |
| 15 # http://dev.w3.org/2006/webapi/WebIDL/ | 15 # http://heycam.github.io/webidl/ |
| 16 # PLY can be found at: | 16 # PLY can be found at: |
| 17 # http://www.dabeaz.com/ply/ | 17 # http://www.dabeaz.com/ply/ |
| 18 # | 18 # |
| 19 # The parser generates a tree by recursively matching sets of items against | 19 # The parser generates a tree by recursively matching sets of items against |
| 20 # defined patterns. When a match is made, that set of items is reduced | 20 # defined patterns. When a match is made, that set of items is reduced |
| 21 # to a new item. The new item can provide a match for parent patterns. | 21 # to a new item. The new item can provide a match for parent patterns. |
| 22 # In this way an AST is built (reduced) depth first. | 22 # In this way an AST is built (reduced) depth first. |
| 23 # | 23 # |
| 24 | 24 |
| 25 # | 25 # |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 # separated by the "|". | 137 # separated by the "|". |
| 138 # | 138 # |
| 139 # The function is called with an object 'p' where p[0] is the output object | 139 # The function is called with an object 'p' where p[0] is the output object |
| 140 # and p[n] is the set of inputs for positive values of 'n'. Len(p) can be | 140 # and p[n] is the set of inputs for positive values of 'n'. Len(p) can be |
| 141 # used to distinguish between multiple item sets in the pattern. | 141 # used to distinguish between multiple item sets in the pattern. |
| 142 # | 142 # |
| 143 # For more details on parsing refer to the PLY documentation at | 143 # For more details on parsing refer to the PLY documentation at |
| 144 # http://www.dabeaz.com/ply/ | 144 # http://www.dabeaz.com/ply/ |
| 145 # | 145 # |
| 146 # The parser is based on the WebIDL standard. See: | 146 # The parser is based on the WebIDL standard. See: |
| 147 # http://www.w3.org/TR/WebIDL/#idl-grammar | 147 # http://heycam.github.io/webidl/#idl-grammar |
| 148 # | 148 # |
| 149 # The various productions are annotated so that the WHOLE number greater than | 149 # The various productions are annotated so that the WHOLE number greater than |
| 150 # zero in the comment denotes the matching WebIDL grammar definition. | 150 # zero in the comment denotes the matching WebIDL grammar definition. |
| 151 # | 151 # |
| 152 # Productions with a fractional component in the comment denote additions to | 152 # Productions with a fractional component in the comment denote additions to |
| 153 # the WebIDL spec, such as comments. | 153 # the WebIDL spec, such as comments. |
| 154 # | 154 # |
| 155 | 155 |
| 156 | 156 |
| 157 class IDLParser(object): | 157 class IDLParser(object): |
| (...skipping 18 matching lines...) Expand all Loading... |
| 176 # [0.2] Produce a COMMENT and aggregate sibling comments | 176 # [0.2] Produce a COMMENT and aggregate sibling comments |
| 177 def p_CommentsRest(self, p): | 177 def p_CommentsRest(self, p): |
| 178 """CommentsRest : COMMENT CommentsRest | 178 """CommentsRest : COMMENT CommentsRest |
| 179 | """ | 179 | """ |
| 180 if len(p) > 1: | 180 if len(p) > 1: |
| 181 p[0] = ListFromConcat(self.BuildComment('Comment', p, 1), p[2]) | 181 p[0] = ListFromConcat(self.BuildComment('Comment', p, 1), p[2]) |
| 182 | 182 |
| 183 | 183 |
| 184 # | 184 # |
| 185 #The parser is based on the WebIDL standard. See: | 185 #The parser is based on the WebIDL standard. See: |
| 186 # http://www.w3.org/TR/WebIDL/#idl-grammar | 186 # http://heycam.github.io/webidl/#idl-grammar |
| 187 # | 187 # |
| 188 # [1] | 188 # [1] |
| 189 def p_Definitions(self, p): | 189 def p_Definitions(self, p): |
| 190 """Definitions : ExtendedAttributeList Definition Definitions | 190 """Definitions : ExtendedAttributeList Definition Definitions |
| 191 | """ | 191 | """ |
| 192 if len(p) > 1: | 192 if len(p) > 1: |
| 193 p[2].AddChildren(p[1]) | 193 p[2].AddChildren(p[1]) |
| 194 p[0] = ListFromConcat(p[2], p[3]) | 194 p[0] = ListFromConcat(p[2], p[3]) |
| 195 | 195 |
| 196 # [2] Add INLINE definition | 196 # [2] |
| 197 def p_Definition(self, p): | 197 def p_Definition(self, p): |
| 198 """Definition : CallbackOrInterface | 198 """Definition : CallbackOrInterface |
| 199 | Partial | 199 | Partial |
| 200 | Dictionary | 200 | Dictionary |
| 201 | Exception | 201 | Exception |
| 202 | Enum | 202 | Enum |
| 203 | Typedef | 203 | Typedef |
| 204 | ImplementsStatement""" | 204 | ImplementsStatement""" |
| 205 p[0] = p[1] | 205 p[0] = p[1] |
| 206 | 206 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 222 def p_CallbackRestOrInterface(self, p): | 222 def p_CallbackRestOrInterface(self, p): |
| 223 """CallbackRestOrInterface : CallbackRest | 223 """CallbackRestOrInterface : CallbackRest |
| 224 | Interface""" | 224 | Interface""" |
| 225 p[0] = p[1] | 225 p[0] = p[1] |
| 226 | 226 |
| 227 # [5] | 227 # [5] |
| 228 def p_Interface(self, p): | 228 def p_Interface(self, p): |
| 229 """Interface : INTERFACE identifier Inheritance '{' InterfaceMembers '}' ';'
""" | 229 """Interface : INTERFACE identifier Inheritance '{' InterfaceMembers '}' ';'
""" |
| 230 p[0] = self.BuildNamed('Interface', p, 2, ListFromConcat(p[3], p[5])) | 230 p[0] = self.BuildNamed('Interface', p, 2, ListFromConcat(p[3], p[5])) |
| 231 | 231 |
| 232 # [6] Error recovery for PARTIAL | 232 # [6] |
| 233 def p_Partial(self, p): | 233 def p_Partial(self, p): |
| 234 """Partial : PARTIAL PartialDefinition""" | 234 """Partial : PARTIAL PartialDefinition""" |
| 235 p[2].AddChildren(self.BuildTrue('Partial')) | 235 p[2].AddChildren(self.BuildTrue('Partial')) |
| 236 p[0] = p[2] | 236 p[0] = p[2] |
| 237 | 237 |
| 238 # [6.1] Error recovery for Enums | 238 # [6.1] Error recovery for Partial |
| 239 def p_PartialError(self, p): | 239 def p_PartialError(self, p): |
| 240 """Partial : PARTIAL error""" | 240 """Partial : PARTIAL error""" |
| 241 p[0] = self.BuildError(p, 'Partial') | 241 p[0] = self.BuildError(p, 'Partial') |
| 242 | 242 |
| 243 # [7] | 243 # [7] |
| 244 def p_PartialDefinition(self, p): | 244 def p_PartialDefinition(self, p): |
| 245 """PartialDefinition : PartialDictionary | 245 """PartialDefinition : PartialDictionary |
| 246 | PartialInterface""" | 246 | PartialInterface""" |
| 247 p[0] = p[1] | 247 p[0] = p[1] |
| 248 | 248 |
| 249 # [8] | 249 # [8] |
| 250 def p_PartialInterface(self, p): | 250 def p_PartialInterface(self, p): |
| 251 """PartialInterface : INTERFACE identifier '{' InterfaceMembers '}' ';'""" | 251 """PartialInterface : INTERFACE identifier '{' InterfaceMembers '}' ';'""" |
| 252 p[0] = self.BuildNamed('Interface', p, 2, p[4]) | 252 p[0] = self.BuildNamed('Interface', p, 2, p[4]) |
| 253 | 253 |
| 254 # [9] | 254 # [9] |
| 255 def p_InterfaceMembers(self, p): | 255 def p_InterfaceMembers(self, p): |
| 256 """InterfaceMembers : ExtendedAttributeList InterfaceMember InterfaceMembers | 256 """InterfaceMembers : ExtendedAttributeList InterfaceMember InterfaceMembers |
| 257 |""" | 257 |""" |
| 258 if len(p) > 1: | 258 if len(p) > 1: |
| 259 p[2].AddChildren(p[1]) | 259 p[2].AddChildren(p[1]) |
| 260 p[0] = ListFromConcat(p[2], p[3]) | 260 p[0] = ListFromConcat(p[2], p[3]) |
| 261 | 261 |
| 262 # [10] | 262 # [10] |
| 263 def p_InterfaceMember(self, p): | 263 def p_InterfaceMember(self, p): |
| 264 """InterfaceMember : Const | 264 """InterfaceMember : Const |
| 265 | AttributeOrOperation""" | 265 | AttributeOrOperationOrIterator""" |
| 266 p[0] = p[1] | 266 p[0] = p[1] |
| 267 | 267 |
| 268 # [11] | 268 # [11] |
| 269 def p_Dictionary(self, p): | 269 def p_Dictionary(self, p): |
| 270 """Dictionary : DICTIONARY identifier Inheritance '{' DictionaryMembers '}'
';'""" | 270 """Dictionary : DICTIONARY identifier Inheritance '{' DictionaryMembers '}'
';'""" |
| 271 p[0] = self.BuildNamed('Dictionary', p, 2, ListFromConcat(p[3], p[5])) | 271 p[0] = self.BuildNamed('Dictionary', p, 2, ListFromConcat(p[3], p[5])) |
| 272 | 272 |
| 273 # [11.1] Error recovery for regular Dictionary | 273 # [11.1] Error recovery for regular Dictionary |
| 274 def p_DictionaryError(self, p): | 274 def p_DictionaryError(self, p): |
| 275 """Dictionary : DICTIONARY error ';'""" | 275 """Dictionary : DICTIONARY error ';'""" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 """Enum : ENUM identifier '{' EnumValueList '}' ';'""" | 346 """Enum : ENUM identifier '{' EnumValueList '}' ';'""" |
| 347 p[0] = self.BuildNamed('Enum', p, 2, p[4]) | 347 p[0] = self.BuildNamed('Enum', p, 2, p[4]) |
| 348 | 348 |
| 349 # [20.1] Error recovery for Enums | 349 # [20.1] Error recovery for Enums |
| 350 def p_EnumError(self, p): | 350 def p_EnumError(self, p): |
| 351 """Enum : ENUM error ';'""" | 351 """Enum : ENUM error ';'""" |
| 352 p[0] = self.BuildError(p, 'Enum') | 352 p[0] = self.BuildError(p, 'Enum') |
| 353 | 353 |
| 354 # [21] | 354 # [21] |
| 355 def p_EnumValueList(self, p): | 355 def p_EnumValueList(self, p): |
| 356 """EnumValueList : ExtendedAttributeList string EnumValues""" | 356 """EnumValueList : ExtendedAttributeList string EnumValueListComma""" |
| 357 enum = self.BuildNamed('EnumItem', p, 2, p[1]) | 357 enum = self.BuildNamed('EnumItem', p, 2, p[1]) |
| 358 p[0] = ListFromConcat(enum, p[3]) | 358 p[0] = ListFromConcat(enum, p[3]) |
| 359 | 359 |
| 360 # [22] | 360 # [22] |
| 361 def p_EnumValues(self, p): | 361 def p_EnumValueListComma(self, p): |
| 362 """EnumValues : ',' ExtendedAttributeList string EnumValues | 362 """EnumValueListComma : ',' EnumValueListString |
| 363 |""" | 363 |""" |
| 364 if len(p) > 1: | 364 if len(p) > 1: |
| 365 enum = self.BuildNamed('EnumItem', p, 3, p[2]) | 365 p[0] = p[2] |
| 366 p[0] = ListFromConcat(enum, p[4]) | |
| 367 | 366 |
| 368 # [23] | 367 # [23] |
| 368 def p_EnumValueListString(self, p): |
| 369 """EnumValueListString : ExtendedAttributeList string EnumValueListComma |
| 370 |""" |
| 371 if len(p) > 1: |
| 372 enum = self.BuildNamed('EnumItem', p, 2, p[1]) |
| 373 p[0] = ListFromConcat(enum, p[3]) |
| 374 |
| 375 # [24] |
| 369 def p_CallbackRest(self, p): | 376 def p_CallbackRest(self, p): |
| 370 """CallbackRest : identifier '=' ReturnType '(' ArgumentList ')' ';'""" | 377 """CallbackRest : identifier '=' ReturnType '(' ArgumentList ')' ';'""" |
| 371 arguments = self.BuildProduction('Arguments', p, 4, p[5]) | 378 arguments = self.BuildProduction('Arguments', p, 4, p[5]) |
| 372 p[0] = self.BuildNamed('Callback', p, 1, ListFromConcat(p[3], arguments)) | 379 p[0] = self.BuildNamed('Callback', p, 1, ListFromConcat(p[3], arguments)) |
| 373 | 380 |
| 374 # [24] | 381 # [25] |
| 375 def p_Typedef(self, p): | 382 def p_Typedef(self, p): |
| 376 """Typedef : TYPEDEF ExtendedAttributeListNoComments Type identifier ';'""" | 383 """Typedef : TYPEDEF ExtendedAttributeListNoComments Type identifier ';'""" |
| 377 p[0] = self.BuildNamed('Typedef', p, 4, ListFromConcat(p[2], p[3])) | 384 p[0] = self.BuildNamed('Typedef', p, 4, ListFromConcat(p[2], p[3])) |
| 378 | 385 |
| 379 # [24.1] Error recovery for Typedefs | 386 # [25.1] Error recovery for Typedefs |
| 380 def p_TypedefError(self, p): | 387 def p_TypedefError(self, p): |
| 381 """Typedef : TYPEDEF error ';'""" | 388 """Typedef : TYPEDEF error ';'""" |
| 382 p[0] = self.BuildError(p, 'Typedef') | 389 p[0] = self.BuildError(p, 'Typedef') |
| 383 | 390 |
| 384 # [25] | 391 # [26] |
| 385 def p_ImplementsStatement(self, p): | 392 def p_ImplementsStatement(self, p): |
| 386 """ImplementsStatement : identifier IMPLEMENTS identifier ';'""" | 393 """ImplementsStatement : identifier IMPLEMENTS identifier ';'""" |
| 387 name = self.BuildAttribute('REFERENCE', p[3]) | 394 name = self.BuildAttribute('REFERENCE', p[3]) |
| 388 p[0] = self.BuildNamed('Implements', p, 1, name) | 395 p[0] = self.BuildNamed('Implements', p, 1, name) |
| 389 | 396 |
| 390 # [26] | 397 # [27] |
| 391 def p_Const(self, p): | 398 def p_Const(self, p): |
| 392 """Const : CONST ConstType identifier '=' ConstValue ';'""" | 399 """Const : CONST ConstType identifier '=' ConstValue ';'""" |
| 393 value = self.BuildProduction('Value', p, 5, p[5]) | 400 value = self.BuildProduction('Value', p, 5, p[5]) |
| 394 p[0] = self.BuildNamed('Const', p, 3, ListFromConcat(p[2], value)) | 401 p[0] = self.BuildNamed('Const', p, 3, ListFromConcat(p[2], value)) |
| 395 | 402 |
| 396 # [27] | 403 # [28] |
| 397 def p_ConstValue(self, p): | 404 def p_ConstValue(self, p): |
| 398 """ConstValue : BooleanLiteral | 405 """ConstValue : BooleanLiteral |
| 399 | FloatLiteral | 406 | FloatLiteral |
| 400 | integer | 407 | integer |
| 401 | null""" | 408 | null""" |
| 402 if type(p[1]) == str: | 409 if type(p[1]) == str: |
| 403 p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'integer'), | 410 p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'integer'), |
| 404 self.BuildAttribute('NAME', p[1])) | 411 self.BuildAttribute('NAME', p[1])) |
| 405 else: | 412 else: |
| 406 p[0] = p[1] | 413 p[0] = p[1] |
| 407 | 414 |
| 408 # [27.1] Add definition for NULL | 415 # [28.1] Add definition for NULL |
| 409 def p_null(self, p): | 416 def p_null(self, p): |
| 410 """null : NULL""" | 417 """null : NULL""" |
| 411 p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'NULL'), | 418 p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'NULL'), |
| 412 self.BuildAttribute('NAME', 'NULL')) | 419 self.BuildAttribute('NAME', 'NULL')) |
| 413 | 420 |
| 414 # [28] | 421 # [29] |
| 415 def p_BooleanLiteral(self, p): | 422 def p_BooleanLiteral(self, p): |
| 416 """BooleanLiteral : TRUE | 423 """BooleanLiteral : TRUE |
| 417 | FALSE""" | 424 | FALSE""" |
| 418 value = self.BuildAttribute('VALUE', Boolean(p[1] == 'true')) | 425 value = self.BuildAttribute('VALUE', Boolean(p[1] == 'true')) |
| 419 p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'boolean'), value) | 426 p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'boolean'), value) |
| 420 | 427 |
| 421 # [29] | 428 # [30] |
| 422 def p_FloatLiteral(self, p): | 429 def p_FloatLiteral(self, p): |
| 423 """FloatLiteral : float | 430 """FloatLiteral : float |
| 424 | '-' INFINITY | 431 | '-' INFINITY |
| 425 | INFINITY | 432 | INFINITY |
| 426 | NAN """ | 433 | NAN """ |
| 427 if len(p) > 2: | 434 if len(p) > 2: |
| 428 val = '-Infinity' | 435 val = '-Infinity' |
| 429 else: | 436 else: |
| 430 val = p[1] | 437 val = p[1] |
| 431 p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'float'), | 438 p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'float'), |
| 432 self.BuildAttribute('VALUE', val)) | 439 self.BuildAttribute('VALUE', val)) |
| 433 | 440 |
| 434 # [30] | 441 # [31] Removed unsupported: Serializer, Stringifier |
| 435 def p_AttributeOrOperation(self, p): | 442 def p_AttributeOrOperationOrIterator(self, p): |
| 436 """AttributeOrOperation : STRINGIFIER StringifierAttributeOrOperation | 443 """AttributeOrOperationOrIterator : StaticMember |
| 437 | StaticAttribute | 444 | Attribute |
| 438 | Attribute | 445 | OperationOrIterator""" |
| 439 | Operation""" | 446 p[0] = p[1] |
| 440 if len(p) > 2: | |
| 441 p[0] = p[2] | |
| 442 else: | |
| 443 p[0] = p[1] | |
| 444 | 447 |
| 445 # [31] | 448 # [32-37] NOT IMPLEMENTED (Serializer) |
| 446 def p_StringifierAttributeOrOperation(self, p): | 449 # [38-39] FIXME: NOT IMPLEMENTED (Stringifier) http://crbug.com/306606 |
| 447 """StringifierAttributeOrOperation : Attribute | |
| 448 | OperationRest | |
| 449 | ';'""" | |
| 450 if p[1] == ';': | |
| 451 p[0] = self.BuildAttribute('STRINGIFIER', Boolean(True)) | |
| 452 else: | |
| 453 p[0] = ListFromConcat(self.BuildAttribute('STRINGIFIER', p[1]), p[1]) | |
| 454 | 450 |
| 455 # [31.1] FIXME: temporary production as part of moving |static| into | 451 # [40] |
| 456 # base parser | 452 def p_StaticMember(self, p): |
| 457 def p_StaticAttribute(self, p): | 453 """StaticMember : STATIC StaticMemberRest""" |
| 458 """StaticAttribute : STATIC Attribute""" | |
| 459 p[2].AddChildren(self.BuildTrue('STATIC')) | 454 p[2].AddChildren(self.BuildTrue('STATIC')) |
| 460 p[0] = p[2] | 455 p[0] = p[2] |
| 461 | 456 |
| 462 # [32] | 457 # [41] |
| 458 def p_StaticMemberRest(self, p): |
| 459 """StaticMemberRest : AttributeRest |
| 460 | ReturnType OperationRest""" |
| 461 if len(p) == 2: |
| 462 p[0] = p[1] |
| 463 else: |
| 464 p[2].AddChildren(p[1]) |
| 465 p[0] = p[2] |
| 466 |
| 467 # [42] |
| 463 def p_Attribute(self, p): | 468 def p_Attribute(self, p): |
| 464 """Attribute : Inherit ReadOnly ATTRIBUTE Type identifier ';'""" | 469 """Attribute : Inherit AttributeRest""" |
| 465 p[0] = self.BuildNamed('Attribute', p, 5, | 470 p[2].AddChildren(ListFromConcat(p[1])) |
| 466 ListFromConcat(p[1], p[2], p[4])) | 471 p[0] = p[2] |
| 467 | 472 |
| 468 # [33] | 473 # [43] |
| 474 def p_AttributeRest(self, p): |
| 475 """AttributeRest : ReadOnly ATTRIBUTE Type identifier ';'""" |
| 476 p[0] = self.BuildNamed('Attribute', p, 4, |
| 477 ListFromConcat(p[1], p[3])) |
| 478 |
| 479 # [44] |
| 469 def p_Inherit(self, p): | 480 def p_Inherit(self, p): |
| 470 """Inherit : INHERIT | 481 """Inherit : INHERIT |
| 471 |""" | 482 |""" |
| 472 if len(p) > 1: | 483 if len(p) > 1: |
| 473 p[0] = self.BuildTrue('INHERIT') | 484 p[0] = self.BuildTrue('INHERIT') |
| 474 | 485 |
| 475 # [34] | 486 # [45] |
| 476 def p_ReadOnly(self, p): | 487 def p_ReadOnly(self, p): |
| 477 """ReadOnly : READONLY | 488 """ReadOnly : READONLY |
| 478 |""" | 489 |""" |
| 479 if len(p) > 1: | 490 if len(p) > 1: |
| 480 p[0] = self.BuildTrue('READONLY') | 491 p[0] = self.BuildTrue('READONLY') |
| 481 | 492 |
| 482 # [35] | 493 # [46] |
| 483 def p_Operation(self, p): | 494 def p_OperationOrIterator(self, p): |
| 484 """Operation : Qualifiers OperationRest""" | 495 """OperationOrIterator : ReturnType OperationOrIteratorRest |
| 485 p[2].AddChildren(p[1]) | 496 | SpecialOperation""" |
| 486 p[0] = p[2] | 497 if len(p) == 3: |
| 487 | 498 p[2].AddChildren(p[1]) |
| 488 # [36] | 499 p[0] = p[2] |
| 489 def p_Qualifiers(self, p): | |
| 490 """Qualifiers : STATIC | |
| 491 | Specials""" | |
| 492 if p[1] == 'static': | |
| 493 p[0] = self.BuildTrue('STATIC') | |
| 494 else: | 500 else: |
| 495 p[0] = p[1] | 501 p[0] = p[1] |
| 496 | 502 |
| 497 # [37] | 503 # [47] |
| 504 def p_SpecialOperation(self, p): |
| 505 """SpecialOperation : Special Specials ReturnType OperationRest""" |
| 506 p[4].AddChildren(ListFromConcat(p[1], p[2], p[3])) |
| 507 p[0] = p[4] |
| 508 |
| 509 # [48] |
| 498 def p_Specials(self, p): | 510 def p_Specials(self, p): |
| 499 """Specials : Special Specials | 511 """Specials : Special Specials |
| 500 | """ | 512 | """ |
| 501 if len(p) > 1: | 513 if len(p) > 1: |
| 502 p[0] = ListFromConcat(p[1], p[2]) | 514 p[0] = ListFromConcat(p[1], p[2]) |
| 503 | 515 |
| 504 # [38] | 516 # [49] |
| 505 def p_Special(self, p): | 517 def p_Special(self, p): |
| 506 """Special : GETTER | 518 """Special : GETTER |
| 507 | SETTER | 519 | SETTER |
| 508 | CREATOR | 520 | CREATOR |
| 509 | DELETER | 521 | DELETER |
| 510 | LEGACYCALLER""" | 522 | LEGACYCALLER""" |
| 511 p[0] = self.BuildTrue(p[1].upper()) | 523 p[0] = self.BuildTrue(p[1].upper()) |
| 512 | 524 |
| 525 # [50] Removed unsupported: IteratorRest |
| 526 def p_OperationOrIteratorRest(self, p): |
| 527 """OperationOrIteratorRest : OperationRest""" |
| 528 p[0] = p[1] |
| 513 | 529 |
| 514 # [39] | 530 # [51-53] NOT IMPLEMENTED (IteratorRest) |
| 531 |
| 532 # [54] |
| 515 def p_OperationRest(self, p): | 533 def p_OperationRest(self, p): |
| 516 """OperationRest : ReturnType OptionalIdentifier '(' ArgumentList ')' ';'""" | 534 """OperationRest : OptionalIdentifier '(' ArgumentList ')' ';'""" |
| 517 arguments = self.BuildProduction('Arguments', p, 3, p[4]) | 535 arguments = self.BuildProduction('Arguments', p, 2, p[3]) |
| 518 p[0] = self.BuildNamed('Operation', p, 2, ListFromConcat(p[1], arguments)) | 536 p[0] = self.BuildNamed('Operation', p, 1, arguments) |
| 519 | 537 |
| 520 # [40] | 538 # [55] |
| 521 def p_OptionalIdentifier(self, p): | 539 def p_OptionalIdentifier(self, p): |
| 522 """OptionalIdentifier : identifier | 540 """OptionalIdentifier : identifier |
| 523 |""" | 541 |""" |
| 524 if len(p) > 1: | 542 if len(p) > 1: |
| 525 p[0] = p[1] | 543 p[0] = p[1] |
| 526 else: | 544 else: |
| 527 p[0] = '_unnamed_' | 545 p[0] = '_unnamed_' |
| 528 | 546 |
| 529 # [41] | 547 # [56] |
| 530 def p_ArgumentList(self, p): | 548 def p_ArgumentList(self, p): |
| 531 """ArgumentList : Argument Arguments | 549 """ArgumentList : Argument Arguments |
| 532 |""" | 550 |""" |
| 533 if len(p) > 1: | 551 if len(p) > 1: |
| 534 p[0] = ListFromConcat(p[1], p[2]) | 552 p[0] = ListFromConcat(p[1], p[2]) |
| 535 | 553 |
| 536 # [41.1] ArgumentList error recovery | 554 # [56.1] ArgumentList error recovery |
| 537 def p_ArgumentListError(self, p): | 555 def p_ArgumentListError(self, p): |
| 538 """ArgumentList : error """ | 556 """ArgumentList : error """ |
| 539 p[0] = self.BuildError(p, 'ArgumentList') | 557 p[0] = self.BuildError(p, 'ArgumentList') |
| 540 | 558 |
| 541 # [42] | 559 # [57] |
| 542 def p_Arguments(self, p): | 560 def p_Arguments(self, p): |
| 543 """Arguments : ',' Argument Arguments | 561 """Arguments : ',' Argument Arguments |
| 544 |""" | 562 |""" |
| 545 if len(p) > 1: | 563 if len(p) > 1: |
| 546 p[0] = ListFromConcat(p[2], p[3]) | 564 p[0] = ListFromConcat(p[2], p[3]) |
| 547 | 565 |
| 548 # [43] | 566 # [58] |
| 549 def p_Argument(self, p): | 567 def p_Argument(self, p): |
| 550 """Argument : ExtendedAttributeList OptionalOrRequiredArgument""" | 568 """Argument : ExtendedAttributeList OptionalOrRequiredArgument""" |
| 551 p[2].AddChildren(p[1]) | 569 p[2].AddChildren(p[1]) |
| 552 p[0] = p[2] | 570 p[0] = p[2] |
| 553 | 571 |
| 554 | 572 # [59] |
| 555 # [44] | |
| 556 def p_OptionalOrRequiredArgument(self, p): | 573 def p_OptionalOrRequiredArgument(self, p): |
| 557 """OptionalOrRequiredArgument : OPTIONAL Type ArgumentName Default | 574 """OptionalOrRequiredArgument : OPTIONAL Type ArgumentName Default |
| 558 | Type Ellipsis ArgumentName""" | 575 | Type Ellipsis ArgumentName""" |
| 559 if len(p) > 4: | 576 if len(p) > 4: |
| 560 arg = self.BuildNamed('Argument', p, 3, ListFromConcat(p[2], p[4])) | 577 arg = self.BuildNamed('Argument', p, 3, ListFromConcat(p[2], p[4])) |
| 561 arg.AddChildren(self.BuildTrue('OPTIONAL')) | 578 arg.AddChildren(self.BuildTrue('OPTIONAL')) |
| 562 else: | 579 else: |
| 563 arg = self.BuildNamed('Argument', p, 3, ListFromConcat(p[1], p[2])) | 580 arg = self.BuildNamed('Argument', p, 3, ListFromConcat(p[1], p[2])) |
| 564 p[0] = arg | 581 p[0] = arg |
| 565 | 582 |
| 566 # [45] | 583 # [60] |
| 567 def p_ArgumentName(self, p): | 584 def p_ArgumentName(self, p): |
| 568 """ArgumentName : ArgumentNameKeyword | 585 """ArgumentName : ArgumentNameKeyword |
| 569 | identifier""" | 586 | identifier""" |
| 570 p[0] = p[1] | 587 p[0] = p[1] |
| 571 | 588 |
| 572 # [46] | 589 # [61] |
| 573 def p_Ellipsis(self, p): | 590 def p_Ellipsis(self, p): |
| 574 """Ellipsis : ELLIPSIS | 591 """Ellipsis : ELLIPSIS |
| 575 |""" | 592 |""" |
| 576 if len(p) > 1: | 593 if len(p) > 1: |
| 577 p[0] = self.BuildNamed('Argument', p, 1) | 594 p[0] = self.BuildNamed('Argument', p, 1) |
| 578 p[0].AddChildren(self.BuildTrue('ELLIPSIS')) | 595 p[0].AddChildren(self.BuildTrue('ELLIPSIS')) |
| 579 | 596 |
| 580 # [47] | 597 # [62] |
| 581 def p_ExceptionMember(self, p): | 598 def p_ExceptionMember(self, p): |
| 582 """ExceptionMember : Const | 599 """ExceptionMember : Const |
| 583 | ExceptionField""" | 600 | ExceptionField""" |
| 584 p[0] = p[1] | 601 p[0] = p[1] |
| 585 | 602 |
| 586 # [48] | 603 # [63] |
| 587 def p_ExceptionField(self, p): | 604 def p_ExceptionField(self, p): |
| 588 """ExceptionField : Type identifier ';'""" | 605 """ExceptionField : Type identifier ';'""" |
| 589 p[0] = self.BuildNamed('ExceptionField', p, 2, p[1]) | 606 p[0] = self.BuildNamed('ExceptionField', p, 2, p[1]) |
| 590 | 607 |
| 591 # [48.1] Error recovery for ExceptionMembers | 608 # [63.1] Error recovery for ExceptionMembers |
| 592 def p_ExceptionFieldError(self, p): | 609 def p_ExceptionFieldError(self, p): |
| 593 """ExceptionField : error""" | 610 """ExceptionField : error""" |
| 594 p[0] = self.BuildError(p, 'ExceptionField') | 611 p[0] = self.BuildError(p, 'ExceptionField') |
| 595 | 612 |
| 596 # [49] No comment version for mid statement attributes. | 613 # [64] No comment version for mid statement attributes. |
| 597 def p_ExtendedAttributeListNoComments(self, p): | 614 def p_ExtendedAttributeListNoComments(self, p): |
| 598 """ExtendedAttributeListNoComments : '[' ExtendedAttribute ExtendedAttribute
s ']' | 615 """ExtendedAttributeListNoComments : '[' ExtendedAttribute ExtendedAttribute
s ']' |
| 599 | """ | 616 | """ |
| 600 if len(p) > 2: | 617 if len(p) > 2: |
| 601 items = ListFromConcat(p[2], p[3]) | 618 items = ListFromConcat(p[2], p[3]) |
| 602 p[0] = self.BuildProduction('ExtAttributes', p, 1, items) | 619 p[0] = self.BuildProduction('ExtAttributes', p, 1, items) |
| 603 | 620 |
| 604 # [49.1] Add optional comment field for start of statements. | 621 # [64.1] Add optional comment field for start of statements. |
| 605 def p_ExtendedAttributeList(self, p): | 622 def p_ExtendedAttributeList(self, p): |
| 606 """ExtendedAttributeList : Comments '[' ExtendedAttribute ExtendedAttributes
']' | 623 """ExtendedAttributeList : Comments '[' ExtendedAttribute ExtendedAttributes
']' |
| 607 | Comments """ | 624 | Comments """ |
| 608 if len(p) > 2: | 625 if len(p) > 2: |
| 609 items = ListFromConcat(p[3], p[4]) | 626 items = ListFromConcat(p[3], p[4]) |
| 610 attribs = self.BuildProduction('ExtAttributes', p, 2, items) | 627 attribs = self.BuildProduction('ExtAttributes', p, 2, items) |
| 611 p[0] = ListFromConcat(p[1], attribs) | 628 p[0] = ListFromConcat(p[1], attribs) |
| 612 else: | 629 else: |
| 613 p[0] = p[1] | 630 p[0] = p[1] |
| 614 | 631 |
| 615 # [50] | 632 # [65] |
| 616 def p_ExtendedAttributes(self, p): | 633 def p_ExtendedAttributes(self, p): |
| 617 """ExtendedAttributes : ',' ExtendedAttribute ExtendedAttributes | 634 """ExtendedAttributes : ',' ExtendedAttribute ExtendedAttributes |
| 618 |""" | 635 |""" |
| 619 if len(p) > 1: | 636 if len(p) > 1: |
| 620 p[0] = ListFromConcat(p[2], p[3]) | 637 p[0] = ListFromConcat(p[2], p[3]) |
| 621 | 638 |
| 622 # We only support: | 639 # We only support: |
| 623 # [ identifier ] | 640 # [ identifier ] |
| 624 # [ identifier = identifier ] | 641 # [ identifier = identifier ] |
| 625 # [ identifier ( ArgumentList )] | 642 # [ identifier ( ArgumentList )] |
| 626 # [ identifier = identifier ( ArgumentList )] | 643 # [ identifier = identifier ( ArgumentList )] |
| 627 # [51] map directly to 74-77 | 644 # [66] map directly to [91-93, 95] |
| 628 # [52-54, 56] are unsupported | 645 # [67-69, 71] are unsupported |
| 629 def p_ExtendedAttribute(self, p): | 646 def p_ExtendedAttribute(self, p): |
| 630 """ExtendedAttribute : ExtendedAttributeNoArgs | 647 """ExtendedAttribute : ExtendedAttributeNoArgs |
| 631 | ExtendedAttributeArgList | 648 | ExtendedAttributeArgList |
| 632 | ExtendedAttributeIdent | 649 | ExtendedAttributeIdent |
| 633 | ExtendedAttributeNamedArgList""" | 650 | ExtendedAttributeNamedArgList""" |
| 634 p[0] = p[1] | 651 p[0] = p[1] |
| 635 | 652 |
| 636 # [55] | 653 # [70] |
| 637 def p_ArgumentNameKeyword(self, p): | 654 def p_ArgumentNameKeyword(self, p): |
| 638 """ArgumentNameKeyword : ATTRIBUTE | 655 """ArgumentNameKeyword : ATTRIBUTE |
| 639 | CALLBACK | 656 | CALLBACK |
| 640 | CONST | 657 | CONST |
| 641 | CREATOR | 658 | CREATOR |
| 642 | DELETER | 659 | DELETER |
| 643 | DICTIONARY | 660 | DICTIONARY |
| 644 | ENUM | 661 | ENUM |
| 645 | EXCEPTION | 662 | EXCEPTION |
| 646 | GETTER | 663 | GETTER |
| 647 | IMPLEMENTS | 664 | IMPLEMENTS |
| 648 | INHERIT | 665 | INHERIT |
| 649 | LEGACYCALLER | 666 | LEGACYCALLER |
| 650 | PARTIAL | 667 | PARTIAL |
| 668 | SERIALIZER |
| 651 | SETTER | 669 | SETTER |
| 652 | STATIC | 670 | STATIC |
| 653 | STRINGIFIER | 671 | STRINGIFIER |
| 654 | TYPEDEF | 672 | TYPEDEF |
| 655 | UNRESTRICTED""" | 673 | UNRESTRICTED""" |
| 656 p[0] = p[1] | 674 p[0] = p[1] |
| 657 | 675 |
| 658 # [57] | 676 # [72] |
| 659 def p_Type(self, p): | 677 def p_Type(self, p): |
| 660 """Type : SingleType | 678 """Type : SingleType |
| 661 | UnionType TypeSuffix""" | 679 | UnionType TypeSuffix""" |
| 662 if len(p) == 2: | 680 if len(p) == 2: |
| 663 p[0] = self.BuildProduction('Type', p, 1, p[1]) | 681 p[0] = self.BuildProduction('Type', p, 1, p[1]) |
| 664 else: | 682 else: |
| 665 p[0] = self.BuildProduction('Type', p, 1, ListFromConcat(p[1], p[2])) | 683 p[0] = self.BuildProduction('Type', p, 1, ListFromConcat(p[1], p[2])) |
| 666 | 684 |
| 667 # [58] | 685 # [73] |
| 668 def p_SingleType(self, p): | 686 def p_SingleType(self, p): |
| 669 """SingleType : NonAnyType | 687 """SingleType : NonAnyType |
| 670 | ANY TypeSuffixStartingWithArray""" | 688 | ANY TypeSuffixStartingWithArray""" |
| 671 if len(p) == 2: | 689 if len(p) == 2: |
| 672 p[0] = p[1] | 690 p[0] = p[1] |
| 673 else: | 691 else: |
| 674 p[0] = ListFromConcat(self.BuildProduction('Any', p, 1), p[2]) | 692 p[0] = ListFromConcat(self.BuildProduction('Any', p, 1), p[2]) |
| 675 | 693 |
| 676 # [59] | 694 # [74] |
| 677 def p_UnionType(self, p): | 695 def p_UnionType(self, p): |
| 678 """UnionType : '(' UnionMemberType OR UnionMemberType UnionMemberTypes ')'""
" | 696 """UnionType : '(' UnionMemberType OR UnionMemberType UnionMemberTypes ')'""
" |
| 679 | 697 |
| 680 # [60] | 698 # [75] |
| 681 def p_UnionMemberType(self, p): | 699 def p_UnionMemberType(self, p): |
| 682 """UnionMemberType : NonAnyType | 700 """UnionMemberType : NonAnyType |
| 683 | UnionType TypeSuffix | 701 | UnionType TypeSuffix |
| 684 | ANY '[' ']' TypeSuffix""" | 702 | ANY '[' ']' TypeSuffix""" |
| 685 # [61] | 703 # [76] |
| 686 def p_UnionMemberTypes(self, p): | 704 def p_UnionMemberTypes(self, p): |
| 687 """UnionMemberTypes : OR UnionMemberType UnionMemberTypes | 705 """UnionMemberTypes : OR UnionMemberType UnionMemberTypes |
| 688 |""" | 706 |""" |
| 689 | 707 |
| 690 # [62] Moved DATE, DOMSTRING, OBJECT to PrimitiveType | 708 # [77] Moved BYTESTRING, DOMSTRING, OBJECT, DATE, REGEXP to PrimitiveType |
| 709 # Moving all built-in types into PrimitiveType makes it easier to |
| 710 # differentiate between them and 'identifier', since p[1] would be a string in |
| 711 # both cases. |
| 691 def p_NonAnyType(self, p): | 712 def p_NonAnyType(self, p): |
| 692 """NonAnyType : PrimitiveType TypeSuffix | 713 """NonAnyType : PrimitiveType TypeSuffix |
| 693 | identifier TypeSuffix | 714 | identifier TypeSuffix |
| 694 | SEQUENCE '<' Type '>' Null""" | 715 | SEQUENCE '<' Type '>' Null""" |
| 695 if len(p) == 3: | 716 if len(p) == 3: |
| 696 if type(p[1]) == str: | 717 if type(p[1]) == str: |
| 697 typeref = self.BuildNamed('Typeref', p, 1) | 718 typeref = self.BuildNamed('Typeref', p, 1) |
| 698 else: | 719 else: |
| 699 typeref = p[1] | 720 typeref = p[1] |
| 700 p[0] = ListFromConcat(typeref, p[2]) | 721 p[0] = ListFromConcat(typeref, p[2]) |
| 701 | 722 |
| 702 if len(p) == 6: | 723 if len(p) == 6: |
| 703 p[0] = self.BuildProduction('Sequence', p, 1, ListFromConcat(p[3], p[5])) | 724 p[0] = self.BuildProduction('Sequence', p, 1, ListFromConcat(p[3], p[5])) |
| 704 | 725 |
| 705 | 726 |
| 706 # [63] | 727 # [78] |
| 707 def p_ConstType(self, p): | 728 def p_ConstType(self, p): |
| 708 """ConstType : PrimitiveType Null | 729 """ConstType : PrimitiveType Null |
| 709 | identifier Null""" | 730 | identifier Null""" |
| 710 if type(p[1]) == str: | 731 if type(p[1]) == str: |
| 711 p[0] = self.BuildNamed('Typeref', p, 1, p[2]) | 732 p[0] = self.BuildNamed('Typeref', p, 1, p[2]) |
| 712 else: | 733 else: |
| 713 p[1].AddChildren(p[2]) | 734 p[1].AddChildren(p[2]) |
| 714 p[0] = p[1] | 735 p[0] = p[1] |
| 715 | 736 |
| 716 | 737 |
| 717 # [64] | 738 # [79] Added BYTESTRING, DOMSTRING, OBJECT, DATE, REGEXP |
| 718 def p_PrimitiveType(self, p): | 739 def p_PrimitiveType(self, p): |
| 719 """PrimitiveType : UnsignedIntegerType | 740 """PrimitiveType : UnsignedIntegerType |
| 720 | UnrestrictedFloatType | 741 | UnrestrictedFloatType |
| 721 | BOOLEAN | 742 | BOOLEAN |
| 722 | BYTE | 743 | BYTE |
| 723 | OCTET | 744 | OCTET |
| 745 | BYTESTRING |
| 724 | DOMSTRING | 746 | DOMSTRING |
| 747 | OBJECT |
| 725 | DATE | 748 | DATE |
| 726 | OBJECT""" | 749 | REGEXP""" |
| 727 if type(p[1]) == str: | 750 if type(p[1]) == str: |
| 728 p[0] = self.BuildNamed('PrimitiveType', p, 1) | 751 p[0] = self.BuildNamed('PrimitiveType', p, 1) |
| 729 else: | 752 else: |
| 730 p[0] = p[1] | 753 p[0] = p[1] |
| 731 | 754 |
| 732 | 755 |
| 733 # [65] | 756 # [80] |
| 734 def p_UnrestrictedFloatType(self, p): | 757 def p_UnrestrictedFloatType(self, p): |
| 735 """UnrestrictedFloatType : UNRESTRICTED FloatType | 758 """UnrestrictedFloatType : UNRESTRICTED FloatType |
| 736 | FloatType""" | 759 | FloatType""" |
| 737 if len(p) == 2: | 760 if len(p) == 2: |
| 738 typeref = self.BuildNamed('PrimitiveType', p, 1) | 761 typeref = self.BuildNamed('PrimitiveType', p, 1) |
| 739 else: | 762 else: |
| 740 typeref = self.BuildNamed('PrimitiveType', p, 2) | 763 typeref = self.BuildNamed('PrimitiveType', p, 2) |
| 741 typeref.AddChildren(self.BuildTrue('UNRESTRICTED')) | 764 typeref.AddChildren(self.BuildTrue('UNRESTRICTED')) |
| 742 p[0] = typeref | 765 p[0] = typeref |
| 743 | 766 |
| 744 | 767 |
| 745 # [66] | 768 # [81] |
| 746 def p_FloatType(self, p): | 769 def p_FloatType(self, p): |
| 747 """FloatType : FLOAT | 770 """FloatType : FLOAT |
| 748 | DOUBLE""" | 771 | DOUBLE""" |
| 749 p[0] = p[1] | 772 p[0] = p[1] |
| 750 | 773 |
| 751 # [67] | 774 # [82] |
| 752 def p_UnsignedIntegerType(self, p): | 775 def p_UnsignedIntegerType(self, p): |
| 753 """UnsignedIntegerType : UNSIGNED IntegerType | 776 """UnsignedIntegerType : UNSIGNED IntegerType |
| 754 | IntegerType""" | 777 | IntegerType""" |
| 755 if len(p) == 2: | 778 if len(p) == 2: |
| 756 p[0] = p[1] | 779 p[0] = p[1] |
| 757 else: | 780 else: |
| 758 p[0] = 'unsigned ' + p[2] | 781 p[0] = 'unsigned ' + p[2] |
| 759 | 782 |
| 760 # [68] | 783 # [83] |
| 761 def p_IntegerType(self, p): | 784 def p_IntegerType(self, p): |
| 762 """IntegerType : SHORT | 785 """IntegerType : SHORT |
| 763 | LONG OptionalLong""" | 786 | LONG OptionalLong""" |
| 764 if len(p) == 2: | 787 if len(p) == 2: |
| 765 p[0] = p[1] | 788 p[0] = p[1] |
| 766 else: | 789 else: |
| 767 p[0] = p[1] + p[2] | 790 p[0] = p[1] + p[2] |
| 768 | 791 |
| 769 # [69] | 792 # [84] |
| 770 def p_OptionalLong(self, p): | 793 def p_OptionalLong(self, p): |
| 771 """OptionalLong : LONG | 794 """OptionalLong : LONG |
| 772 | """ | 795 | """ |
| 773 if len(p) > 1: | 796 if len(p) > 1: |
| 774 p[0] = ' ' + p[1] | 797 p[0] = ' ' + p[1] |
| 775 else: | 798 else: |
| 776 p[0] = '' | 799 p[0] = '' |
| 777 | 800 |
| 778 | 801 |
| 779 # [70] Add support for sized array | 802 # [85] Add support for sized array |
| 780 def p_TypeSuffix(self, p): | 803 def p_TypeSuffix(self, p): |
| 781 """TypeSuffix : '[' integer ']' TypeSuffix | 804 """TypeSuffix : '[' integer ']' TypeSuffix |
| 782 | '[' ']' TypeSuffix | 805 | '[' ']' TypeSuffix |
| 783 | '?' TypeSuffixStartingWithArray | 806 | '?' TypeSuffixStartingWithArray |
| 784 | """ | 807 | """ |
| 785 if len(p) == 5: | 808 if len(p) == 5: |
| 786 p[0] = self.BuildNamed('Array', p, 2, p[4]) | 809 p[0] = self.BuildNamed('Array', p, 2, p[4]) |
| 787 | 810 |
| 788 if len(p) == 4: | 811 if len(p) == 4: |
| 789 p[0] = self.BuildProduction('Array', p, 1, p[3]) | 812 p[0] = self.BuildProduction('Array', p, 1, p[3]) |
| 790 | 813 |
| 791 if len(p) == 3: | 814 if len(p) == 3: |
| 792 p[0] = ListFromConcat(self.BuildTrue('NULLABLE'), p[2]) | 815 p[0] = ListFromConcat(self.BuildTrue('NULLABLE'), p[2]) |
| 793 | 816 |
| 794 | 817 |
| 795 # [71] | 818 # [86] |
| 796 def p_TypeSuffixStartingWithArray(self, p): | 819 def p_TypeSuffixStartingWithArray(self, p): |
| 797 """TypeSuffixStartingWithArray : '[' ']' TypeSuffix | 820 """TypeSuffixStartingWithArray : '[' ']' TypeSuffix |
| 798 | """ | 821 | """ |
| 799 if len(p) > 1: | 822 if len(p) > 1: |
| 800 p[0] = self.BuildProduction('Array', p, 0, p[3]) | 823 p[0] = self.BuildProduction('Array', p, 0, p[3]) |
| 801 | 824 |
| 802 # [72] | 825 # [87] |
| 803 def p_Null(self, p): | 826 def p_Null(self, p): |
| 804 """Null : '?' | 827 """Null : '?' |
| 805 |""" | 828 |""" |
| 806 if len(p) > 1: | 829 if len(p) > 1: |
| 807 p[0] = self.BuildTrue('NULLABLE') | 830 p[0] = self.BuildTrue('NULLABLE') |
| 808 | 831 |
| 809 # [73] | 832 # [88] |
| 810 def p_ReturnType(self, p): | 833 def p_ReturnType(self, p): |
| 811 """ReturnType : Type | 834 """ReturnType : Type |
| 812 | VOID""" | 835 | VOID""" |
| 813 if p[1] == 'void': | 836 if p[1] == 'void': |
| 814 p[0] = self.BuildProduction('Type', p, 1) | 837 p[0] = self.BuildProduction('Type', p, 1) |
| 815 p[0].AddChildren(self.BuildNamed('PrimitiveType', p, 1)) | 838 p[0].AddChildren(self.BuildNamed('PrimitiveType', p, 1)) |
| 816 else: | 839 else: |
| 817 p[0] = p[1] | 840 p[0] = p[1] |
| 818 | 841 |
| 819 # [74] | 842 # [89-90] NOT IMPLEMENTED (IdentifierList) |
| 843 |
| 844 # [91] |
| 820 def p_ExtendedAttributeNoArgs(self, p): | 845 def p_ExtendedAttributeNoArgs(self, p): |
| 821 """ExtendedAttributeNoArgs : identifier""" | 846 """ExtendedAttributeNoArgs : identifier""" |
| 822 p[0] = self.BuildNamed('ExtAttribute', p, 1) | 847 p[0] = self.BuildNamed('ExtAttribute', p, 1) |
| 823 | 848 |
| 824 # [75] | 849 # [92] |
| 825 def p_ExtendedAttributeArgList(self, p): | 850 def p_ExtendedAttributeArgList(self, p): |
| 826 """ExtendedAttributeArgList : identifier '(' ArgumentList ')'""" | 851 """ExtendedAttributeArgList : identifier '(' ArgumentList ')'""" |
| 827 arguments = self.BuildProduction('Arguments', p, 2, p[3]) | 852 arguments = self.BuildProduction('Arguments', p, 2, p[3]) |
| 828 p[0] = self.BuildNamed('ExtAttribute', p, 1, arguments) | 853 p[0] = self.BuildNamed('ExtAttribute', p, 1, arguments) |
| 829 | 854 |
| 830 # [76] | 855 # [93] |
| 831 def p_ExtendedAttributeIdent(self, p): | 856 def p_ExtendedAttributeIdent(self, p): |
| 832 """ExtendedAttributeIdent : identifier '=' identifier""" | 857 """ExtendedAttributeIdent : identifier '=' identifier""" |
| 833 value = self.BuildAttribute('VALUE', p[3]) | 858 value = self.BuildAttribute('VALUE', p[3]) |
| 834 p[0] = self.BuildNamed('ExtAttribute', p, 1, value) | 859 p[0] = self.BuildNamed('ExtAttribute', p, 1, value) |
| 835 | 860 |
| 836 # [77] | 861 # [94] NOT IMPLEMENTED (ExtendedAttributeIdentList) |
| 862 |
| 863 # [95] |
| 837 def p_ExtendedAttributeNamedArgList(self, p): | 864 def p_ExtendedAttributeNamedArgList(self, p): |
| 838 """ExtendedAttributeNamedArgList : identifier '=' identifier '(' ArgumentLis
t ')'""" | 865 """ExtendedAttributeNamedArgList : identifier '=' identifier '(' ArgumentLis
t ')'""" |
| 839 args = self.BuildProduction('Arguments', p, 4, p[5]) | 866 args = self.BuildProduction('Arguments', p, 4, p[5]) |
| 840 value = self.BuildNamed('Call', p, 3, args) | 867 value = self.BuildNamed('Call', p, 3, args) |
| 841 p[0] = self.BuildNamed('ExtAttribute', p, 1, value) | 868 p[0] = self.BuildNamed('ExtAttribute', p, 1, value) |
| 842 | 869 |
| 870 # [96] NOT IMPLEMENTED (ExtendedAttributeTypePair) |
| 871 |
| 843 # | 872 # |
| 844 # Parser Errors | 873 # Parser Errors |
| 845 # | 874 # |
| 846 # p_error is called whenever the parser can not find a pattern match for | 875 # p_error is called whenever the parser can not find a pattern match for |
| 847 # a set of items from the current state. The p_error function defined here | 876 # a set of items from the current state. The p_error function defined here |
| 848 # is triggered logging an error, and parsing recovery happens as the | 877 # is triggered logging an error, and parsing recovery happens as the |
| 849 # p_<type>_error functions defined above are called. This allows the parser | 878 # p_<type>_error functions defined above are called. This allows the parser |
| 850 # to continue so as to capture more than one error per file. | 879 # to continue so as to capture more than one error per file. |
| 851 # | 880 # |
| 852 def p_error(self, t): | 881 def p_error(self, t): |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1052 | 1081 |
| 1053 print '\n'.join(ast.Tree(accept_props=['PROD'])) | 1082 print '\n'.join(ast.Tree(accept_props=['PROD'])) |
| 1054 if errors: | 1083 if errors: |
| 1055 print '\nFound %d errors.\n' % errors | 1084 print '\nFound %d errors.\n' % errors |
| 1056 | 1085 |
| 1057 return errors | 1086 return errors |
| 1058 | 1087 |
| 1059 | 1088 |
| 1060 if __name__ == '__main__': | 1089 if __name__ == '__main__': |
| 1061 sys.exit(main(sys.argv[1:])) | 1090 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |