Best Python code snippet using autotest_python
fe_parser.py
Source:fe_parser.py
...92 if self._current.is_COLON():93 self._append_syntaxic_node()94 self._next_token_node()95 if not self._access_qualifier():96 self._append_error( FESyntaxErrors.ACCESS_QUALIFIER )97 if self._current.is_COLON():98 self._append_syntaxic_node()99 self._next_token_node()100 else:101 self._append_error( FESyntaxErrors.ACCESS_END )102 return True103 else:104 return False105 #-------------------------------------------------------------------------106 def _access_qualifier(self) -> bool:107 #=======================================================================108 # <protection qualifier> ::= 'hidden'109 # | 'local'110 # | 'private'111 # | 'protected'112 # | 'public'113 #=======================================================================114 if self._current.is_HIDDEN() or self._current.is_PROTECTED() or self._current.is_PUBLIC(): ## (notice: previously scanned by Scanner)115 self._append_syntaxic_node()116 self._next_token_node()117 return True118 else:119 return False120 #-------------------------------------------------------------------------121 def _and_test(self) -> bool:122 #=======================================================================123 # <and test> ::= <not test> <and test'>124 #=======================================================================125 return self._not_test() and self._and_test1()126 #-------------------------------------------------------------------------127 def _and_test1(self) -> bool:128 #=======================================================================129 # <and test'> ::= 'and' <not test>130 # | EPS131 #=======================================================================132 if self._current.is_AND():133 self._append_syntaxic_node()134 self._next_token_node()135 self._not_test()136 return True137 #-------------------------------------------------------------------------138 def _arithmetic_expr(self) -> bool:139 #=======================================================================140 # <arithmetic expr> ::= <term> <arithmetic expr'>141 #=======================================================================142 return self._term() and self._arithmetic_expr1()143 #-------------------------------------------------------------------------144 def _arithmetic_expr1(self) -> bool:145 #=======================================================================146 # <artihmetic expr'> ::= '+' <template args> <term> <arithmetic expr'>147 # | '-' <template args> <term> <arithmetic expr'>148 # | EPS149 #=======================================================================150 while self._current.is_MINUS() or self._current.is_PLUS():151 self._append_syntaxic_node()152 self._next_token_node()153 self._template_args() ## (notice: always returns True)154 if not self._term():155 self._append_error( FESyntaxErrors.ARITHM_EXPR )156 return True157 #-------------------------------------------------------------------------158 def _array_type(self) -> bool:159 #=======================================================================160 # <array type> ::= "array" <declared contained type>161 #=======================================================================162 if self._current.is_ARRAY():163 self._append_syntaxic_node()164 self._next_token_node()165 if not self._declared_contained_type():166 self._append_error( FESyntaxErrors.ARRAY_CONTAINED_TYPE )167 return True168 else:169 return False170 #-------------------------------------------------------------------------171 def _assert_statement(self) -> bool:172 #===============================================================================173 # <assert statement> ::= 'assert' <expression> <assert statement'>174 #===============================================================================175 if self._current.is_ASSERT():176 self._append_syntaxic_node()177 self._next_token_node()178 if not self._expression():179 self._append_error( FESyntaxErrors.ASSERT_EXPR )180 self._assert_statement1()181 return True182 else:183 return False184 #-------------------------------------------------------------------------185 def _assert_statement1(self) -> bool:186 #=======================================================================187 # <assert statement'> ::= ',' <expression>188 # | EPS189 #=======================================================================190 if self._current.is_COMMA():191 self._append_syntaxic_node()192 self._next_token_node()193 if not self._expression():194 self._append_error( FESyntaxErrors.ASSERT_COMMA_EXPR )195 return True196 #-------------------------------------------------------------------------197 def _assign_decl_def_funccall_statement(self) -> bool:198 #=======================================================================199 # <assign decl def func-call statement> ::= <access qualifier> <decl or def statement>200 # | <decl or def statement>201 # | <dotted name> <assign or func-call statement> <simple statement end>202 #=======================================================================203 if self._access_qualifier():204 if not self._decl_or_def_statement():205 self._append_error( FESyntaxErrors.PROTECTION_DECL_DEF )206 return True207 elif self._decl_or_def_statement():208 return True209 elif self._dotted_name():210 if not self._assign_or_funccall_statement():211 self._append_error( FESyntaxErrors.ASSIGN_FUNC_CALL )212 if not self._simple_statement_end():213 self._append_error( FESyntaxErrors.STATEMENT_END )214 return True215 else:216 return False217 #-------------------------------------------------------------------------218 def _assign_op(self) -> bool:219 #=======================================================================220 # <assign op> ::= '='221 # | <augmented assign op>222 #=======================================================================223 if self._current.is_ASSIGN():224 self._append_syntaxic_node()225 self._next_token_node()226 return True227 else:228 return self._augmented_assign_op()229 #-------------------------------------------------------------------------230 def _assign_or_funccall_statement(self) -> bool:231 #=======================================================================232 # <assign or func-call statement> ::= <target list'> <assignment statement>233 # | <function call>234 #=======================================================================235 if self._target_list1():236 if not self._assignment_statement():237 self._append_error( FESyntaxErrors.ASSIGN_OPERATOR )238 return True239 elif self._function_call():240 return True241 else:242 return False243 #-------------------------------------------------------------------------244 def _assignment_statement(self) -> bool:245 #=======================================================================246 # <assignment statement> ::= <assign op> <expr list>247 #=======================================================================248 if self._assign_op():249 if not self._expr_list():250 self._append_error( FESyntaxErrors.ASSIGN_EXPR )251 return True252 else:253 return False254 255 #-------------------------------------------------------------------------256 def _atom(self) -> bool:257 #=======================================================================258 # <atom> ::= <decr> <dotted name> <incr or decr>259 # | <incr> <dotted name> <incr or decr>260 # | <enclosure>261 # | <reference>262 # | <scalar>263 # | <string>264 # | <boolean>265 #=======================================================================266 if self._decr():267 if not self._dotted_name():268 self._append_error( FESyntaxErrors.DECR_IDENT )269 return self._incr_or_decr()270 elif self._incr():271 if not self._dotted_name():272 self._append_error( FESyntaxErrors.INCR_IDENT )273 return self._incr_or_decr()274 else:275 return self._enclosure() or \276 self._reference() or \277 self._scalar() or \278 self._string() or \279 self._boolean()280 281 #-------------------------------------------------------------------------282 def atom1(self) -> bool:283 #=======================================================================284 # <atom'> ::= <incr or decr>285 # | <for comprehension>286 # | '??' <expression> <atom''> 287 #=======================================================================288 if self._current.is_OP_2QUEST():289 self._append_syntaxic_node()290 self._next_token_node()291 if not self._expression():292 self._append_error( FESyntaxErrors.OP_2QUEST_EXPR )293 return self._atom2()294 else:295 return self._for_comprehension() or self._incr_or_decr()296 ## CAUTION: this order of calls is MANDATORY297 298 #-------------------------------------------------------------------------299 def atom2(self) -> bool:300 #=======================================================================301 # <atom''> ::= '??' <expression> <atom''>302 # | EPS303 #=======================================================================304 while self._current.is_OP_2QUEST():305 self._append_syntaxic_node()306 self._next_token_node()307 if not self._expression():308 self._append_error( FESyntaxErrors.OP_2QUEST_EXPR )309 return True310 #-------------------------------------------------------------------------311 def _atom_element(self) -> bool:312 #===============================================================================313 # <atom element> ::= <atom> 314 # | <dotted name> <atom element'>315 # | <const qualifier> <atom element''>316 # | <atom element''>317 #===============================================================================318 if self._atom():319 return True320 elif self._dotted_name():321 return self._atom_element1()322 elif self._const_qualifier():323 if not self._atom_element2():324 self._append_error( FESyntaxErrors.SCALAR_TYPE )325 return True326 elif self._atom_element2():327 return True328 else:329 return False330 #-------------------------------------------------------------------------331 def _atom_element1(self) -> bool:332 #=======================================================================333 # <atom element'> ::= <atom'>334 # | <atom element'''>335 #=======================================================================336 return self._atom1() or self._atom_element3()337 #-------------------------------------------------------------------------338 def _atom_element2(self) -> bool:339 #=======================================================================340 # <atom element''> ::= <scalar type'> <scalar type casting>341 #=======================================================================342 if self._scalar_type1():343 if not self._type_casting():344 self._append_error( FESyntaxErrors.CASTING_PAROP )345 return True346 else:347 return False348 #-------------------------------------------------------------------------349 def _atom_element3(self) -> bool:350 #=======================================================================351 # <atom element'''> ::= <function call> <atom element''''>352 # | <is instance of>353 # | <subscription or slicing> <atom element''''>354 # | EPS355 #=======================================================================356 while self._function_call() or self._subscription_or_slicing():357 continue358 if self._is_instance_of():359 return True360 else:361 return True362 #-------------------------------------------------------------------------363 def _augmented_assign_op(self) -> bool:364 #===============================================================================365 # <augmented assign op> ::= '+='366 # | '-='367 # | '*='368 # | '/='369 # | '%='370 # | '&='371 # | '|='372 # | '^='373 # | '<<='374 # | '<<<='375 # | '>>='376 # | '>>>='377 # | '**='378 # | '^^='379 # | '@='380 # | '@@='381 # | '><='382 # | '<>='383 # | '!!='384 # | '::='385 # | '??='386 #===============================================================================387 if isinstance( self._current, (ICTokenNode_AUG_2AROB,388 ICTokenNode_AUG_2COLN,389 ICTokenNode_AUG_2EXCL, 390 ICTokenNode_AUG_2QUEST, 391 ICTokenNode_AUG_AROBASE,392 ICTokenNode_AUG_BITAND,393 ICTokenNode_AUG_BITOR,394 ICTokenNode_AUG_BITXOR,395 ICTokenNode_AUG_DIV,396 ICTokenNode_AUG_GRLE,397 ICTokenNode_AUG_LEGR,398 ICTokenNode_AUG_MINUS,399 ICTokenNode_AUG_MOD,400 ICTokenNode_AUG_MUL,401 ICTokenNode_AUG_PLUS,402 ICTokenNode_AUG_POWER,403 ICTokenNode_AUG_SHIFT0L,404 ICTokenNode_AUG_SHIFT0R,405 ICTokenNode_AUG_SHIFTL,406 ICTokenNode_AUG_SHIFTR) ):407 self._append_syntaxic_node()408 self._next_token_node()409 return True410 else:411 return False412 #-------------------------------------------------------------------------413 def _auto_type(self) -> bool:414 #=======================================================================415 # <auto type> ::= '?' <auto type'>416 #=======================================================================417 if self._current.is_ANY_TYPE():418 self._append_syntaxic_node()419 self._next_token_node()420 self._auto_type1() ## (notice: always returns True)421 return True422 else:423 return False424 425 #-------------------------------------------------------------------------426 def _auto_type1(self) -> bool:427 #=======================================================================428 # <auto type'> ::= 'in' '(' <types list> ')'429 # | EPS430 #=======================================================================431 if self._current.is_IN():432 self._append_syntaxic_node()433 self._next_token_node()434 if self._current.is_PAROP():435 self._append_syntaxic_node()436 self._next_token_node()437 else:438 self._append_error( FESyntaxErrors.AUTO_IN_PAROP )439 if not self._types_list():440 self._append_error( FESyntaxErrors.AUTO_IN_TYPES_LIST )441 if self._current.is_PARCL():442 self._append_syntaxic_node()443 self._next_token_node()444 else:445 self._append_error( FESyntaxErrors.AUTO_IN_PARCL )446 return True447 #-------------------------------------------------------------------------448 def _bitand_expr(self) -> bool:449 #===============================================================================450 # <bitand expr> ::= <shift expr> <bitand expr'>451 #===============================================================================452 if self._shift_expr():453 self._bitand_expr1()454 return True455 else:456 return False457 #-------------------------------------------------------------------------458 def _bitand_expr1(self) -> bool:459 #=======================================================================460 # <bitand expr'> ::= '&' <template args> <shift expr> <bitand expr'>461 # | EPS462 #=======================================================================463 while self._current.is_BITAND():464 self._append_syntaxic_node()465 self._next_token_node()466 self._template_args()467 if not self._shift_expr():468 self._append_error( FESyntaxErrors.BITAND_EXPR )469 return True470 #-------------------------------------------------------------------------471 def _bitor_expr(self) -> bool:472 #=======================================================================473 # <bitor expr> ::= <bitxor expr> <bitor expr'>474 #=======================================================================475 if self._bitxor_expr():476 self._bitor_expr1()477 return True478 else:479 return False480 #-------------------------------------------------------------------------481 def _bitor_expr1(self) -> bool:482 #=======================================================================483 # <bitor expr'> ::= '|' <template args> <bitxor expr> <bitor expr'>484 # | EPS485 #=======================================================================486 while self._current.is_BITOR():487 self._append_syntaxic_node()488 self._next_token_node()489 self._template_args()490 if not self._bitxor_expr():491 self._append_error( FESyntaxErrors.BITOR_EXPR )492 return True493 #-------------------------------------------------------------------------494 def _bitxor_expr(self) -> bool:495 #=======================================================================496 # <bitxor expr> ::= <bitand expr> <bitxor expr'>497 #=======================================================================498 if self._bitand_expr():499 self._bitxor_expr1()500 return True501 else:502 return False503 #-------------------------------------------------------------------------504 def _bitxor_expr1(self) -> bool:505 #=======================================================================506 # <bitxor expr'> ::= '^' <template args> <bitand expr> <bitxor expr'>507 # | EPS508 #=======================================================================509 while self._current.is_BITXOR():510 self._append_syntaxic_node()511 self._next_token_node()512 self._template_args()513 if not self._bitand_expr():514 self._append_error( FESyntaxErrors.BITXOR_EXPR )515 return True516 #-------------------------------------------------------------------------517 def _boolean(self) -> bool:518 #=======================================================================519 # <boolean> ::= <TRUE> | <FALSE>520 #=======================================================================521 return self._true() or self._false()522 #-------------------------------------------------------------------------523 def _bracket_form(self) -> bool:524 #=======================================================================525 # <bracket form> ::= '[' <expression> <list or map form> ']'526 #=======================================================================527 if self._current.is_BRACKETOP():528 self._append_syntaxic_node()529 self._next_token_node()530 if not self._expression():531 self._append_error( FESyntaxErrors.BRACKET_FORM_EXPR )532 if not self._list_or_map_form():533 self._append_error( FESyntaxErrors.BRACKET_FORM_LIST_OR_MAP )534 if self._current.is_BRACKETCL():535 self._append_syntaxic_node()536 self._next_token_node()537 else:538 self._append_error( FESyntaxErrors.BRACKET_ENDING )539 return True540 else:541 return False542 #-------------------------------------------------------------------------543 def _call_operator(self) -> bool:544 #=======================================================================545 # <call operator> ::= '(' ')'546 #=======================================================================547 if self._current.is_PAROP():548 self._append_syntaxic_node()549 self._next_token_node()550 if self._current.is_PARCL():551 self._append_syntaxic_node()552 self._next_token_node()553 else:554 self._append_error( FESyntaxErrors.CALL_OP )555 return True556 else:557 return False558 559 #-------------------------------------------------------------------------560 def _case(self) -> bool:561 #=======================================================================562 # <case> ::= 'case' <expr list> <statements block>563 #=======================================================================564 if self._current.is_CASE():565 self._append_syntaxic_node()566 self._next_token_node()567 if not self._expr_list():568 self._append_error( FESyntaxErrors.CASE_EXPR )569 if not self._statements_block():570 self._append_error( FESyntaxErrors.CASE_BODY )571 return True572 else:573 return False574 #-------------------------------------------------------------------------575 def _cast_op(self) -> bool:576 #=======================================================================577 # <cast op> ::= 'cast' <identifier>578 #=======================================================================579 if self._current.is_CAST():580 self._append_syntaxic_node()581 self._next_token_node()582 if self._current.is_IDENT():583 self._append_syntaxic_node()584 self._next_token_node()585 else:586 self._append_error( FESyntaxErrors.CASTED_TYPE )587 return True588 else:589 return False 590 #-------------------------------------------------------------------------591 def _class_definition(self) -> bool:592 #=======================================================================593 # <class definition> ::= 'class' <identifier> <template def> <inheritance> <statements block>594 #=======================================================================595 if self._current.is_CLASS():596 self._append_syntaxic_node()597 self._next_token_node()598 if not self._current._identifier():599 self._append_error( FESyntaxErrors.CLASS_NAME )600 self._template_def()601 self._inheritance()602 if not self._statements_block():603 self._append_error( FESyntaxErrors.CLASS_BODY )604 return True605 else:606 return False607 #-------------------------------------------------------------------------608 def _comment(self) -> bool:609 #=======================================================================610 # <comment> ::= '//' <comment'>611 # | '/*' <multi lines comment>612 # <comment'> ::= <any non newline char> <comment'>613 # | <end line>614 # | <ENDOFFILE>615 #=======================================================================616 if self._current.is_COMMENT() or self._current.is_COMMENT_ML(): ## (notice: previously scanned by the Scanner)617 self._append_syntaxic_node()618 self._next_token_node()619 return True620 else:621 return False622 #-------------------------------------------------------------------------623 def _comparison(self) -> bool:624 #=======================================================================625 # <comparison> ::= <bitor expr> <comparison'>626 #=======================================================================627 return self._bitor_expr() and self._comparison1()628 #-------------------------------------------------------------------------629 def _comparison1(self) -> bool:630 #===============================================================================631 # <comparison'> ::= <comp operator> <template args> <bitor expr> <comparison'>632 # | <comp operator'> <spaced template args> <bitor expr> <comparison'>633 # | EPS634 #===============================================================================635 while True:636 if self._comp_operator():637 self._template_args()638 if not self._bitor_expr():639 self._append_error( FESyntaxErrors.COMP_EXPR )640 elif self._comp_operator1():641 self._spaced_template_args()642 if not self._bitor_expr():643 self._append_error( FESyntaxErrors.COMP_EXPR )644 else:645 break646 return True647 #-------------------------------------------------------------------------648 def _comp_operator(self) -> bool:649 #=======================================================================650 # <comp operator> ::= '<=' | '==' | '!=' | '>='651 # | 'in'652 # | <is operator>653 # | 'not' 'in'654 #=======================================================================655 if self._current.is_LE() or \656 self._current.is_EQ() or \657 self._current.is_NE() or \658 self._current.is_GE() or \659 self._current.is_IN():660 self._append_syntaxic_node()661 self._next_token_node()662 return True663 elif self._current.is_NOT():664 self._append_syntaxic_node()665 self._next_token_node()666 if self._current.is_IN():667 self._append_syntaxic_node()668 self._next_token_node()669 else:670 self._append_error( FESyntaxErrors.NOT_IN )671 return True672 else:673 return self._is_operator()674 #-------------------------------------------------------------------------675 def _comp_operator1(self) -> bool:676 #=======================================================================677 # <comp operator'> ::= '<' | '>' | '<=>'678 #=======================================================================679 if self._current.is_LT() or self._current.is_GT() or self._current.is_LEG():680 self._append_syntaxic_node()681 self._next_token_node()682 return True683 else:684 return False685 686 #-------------------------------------------------------------------------687 def _compound_statement(self) -> bool:688 #=======================================================================689 # <compound statement> ::= <assign decl def func-call statement>690 # | <embed statement>691 # | <exclude statement>692 # | <for statement>693 # | <forever statement>694 # | <if statement>695 # | <repeat statement>696 # | <switch statement>697 # | <try statement>698 # | <while statement>699 # | <with statement>700 #=======================================================================701 return self._assign_decl_def_funccall_statement() or \702 self._embed_statement() or \703 self._exclude_statement() or \704 self._for_statement() or \705 self._forever_statement() or \706 self._if_statement() or \707 self._repeat_statement() or \708 self._switch_statement() or \709 self._try_statement() or \710 self._while_statement() or \711 self._with_statement()712 #-------------------------------------------------------------------------713 def _condition(self) -> bool:714 #=======================================================================715 # <condition> ::= <or test> <condition'>716 #=======================================================================717 return self._or_test() and self._condition1()718 #-------------------------------------------------------------------------719 def _condition1(self) -> bool:720 #=======================================================================721 # <condition'> ::= 'if' <or test> <condition">722 # | EPS723 #=======================================================================724 if self._current.is_IF():725 self._append_syntaxic_node()726 self._next_token_node()727 if not self._or_test():728 self._append_error( FESyntaxErrors.IF_COND )729 return self._condition2()730 else:731 return True 732 #-------------------------------------------------------------------------733 def _condition2(self) -> bool:734 #===========================================================================735 # <condition"> ::= 'else' <expression>736 # | 'otherwise' <expression>737 #===========================================================================738 if self._current.is_ELSE() or self._current.is_OTHERWISE():739 self._append_syntaxic_node()740 self._next_token_node()741 if not self._expression():742 self._append_error( FESyntaxErrors.IF_ELSE_EXPR if self._current.is_ELSE() \743 else FESyntaxErrors.IF_OTHERWISE_EXPR )744 return True745 else:746 self._append_error( FESyntaxErrors.IF_ELSE )747 return True748 #-------------------------------------------------------------------------749 def _condition_or_unnamed_func(self) -> bool:750 #=======================================================================751 # <condition or unnamed func> ::= <or test>752 # | <unnamed function>753 #=======================================================================754 return self._or_test() or self._unnamed_function()755 #-------------------------------------------------------------------------756 def _const_qualifier(self) -> bool:757 #=======================================================================758 # <const qualifier> ::= "const"759 #=======================================================================760 if self._current.is_CONST():761 self._append_syntaxic_node()762 self._next_token_node()763 return True764 else:765 return False766 #-------------------------------------------------------------------------767 def _contained_type(self) -> bool:768 #=======================================================================769 # <contained type> ::= <declared contained type>770 # | EPS771 #=======================================================================772 self._declared_contained_type() ## (notice: returned value doesn't matter)773 return True774 #-------------------------------------------------------------------------775 def _container_type(self) -> bool:776 #=======================================================================777 # <container type> ::= <array_type>778 # | <enum type>779 # | <list type>780 # | <map type>781 # | <set type>782 #=======================================================================783 return self._array_type() or \784 self.enum_type() or \785 self._list_type() or \786 self._map_type() or \787 self._set_type()788 #-------------------------------------------------------------------------789 def _decl_constructor_or_decl_end(self) -> bool:790 #=======================================================================791 # <decl constructor or decl end> ::= <dotted name'> <decl or def statement'''>792 # | <function definition'>793 #=======================================================================794 if self._dotted_name1():795 if not self._decl_or_def_statement3():796 self._append_error( FESyntaxErrors.DECL_DEF_IDENT_OP )797 return True798 else:799 return self._function_definition1()800 #-------------------------------------------------------------------------801 def _decl_or_def_statement(self) -> bool:802 #=======================================================================803 # <decl or def statement> ::= <static qualifier> <decl or def statement'>804 # | <class definition>805 # | <decl or def statement'>806 # | <forward decl>807 #=======================================================================808 if self._static_qualifier():809 if not self._decl_or_def_statement1():810 self._append_error( FESyntaxErrors.STATIC_DECL_DEF )811 else:812 return self._class_definition() or \813 self._decl_or_def_statement1() or \814 self._forward_decl()815 #-------------------------------------------------------------------------816 def _decl_or_def_statement1(self) -> bool:817 #=======================================================================818 # <decl or def statement'> ::= <abstract or final qualif> <method or operator definition>819 # | <volatile qualifier> <TYPE> <identifier> <memory address> <simple statement end>820 # | <type alias> <simple statement end>821 # | <decl or def statement''>822 #=======================================================================823 if self._abstract_or_final_qualif():824 if not self._method_or_operator_definition():825 self._append_error( FESyntaxErrors.ABSTRACT_DEF )826 return True827 elif self._final_qualifier():828 if not self._method_or_operator_definition():829 self._append_error( FESyntaxErrors.FINAL_DEF )830 return True831 elif self._volatile_qualifier():832 if not self._TYPE():833 self._append_error( FESyntaxErrors.VOLATILE_TYPE )834 if not self._identifier():835 self._append_error( FESyntaxErrors.VAR_NAME )836 return True837 if not self._memory_address():838 self._append_error( FESyntaxErrors.VOLATILE_MEM_KW )839 if not self._simple_statement_end():840 self._append_error( FESyntaxErrors.STATEMENT_END )841 return True842 elif self._type_alias():843 if not self._simple_statement_end():844 self._append_error( FESyntaxErrors.STATEMENT_END )845 return True846 else:847 return self._decl_or_def_statement2()848 #-------------------------------------------------------------------------849 def _decl_or_def_statement2(self) -> bool:850 #=======================================================================851 # <decl or def statement''> ::= <TYPE'> <decl or def statement'''>852 # | <enum definition>853 # | <identifier> <decl constructor or decl end>854 #=======================================================================855 if self._TYPE1():856 if not self._decl_or_def_statement3():857 self._append_error( FESyntaxErrors.OP_IDENT_DECL_DEF )858 return True859 elif self._identifier():860 if not self._decl_constructor_or_decl_end():861 self._append_error( FESyntaxErrors.DECL_DEF_TYPE )862 return True863 elif self._enum_definition():864 return True865 else:866 self._append_error( FESyntaxErrors.VAR_TYPE )867 return False868 #-------------------------------------------------------------------------869 def _decl_or_def_statement3(self) -> bool:870 #=======================================================================871 # <decl or def statement'''> ::= <identifier> <decl or def statement''''>872 # | <operator definition>873 #=======================================================================874 if self._identifier():875 return self._decl_or_def_statement4()876 else:877 return self._operator_definition()878 #-------------------------------------------------------------------------879 def _decl_or_def_statement4(self) -> bool:880 #=======================================================================881 # <decl or def statement''''> ::= <function definition>882 # | <var declaration or assignment> <simple statement end>883 #=======================================================================884 if self._function_declaration():885 return True886 elif self._var_declaration_or_assignment():887 if not self._simple_statement_end():888 self._append_error( FESyntaxErrors.STATEMENT_END )889 return True890 else:891 return False892 893 #-------------------------------------------------------------------------894 def _declared_contained_type(self) -> bool:895 #=======================================================================896 # <declared contained type> ::= '<' <TYPE> '>'897 #=======================================================================898 if self._current.is_LT():899 self._append_syntaxic_node()900 self._next_token_node()901 if not self._TYPE():902 self._append_error( FESyntaxErrors.CONTAINED_TYPE )903 if self._current.is_GT():904 self._append_syntaxic_node()905 self._next_token_node()906 else:907 self._append_error( FESyntaxErrors.CONTAINER_END )908 return True909 else:910 return False911 #-------------------------------------------------------------------------912 def _del_statement(self) -> bool:913 #=======================================================================914 # <del statement> ::= 'del' <identifiers list>915 #=======================================================================916 if self._current.is_DEL():917 self._append_syntaxic_node()918 self._next_token_node()919 if not self._identifiers_list():920 self._append_error( FESyntaxErrors.DEL_IDENT )921 return True922 else:923 return False924 #-------------------------------------------------------------------------925 def _dimensions(self) -> bool:926 #=======================================================================927 # <dimensions> ::= '[' <dimensions'> ']' <dimensions>928 # | EPS929 #=======================================================================930 while self._current.is_BRACKETOP():931 self._append_syntaxic_node()932 self._next_token_node()933 if not self._dimensions1():934 if self._float_number():935 self._append_error( FESyntaxErrors.DIMENSION_FLOAT )936 else:937 self._append_error( FESyntaxErrors.DIMENSION_CONST )938 if self._current.is_BRACKETCL():939 self._append_syntaxic_node()940 self._next_token_node()941 else:942 self._append_error( FESyntaxErrors.DIMENSION_END )943 return True944 #-------------------------------------------------------------------------945 def _dimensions1(self) -> bool:946 #=======================================================================947 # <dimensions'> ::= <integer number>948 # | <dotted name>949 #=======================================================================950 if self._integer_number():951 return True952 elif self._dotted_name():953 return True954 else:955 return False956 #-------------------------------------------------------------------------957 def _dotted_as_name(self) -> bool:958 #=======================================================================959 # <dotted as name> ::= <dotted name> <dotted as name'>960 #=======================================================================961 if self._dotted_name():962 return self.dotted_as_name1() ## (notice: always returns True)963 else:964 return False965 #-------------------------------------------------------------------------966 def dotted_as_name1(self) -> bool:967 #=======================================================================968 # <dotted as name'> ::= 'as' <identifier>969 # | EPS970 #=======================================================================971 if self._current.is_AS():972 self._append_syntaxic_node()973 self._next_token_node()974 if not self._identifier():975 self._append_error( FESyntaxErrors.AS_IDENT )976 return True977 else:978 return True979 #-------------------------------------------------------------------------980 def _dotted_as_names(self) -> bool:981 #=======================================================================982 # <dotted as names> ::= <dotted as name> <dotted as names'>983 #=======================================================================984 if self._dotted_as_name():985 return self._dotted_as_names1() ## (notice: always returns True)986 else:987 return False988 #-------------------------------------------------------------------------989 def _dotted_as_names1(self) -> bool:990 #=======================================================================991 # <dotted as names'> ::= ',' <dotted as name> <dotted as names'>992 # | EPS993 #=======================================================================994 while self._current.is_COMMA():995 self._append_syntaxic_node()996 self._next_token_node()997 if not self._dotted_as_name():998 self._append_error( FESyntaxErrors.DOTTED_AS )999 return True1000 #-------------------------------------------------------------------------1001 def _dotted_name(self) -> bool:1002 #=======================================================================1003 # <dotted name> ::= <identifier> <dotted name'>1004 #=======================================================================1005 if self._identifier():1006 return self._dotted_name1() ## (notice: always returns True)1007 else:1008 return False1009 #-------------------------------------------------------------------------1010 def _dotted_name1(self) -> bool:1011 #=======================================================================1012 # <dotted name'> ::= '.' <identifier> <dotted name'>1013 # | EPS1014 #=======================================================================1015 while self._current.is_DOT():1016 self._append_syntaxic_node()1017 self._next_token_node()1018 if not self.identifier():1019 self._append_error( FESyntaxErrors.DOTTED_IDENT )1020 return True1021 #-------------------------------------------------------------------------1022 def _ellipsis(self) -> bool:1023 #=======================================================================1024 # <ellipsis> ::= '...'1025 #=======================================================================1026 if self._current.is_ELLIPSIS():1027 self._append_syntaxic_node()1028 self._next_token_node()1029 return True1030 else:1031 return False1032 #-------------------------------------------------------------------------1033 def _embed_statement(self) -> bool:1034 #=======================================================================1035 # <embed statement> ::= 'embed' <language> <embed statement'>1036 #=======================================================================1037 if self._current.is_EMBED():1038 self._append_syntaxic_node()1039 self._next_token_node()1040 if not self._language():1041 self._append_error( FESyntaxErrors.EMBEDDED_LANGUAGE )1042 if not self._embed_statement1():1043 self._append_error( FESyntaxErrors.EMBEDDED_LANGUAGE_CODE )1044 return True1045 else:1046 return False1047 #-------------------------------------------------------------------------1048 def _embed_statement1(self) -> bool:1049 #=======================================================================1050 # <embed statement'> ::= <dotted name> <simple statement end>1051 # | <embedded language code>1052 #=======================================================================1053 if self._dotted_name():1054 if self._simple_statement_end():1055 self._append_syntaxic_node()1056 self._next_token_node()1057 else:1058 self._append_error( FESyntaxErrors.STATEMENT_END )1059 return True1060 elif self._embedded_language_code():1061 return True1062 else:1063 return False1064 #-------------------------------------------------------------------------1065 def _embedded_language_code(self) -> bool:1066 #===================================================================1067 # <embedded language code> ::= '{{' <embedded language code'>1068 # <embedded language code'> ::= <any embedded code char> <embeded language code'>1069 # | '}' <embedded language code">1070 # <embedded language code"> ::= <any embedded code char> <embeded language code'>1071 # | '}' <embedded language exit>1072 #===================================================================1073 if self._current.is_EMBED_CODE(): ## (notice: previously scanned by the Scanner)1074 self._append_syntaxic_node()1075 self._next_token_node()1076 return self._embedded_language_exit()1077 elif self._current.is_UNEXPECTED():1078 self._append_syntaxic_node()1079 self._next_token_node()1080 self._append_error( FESyntaxErrors.EMBEDDED_CODE_END )1081 return True1082 else:1083 return False1084 #-------------------------------------------------------------------------1085 def _embedded_language_exit(self) -> bool:1086 #=======================================================================1087 # <embedded language exit> ::= 'exit'1088 # | EPS1089 #=======================================================================1090 if self._current.is_EXIT():1091 self._append_syntaxic_node()1092 self._next_token_node()1093 return True1094 #-------------------------------------------------------------------------1095 def _empty_statement(self) -> bool:1096 #=======================================================================1097 # <empty statement> ::= <comment>1098 # | <NEWLINE>1099 #=======================================================================1100 if self._current.is_COMMENT() or self._current.is_COMMENT_ML(): ## (notice: previously scanned by Scanner)1101 self._append_syntaxic_node()1102 self._next_token_node()1103 if not self._new_line():1104 self._append_error( FESyntaxErrors.COMMENT_NL )1105 return True1106 elif self._current.is_NL():1107 self._append_syntaxic_node()1108 self._next_token_node()1109 return True1110 else:1111 return False1112 #-------------------------------------------------------------------------1113 def _enclosure(self) -> bool:1114 #=======================================================================1115 # <enclosure> ::= <bracket form>1116 # | <parenthesis form>1117 #=======================================================================1118 return self._bracket_form() or self._parenthesis_form()1119 #-------------------------------------------------------------------------1120 def _end_line(self) -> bool:1121 #=======================================================================1122 # <end line> ::= <NEWLINE>1123 # | <ENDOFFILE>1124 #=======================================================================1125 if self._current.is_NL() or self._current.is_EOF():1126 self._append_syntaxic_node()1127 self._next_token_node()1128 return True1129 else:1130 return False1131 #-------------------------------------------------------------------------1132 def _end_of_file(self) -> bool:1133 #=======================================================================1134 # <ENDOFFILE> ::= u0x001135 #=======================================================================1136 if self._current.is_EOF():1137 self._append_syntaxic_node()1138 self._next_token_node()1139 return True1140 else:1141 return False1142 #-------------------------------------------------------------------------1143 def _ensure_statement(self) -> bool:1144 #=======================================================================1145 # <ensure statement> ::= 'ensure' <expression> <ensure statement'>1146 #=======================================================================1147 if self._current.is_ENSURE():1148 self._append_syntaxic_node()1149 self._next_token_node()1150 if not self._expression():1151 self._append_error( FESyntaxErrors.ENSURE_EXPR )1152 self._ensure_statement1() ##(notice: always returns True)1153 return True1154 else:1155 return False1156 #-------------------------------------------------------------------------1157 def _ensure_statement1(self) -> bool:1158 #=======================================================================1159 # <ensure statement'> ::= ',' <expression>1160 # | EPS1161 #=======================================================================1162 if self._current.is_COMMA():1163 self._append_syntaxic_node()1164 self._next_token_node()1165 if not self._expression():1166 self._append_error( FESyntaxErrors.ENSURE_COMMA_EXPR )1167 return True1168 #-------------------------------------------------------------------------1169 def _enum_definition(self) -> bool:1170 #=======================================================================1171 # <enum definition> ::= <enum type> <identifier> '{' <enum list> '}'1172 #=======================================================================1173 if self._current.is_ENUM():1174 self._append_syntaxic_node()1175 self._next_token_node()1176 if self._current.is_IDENT():1177 self._append_syntaxic_node()1178 self._next_token_node()1179 else:1180 self._append_error( FESyntaxErrors.ENUM_IDENT )1181 if self._current.is_BRACKETOP:1182 self._append_syntaxic_node()1183 self._next_token_node()1184 else:1185 self._append_error( FESyntaxErrors.ENUM_BRACKET_OP )1186 if not self._enum_list():1187 self._append_error( FESyntaxErrors.ENUM_LIST )1188 if self._current.is_BRACKETCL():1189 self._append_syntaxic_node()1190 self._next_token_node()1191 else:1192 self._append_error( FESyntaxErrors.ENUM_BRACKET_CL )1193 #-------------------------------------------------------------------------1194 def _enum_item(self) -> bool:1195 #=======================================================================1196 # <enum item> ::= <identifier> <enum item'>1197 #=======================================================================1198 if self._current.is_IDENT():1199 self._append_syntaxic_node()1200 self._next_token_node()1201 return self._enum_item1()1202 else:1203 return False1204 #-------------------------------------------------------------------------1205 def _enum_item1(self) -> bool:1206 #=======================================================================1207 # <enum item'> ::= '=' <expression>1208 # | EPS1209 #=======================================================================1210 if self._current.is_ASSIGN():1211 self._append_syntaxic_node()1212 self._next_token_node()1213 if not self._expression():1214 self._append_error( FESyntaxErrors.ENUM_EXPR )1215 return True1216 else:1217 return False1218 #-------------------------------------------------------------------------1219 def _enum_list(self) -> bool:1220 #=======================================================================1221 # <enum list> ::= <enum item> <enum list'>1222 # <enum list'> ::= ',' <enum item> <enum list'>1223 # | EPS1224 #=======================================================================1225 if self._enum_item():1226 self._append_syntaxic_node()1227 self._next_token_node()1228 while self._current.is_COMMA():1229 self._append_syntaxic_node()1230 self._next_token_node()1231 if self._enum_item():1232 self._append_syntaxic_node()1233 self._next_token_node()1234 else:1235 self._append_error( FESyntaxErrors.ENUM_LIST_ITEM )1236 return True1237 else:1238 return False 1239 #-------------------------------------------------------------------------1240 def _enum_type(self) -> bool:1241 #=======================================================================1242 # <enum type> ::= 'enum'1243 #=======================================================================1244 if self._current.is_ENUM():1245 self._append_syntaxic_node()1246 self._next_token_node()1247 return True1248 else:1249 return False1250 #-------------------------------------------------------------------------1251 def _exclude_statement(self) -> bool:1252 #=======================================================================1253 # <exclude statement> ::= 'exclude' <languages> '{{' <statements list> '}}' 1254 #=======================================================================1255 if self._current.is_EXCLUDE():1256 self._append_syntaxic_node()1257 self._next_token_node()1258 if not self._languages():1259 self._append_error( FESyntaxErrors.EXCLUDE_LANGS )1260 if self._current.is_EMBED_CODE():1261 self._append_syntaxic_node()1262 self._next_token_node()1263 else:1264 self._append_error( FESyntaxErrors.EXCLUDE_EMBED )1265 return True1266 else:1267 return False 1268 #-------------------------------------------------------------------------1269 def _expr_list(self) -> bool:1270 #=======================================================================1271 # <expr list> ::= <expression> <expr list'>1272 #=======================================================================1273 return self._expression() and self._expr_list1()1274 #-------------------------------------------------------------------------1275 def _expr_list1(self) -> bool:1276 #=======================================================================1277 # <expr list'> ::= ',' <expression> <expr list'>1278 # | EPS1279 #=======================================================================1280 while self._current.is_COMMA():1281 self._append_syntaxic_node()1282 self._next_token_node()1283 if not self._expression():1284 self._append_error( FESyntaxErrors.LIST_COMMA_EXPR )1285 return True1286 #-------------------------------------------------------------------------1287 def _expression(self) -> bool:1288 #=======================================================================1289 # <expression> ::= <condition>1290 # | <unnamed func>1291 #=======================================================================1292 if self._condition():1293 return True1294 elif self._unnamed_func():1295 return True1296 else:1297 return False1298 #-------------------------------------------------------------------------1299 def _factor(self) -> bool:1300 #=======================================================================1301 # <factor> ::= <atom element> <factor'>1302 #=======================================================================1303 if self._atom_element():1304 self._factor1()1305 return True1306 else:1307 return False1308 #-------------------------------------------------------------------------1309 def _factor1(self) -> bool:1310 #=======================================================================1311 # <factor'> ::= '**' <template args> <unary expr>1312 # | '^^' <template args> <unary expr>1313 # | EPS1314 #=======================================================================1315 if self._current.is_POWER():1316 self._append_syntaxic_node()1317 self._next_token_node()1318 self._template_args()1319 if not self._unary_expr():1320 self._append_error( FESyntaxErrors.POWER_EXPR )1321 return True1322 1323 #-------------------------------------------------------------------------1324 def _false(self) -> bool:1325 #=======================================================================1326 # <FALSE> ::= 'False'1327 # | 'false'1328 #=======================================================================1329 if self._current.is_FALSE():1330 self._append_syntaxic_node()1331 self._next_token_node()1332 return True1333 else:1334 return False1335 #-------------------------------------------------------------------------1336 def _file_endianness(self) -> bool:1337 #=======================================================================1338 # <file endianness> ::= '<' <expression> <file endianness'>1339 # | '>' <expression> <file endianness'>1340 #=======================================================================1341 if self._current.is_LT() or self._current.is_GT():1342 self._append_syntaxic_node()1343 self._next_token_node()1344 if not self._expression():1345 self._append_error( FESyntaxErrors.FILE_ENDIAN_EXPR )1346 self._file_endianness1()1347 return True1348 else:1349 return False1350 #-------------------------------------------------------------------------1351 def _file_endianness1(self) -> bool:1352 #=======================================================================1353 # <file endianness'> ::= '<<' <expression> <file endianness'>1354 # | '>>' <expression> <file endianness'>1355 # | '>>>' <expression> <file endianness'>1356 # | EPS1357 #=======================================================================1358 while self._current.is_SHIFTL() or \1359 self._current.is_SHIFTR() or \1360 self._current.is_SHIFT0R():1361 self._append_syntaxic_node()1362 self._next_token_node()1363 if not self._expression():1364 self._append_error( FESyntaxErrors.FILE_STREAM_EXPR )1365 return True1366 1367 #-------------------------------------------------------------------------1368 def _file_flushing(self) -> bool:1369 #=======================================================================1370 # <file flushing> ::= '!' <dotted name> <file flushing'>1371 #=======================================================================1372 if self._current.is_EXCL():1373 self._append_syntaxic_node()1374 self._next_token_node()1375 if not self._dotted_name():1376 self._append_error( FESyntaxErrors.FILE_FLUSH_IDENT )1377 self._file_flushing1();1378 return True1379 else:1380 return False1381 1382 #-------------------------------------------------------------------------1383 def _file_flushing1(self) -> bool:1384 #=======================================================================1385 # <file flushing'> ::= '(' <expression> <file flushing''> ')'1386 # | '[' <expression> ']' '=' <expression>1387 # | '>>' <expression>1388 # | '>>>' <expression>1389 # | EPS1390 #=======================================================================1391 if self._current.is_PAROP():1392 self._append_syntaxic_node()1393 self._next_token_node()1394 if not self._expression():1395 self._append_error( FESyntaxErrors.FILE_FLUSH_FUNC_CALL )1396 self._file_flushing2()1397 if self._current.is_PARCL():1398 self._append_syntaxic_node()1399 self._next_token_node()1400 else:1401 self._append_error( FESyntaxErrors.FILE_FLUSH_FUNC_END )1402 elif self._current.is_BRACKETOP():1403 self._append_syntaxic_node()1404 self._next_token_node()1405 if not self._expression():1406 self._append_error( FESyntaxErrors.FILE_FLUSH_INDEX )1407 if self._current.is_BRACKETCL():1408 self._append_syntaxic_node()1409 self._next_token_node()1410 else:1411 self._append_error( FESyntaxErrors.FILE_FLUSH_INDEX_END )1412 if self._current.is_ASSIGN():1413 self._append_syntaxic_node()1414 self._next_token_node()1415 else:1416 self._append_error( FESyntaxErrors.FILE_FLUSH_INDEX_ASSIGN )1417 if not self._expression():1418 self._append_error( FESyntaxErrors.FILE_FLUSH_INDEX_EXPR )1419 elif self._current.is_SHIFTR():1420 self._append_syntaxic_node()1421 self._next_token_node()1422 if not self._expression():1423 self._append_error( FESyntaxErrors.FILE_FLUSH_STREAM_EXPR )1424 elif self._current.is_SHIFT0R():1425 self._append_syntaxic_node()1426 self._next_token_node()1427 if not self._expression():1428 self._append_error( FESyntaxErrors.FILE_FLUSH_APPEND_EXPR )1429 return True1430 1431 #-------------------------------------------------------------------------1432 def file_flushing2(self) -> bool:1433 #=======================================================================1434 # <file flushing''> ::= ',' <expression> <file flushing'>1435 # | EPS1436 #=======================================================================1437 if self._current.is_COMMA():1438 self._append_syntaxic_node()1439 self._next_token_node()1440 if not self._expression():1441 self._append_error( FESyntaxErrors.FILE_FLUSH_FUNC_CALL )1442 return self._file_flushing1()1443 return True1444 #-------------------------------------------------------------------------1445 def _file_type(self) -> bool:1446 #=======================================================================1447 # <file type> ::= 'file' <contained type>1448 #=======================================================================1449 if self._current.is_FILE():1450 self._append_syntaxic_node()1451 self._next_token_node()1452 self._contained_type() ## (notice: always returns True)1453 return True1454 else:1455 return False1456 #-------------------------------------------------------------------------1457 def _float_number(self) -> bool:1458 if self._current.is_FLOAT():1459 self._append_syntaxic_node()1460 self._next_token_node()1461 return True1462 else:1463 return False1464 #-------------------------------------------------------------------------1465 def _flow_statement(self) -> bool:1466 #=======================================================================1467 # <flow statement> ::= 'break'1468 # | 'continue'1469 # | <raise statement>1470 # | <return statement>1471 #=======================================================================1472 if self._current.is_BREAK() or self._current.is_CONTINUE():1473 self._append_syntaxic_node()1474 self._next_token_node()1475 return True1476 elif self._raise_statement():1477 return True1478 elif self._return_statement():1479 return True1480 else:1481 return False1482 #-------------------------------------------------------------------------1483 def _for_comprehension(self) -> bool:1484 #=======================================================================1485 # <for comprehension> ::= 'for' '(' <target list> 'in' <or test> <iter comprehension> ')'1486 #=======================================================================1487 if self._current.is_FOR():1488 self._append_syntaxic_node()1489 self._next_token_node()1490 if self._current.is_PAROP():1491 self._append_syntaxic_node()1492 self._next_token_node()1493 else:1494 self._append_error( FESyntaxErrors.FOR_PAROP )1495 if not self._target_list():1496 self._append_error( FESyntaxErrors.FOR_COMPR_TARGETS)1497 if self._current.is_IN():1498 self._append_syntaxic_node()1499 self._next_token_node()1500 else:1501 self._append_error( FESyntaxErrors.FOR_COMPR_IN )1502 if not self._or_test():1503 self._append_error( FESyntaxErrors.FOR_COMPR_CONDITION )1504 self._iter_comprehension()1505 if self._current.is_PARCL():1506 self._append_syntaxic_node()1507 self._next_token_node()1508 else:1509 self._append_error( FESyntaxErrors.FOR_PARCL )1510 return True1511 else:1512 return False1513 #-------------------------------------------------------------------------1514 def _for_statement(self) -> bool:1515 #=======================================================================1516 # <for statement> ::= 'for' '(' <target list> 'in' <expr list> ')' <statements block> <for statement'>1517 #=======================================================================1518 if self._current.is_FOR():1519 self._append_syntaxic_node()1520 self._next_token_node()1521 if self._current.is_PAROP():1522 self._append_syntaxic_node()1523 self._next_token_node()1524 else:1525 self._append_error( FESyntaxErrors.FOR_PAROP )1526 if not self._target_list():1527 self._append_error( FESyntaxErrors.FOR_TARGETS )1528 if self._current.is_IN():1529 self._append_syntaxic_node()1530 self._next_token_node()1531 else:1532 self._append_error( FESyntaxErrors.FOR_IN )1533 if not self._expr_list():1534 self._append_error( FESyntaxErrors.FOR_EXPR)1535 if self._current.is_PARCL():1536 self._append_syntaxic_node()1537 self._next_token_node()1538 else:1539 self._append_error( FESyntaxErrors.FOR_PARCL )1540 if not self._statements_block():1541 self._append_error( FESyntaxErrors.FOR_BODY )1542 self._for_statement1() ## (notice: always returns True)1543 return True1544 else:1545 return False1546 #-------------------------------------------------------------------------1547 def _for_statement1(self) -> bool:1548 #=======================================================================1549 # <for statement'> ::= 'otherwise' <statements block>1550 # | EPS1551 #=======================================================================1552 if self._current.is_OTHERWISE():1553 self._append_syntaxic_node()1554 self._next_token_node()1555 if not self._statements_block():1556 self._append_error( FESyntaxErrors.FOR_ELSE_BODY )1557 return True1558 1559 #-------------------------------------------------------------------------1560 def _forever_statement(self) -> bool:1561 #=======================================================================1562 # <forever statement> ::= 'forever' '(' ')' <statements block>1563 #=======================================================================1564 if self._current.is_FOREVER():1565 self._append_syntaxic_node()1566 self._next_token_node()1567 if self._current.is_PAROP():1568 self._append_syntaxic_node()1569 self._next_token_node()1570 else:1571 self._append_error( FESyntaxErrors.FOREVER_PAROP )1572 if self._current.is_PARCL():1573 self._append_syntaxic_node()1574 self._next_token_node()1575 else:1576 self._append_error( FESyntaxErrors.FOREVER_PARCL )1577 if not self._statements_block():1578 self._append_error( FESyntaxErrors.FOREVER_BODY )1579 return True1580 else:1581 return False1582 1583 #-------------------------------------------------------------------------1584 def _forward_decl(self) -> bool:1585 #=======================================================================1586 # <forward decl> ::= <forward> <forward decl'>1587 #=======================================================================1588 if self._current.is_FORWARD():1589 self._append_syntaxic_node()1590 self._next_token_node()1591 if not self._forward_decl1():1592 self._append_error( FESyntaxErrors.FORWARD_DECL )1593 return True1594 else:1595 return False1596 #-------------------------------------------------------------------------1597 def _forward_decl1(self) -> bool:1598 #=======================================================================1599 # <forward decl'> ::= <static qualifier> <forward decl''>1600 # | <forward decl''>1601 # | <fwd class decl>1602 #=======================================================================1603 if self._current.is_STATIC():1604 self._append_syntaxic_node()1605 self._next_token_node()1606 if not self._forward_decl2():1607 self._append_error( FESyntaxErrors.FORWARD_STATIC_DECL )1608 return True1609 else:1610 return self._forward_decl2() or self._fwd_class_decl()1611 #-------------------------------------------------------------------------1612 def _forward_decl2(self) -> bool:1613 #=======================================================================1614 # <forward decl''> ::= <volatile qualifier> <type> <identifier>1615 # | <fwd type decl>1616 # | <forward decl'''>1617 #=======================================================================1618 if self._current.is_VOLATILE():1619 self._append_syntaxic_node()1620 self._next_token_node()1621 if not self._type():1622 self._append_error( FESyntaxErrors.VOLATILE_TYPE )1623 return True1624 else:1625 return self._fwd_type_decl() or self._forward_decl3()1626 #-------------------------------------------------------------------------1627 def _forward_decl3(self) -> bool:1628 #=======================================================================1629 # <forward decl'''> ::= <TYPE'> <forward decl''''>1630 # | <identifier> <fwd decl constructor>1631 #=======================================================================1632 if self._TYPE1():1633 if not self._forward_decl4():1634 self._append_error( FESyntaxErrors.FORWARD_TYPE_DECL )1635 return True1636 elif self._identifier():1637 if not self._fwd_decl_constructor():1638 self._append_error( FESyntaxErrors.FORWARD_DECL_CONSTR )1639 return True1640 else:1641 return False1642 #-------------------------------------------------------------------------1643 def _forward_decl4(self) -> bool:1644 #=======================================================================1645 # <forward decl''''> ::= <identifier> <forward decl'''''>1646 # | <operator declaration>1647 #=======================================================================1648 if self._identifier():1649 if not self._forward_decl5():1650 self._append_error( FESyntaxErrors.FORWARD_FUNC_VAR_DECL )1651 return True1652 else:1653 return self._operator_declaration()1654 #-------------------------------------------------------------------------1655 def _forward_decl5(self) -> bool:1656 #=======================================================================1657 # <forward decl'''''> ::= <function declaration>1658 # | <fwd var decl>1659 #=======================================================================1660 return self._function_declaration() or self._fwd_var_decl()1661 #-------------------------------------------------------------------------1662 def _function_args_declaration(self) -> bool:1663 #=======================================================================1664 # <function args declaration> ::= '(' <typed args list> ')'1665 #=======================================================================1666 if self._current.is_PAROP():1667 self._append_syntaxic_node()1668 self._next_token_node()1669 self._typed_args_list()1670 if self._current.is_PARCL():1671 self._append_syntaxic_node()1672 self._next_token_node()1673 else:1674 self._append_error( FESyntaxErrors.FUNCTION_ARGS_END )1675 return True1676 else:1677 return False1678 #-------------------------------------------------------------------------1679 def _function_call(self) -> bool:1680 #=======================================================================1681 # <function call> ::= <template args> '(' <function call args> ')'1682 #=======================================================================1683 if self._template_args():1684 if self._current.is_PAROP():1685 self._append_syntaxic_node()1686 self._next_token_node()1687 self._function_call_args()1688 if self._current.is_PARCL():1689 self._append_syntaxic_node()1690 self._next_token_node()1691 else:1692 self._append_error( FESyntaxErrors.FUNCTION_CALL_END )1693 else:1694 self._append_error( FESyntaxErrors.FUNCTION_CALL_BEGIN )1695 return True1696 else:1697 return False1698 #-------------------------------------------------------------------------1699 def _function_call_args(self) -> bool:1700 #=======================================================================1701 # <function call args> ::= <expression> <function call args'>1702 # | EPS1703 #=======================================================================1704 if self._expression():1705 return self._function_call_args1()1706 else:1707 return True1708 #-------------------------------------------------------------------------1709 def _function_call_args1(self) -> bool:1710 #=======================================================================1711 # <function call args'> ::= ',' <function call args">1712 # | <for comprehension>1713 # | EPS1714 #=======================================================================1715 if self._current.is_COMMA():1716 self._append_syntaxic_node()1717 self._next_token_node()1718 if not self._function_call_args2():1719 self._append_error( FESyntaxErrors.FUNCTION_ARGS_LIST )1720 return True1721 elif self._for_comprehension():1722 return True1723 else:1724 return True 1725 #-------------------------------------------------------------------------1726 def _function_call_args2(self) -> bool:1727 #=======================================================================1728 # <function call args"> ::= <expression> <function call args'>1729 # | <ellipsis> <identifier>1730 #=======================================================================1731 if self._expression():1732 self._function_call_args1()1733 return True1734 elif self._ellipsis():1735 if not self._identifier():1736 self._append_error( FESyntaxErrors.ELLIPSIS_IDENT )1737 return True1738 else:1739 return False1740 #-------------------------------------------------------------------------1741 def _function_declaration(self) -> bool:1742 #=======================================================================1743 # <function declaration> ::= <template def> <function declaration'>1744 # | <function declaration'>1745 #=======================================================================1746 if self._template_def():1747 return self._function_declaration1()1748 else:1749 return self._function_declaration1()1750 #-------------------------------------------------------------------------1751 def _function_declaration1(self) -> bool:1752 #=======================================================================1753 # <function declaration'> ::= <function args declaration>1754 #=======================================================================1755 return self._function_args_declaration()1756 #-------------------------------------------------------------------------1757 def _function_definition(self) -> bool:1758 #=======================================================================1759 # <function definition> ::= <template def> <function definition'>1760 # | <function definition'>1761 #=======================================================================1762 if self._template_def():1763 return self._function_definition1()1764 else:1765 return self._function_definition1()1766 #-------------------------------------------------------------------------1767 def _function_definition1(self) -> bool:1768 #=======================================================================1769 # <function definition'> ::= <function args declaration> <function definition"> <statements block>1770 #=======================================================================1771 if not self._function_args_declaration():1772 self._append_error( FESyntaxErrors.FUNCTION_ARGS )1773 self._function_definition2()1774 if not self._statements_block():1775 self._append_error( FESyntaxErrors.FUNCTION_BODY )1776 return True 1777 #-------------------------------------------------------------------------1778 def _function_definition2(self) -> bool:1779 #=======================================================================1780 # <function definition"> ::= 'exclude' <languages> | EPS1781 #=======================================================================1782 if self._current.is_EXCLUDE():1783 if not self._languages():1784 self._append_error( FESyntaxErrors.LANGUAGES_LIST )1785 return True1786 #-------------------------------------------------------------------------1787 def _fwd_class_decl(self) -> bool:1788 #=======================================================================1789 # <fwd class decl> ::= 'class' <identifier> <template def> <fwd class decl'>1790 # <fwd class decl'> ::= <inheritance>1791 # | EPS1792 #=======================================================================1793 if self._current.is_CLASS():1794 self._append_syntaxic_node()1795 self._next_token_node()1796 if not self._identifier():1797 self._append_error( FESyntaxErrors.CLASS_NAME )1798 self._template_def()1799 return self._inheritance()1800 else:1801 return False1802 #-------------------------------------------------------------------------1803 def _fwd_decl_constructor(self) -> bool:1804 #=======================================================================1805 # <fwd decl constructor> ::= <dotted name'> <forward decl''''>1806 # | <function declaration'>1807 #=======================================================================1808 if self._dotted_name1():1809 if not self._forward_decl4():1810 self._append_error( FESyntaxErrors.FORWARD_DECL_FUNC_VAR_OP )1811 return True1812 else:1813 return self._function_declaration1()1814 #-------------------------------------------------------------------------1815 def _fwd_var_decl(self) -> bool:1816 #=======================================================================1817 # <fwd var decl> ::= ',' <identifier> <fwd var decl>1818 # | EPS1819 #=======================================================================1820 while self._current.is_COMMA():1821 self._append_syntaxic_node()1822 self._next_token_node()1823 if not self._identifier():1824 self._append_error( FESyntaxErrors.FORWARD_VARS_LIST )1825 return True 1826 #-------------------------------------------------------------------------1827 def _generic_scalar_type(self) -> bool:1828 #=======================================================================1829 # <generic scalar type> ::= '_float_' 1830 # | '_int_' 1831 # | '_numeric_' 1832 # | '_uint_' 1833 #=======================================================================1834 if self._current.is_GENRIC_SCALAR_TYPE(): ## (notice: previously scanned by Front-End Scanner)1835 self._append_syntaxic_node()1836 self._next_token_node()1837 return True1838 else:1839 return False1840 #-------------------------------------------------------------------------1841 def _identifier(self) -> bool:1842 #=======================================================================1843 # <identifier> ::= '_' <identifier'>1844 # | <alpha char> <identifier'>1845 # <identifier'> ::= <alpha num char> <identifier'>1846 # | '_' <identifier'>1847 # | EPS1848 #=======================================================================1849 if self._current.is_IDENT():1850 self._append_syntaxic_node()1851 self._next_token_node()1852 return True1853 else:1854 self._append_error( 'missing or incorrect identifier' )1855 return True1856 #-------------------------------------------------------------------------1857 def _identifiers_list(self) -> bool:1858 #=======================================================================1859 # <identifiers list> ::= <dotted name> <identifiers list'>1860 #=======================================================================1861 if self._current._dotted_name():1862 return self._identifiers_list1() ## (notice: always returns True)1863 else:1864 return False1865 #-------------------------------------------------------------------------1866 def _identifiers_list1(self) -> bool:1867 #=======================================================================1868 # <identifiers list'> ::= ',' <dotted name> <identifiers list'>1869 # | EPS1870 #=======================================================================1871 while self._current.is_COMMA():1872 self._append_syntaxic_node()1873 self._next_token_node()1874 if not self._dotted_name():1875 self._append_error( FESyntaxErrors.LIST_COMMA_IDENT )1876 return True1877 #-------------------------------------------------------------------------1878 def _if_comprehension(self) -> bool:1879 #=======================================================================1880 # <if comprehension> ::= 'if' '(' <condition or unnamed func> ')' <iter comprehension>1881 #=======================================================================1882 if self._current.is_IF():1883 self._append_syntaxic_node()1884 self._next_token_node()1885 if self._current.is_PAROP():1886 self._append_syntaxic_node()1887 self._next_token_node()1888 else:1889 self._append_error( FESyntaxErrors.IF_CONDITION_BEGIN )1890 if not self._condition_or_unnamed_func():1891 self._append_error( FESyntaxErrors.IF_COMPR_COND )1892 if self._current.is_PARCL():1893 self._append_syntaxic_node()1894 self._next_token_node()1895 else:1896 self._append_error( FESyntaxErrors.IF_CONDITION_END )1897 self._iter_comprehension()1898 return True1899 else:1900 return False1901 #-------------------------------------------------------------------------1902 def _if_statement(self) -> bool:1903 #=======================================================================1904 # <if statement> ::= 'if' '(' <expression> ')' <statements block> <if statement'>1905 #=======================================================================1906 if self._current.is_IF():1907 self._append_syntaxic_node()1908 self._next_token_node()1909 if self._current.is_PAROP():1910 self._append_syntaxic_node()1911 self._next_token_node()1912 else:1913 self._append_error( FESyntaxErrors.IF_CONDITION_BEGIN )1914 if not self._expression():1915 self._append_error( FESyntaxErrors.IF_COND )1916 if self._current.is_PARCL():1917 self._append_syntaxic_node()1918 self._next_token_node()1919 else:1920 self._append_error( FESyntaxErrors.IF_CONDITION_END )1921 if not self._statements_block():1922 self._append_error( FESyntaxErrors.IF_BODY )1923 self._if_statement1() ## (notice: always returns True)1924 return True1925 else:1926 return False1927 #-------------------------------------------------------------------------1928 def _if_statement1(self) -> bool:1929 #=======================================================================1930 # <if statement'> ::= 'elseif' '(' <expression> ')' <statements block> <if statement'>1931 # | 'elif' '(' <expression> ')' <statements block> <if statement'>1932 # | 'elsif' '(' <expression> ')' <statements block> <if statement'>1933 # | 'else' <statements block>1934 # | 'otherwise' <statements block>1935 # | EPS1936 #=======================================================================1937 while self._current.is_ELIF():1938 self._append_syntaxic_node()1939 self._next_token_node()1940 if self._current.is_PAROP():1941 self._append_syntaxic_node()1942 self._next_token_node()1943 else:1944 self._append_error( FESyntaxErrors.ELIF_CONDITION_BEGIN )1945 if not self._expression():1946 self._append_error( FESyntaxErrors.ELIF_COND )1947 if self._current.is_PARCL():1948 self._append_syntaxic_node()1949 self._next_token_node()1950 else:1951 self._append_error( FESyntaxErrors.ELIF_CONDITION_END )1952 if not self._statements_block():1953 self._append_error( FESyntaxErrors.ELIF_BODY )1954 if self._current.is_ELSE() or self._current.is_OTHERWISE():1955 self._append_syntaxic_node()1956 self._next_token_node()1957 if not self._statements_block():1958 self._append_error( FESyntaxErrors.ELSE_BODY if self._current.is_ELSE()1959 else FESyntaxErrors.OTHERWISE_BODY )1960 return True1961 #-------------------------------------------------------------------------1962 def _import_as_name(self) -> bool:1963 #=======================================================================1964 # <import as name> ::= <identifier> <import as name'>1965 #=======================================================================1966 if self._identifier():1967 return self._import_as_name1() ## (notice: always returns True)1968 else:1969 return False1970 #-------------------------------------------------------------------------1971 def _import_as_name1(self) -> bool:1972 #=======================================================================1973 # <import as name'> ::= 'as' <identifier>1974 # | EPS1975 #=======================================================================1976 if self._current.is_AS():1977 self._append_syntaxic_node()1978 self._next_token_node()1979 if not self._identifier():1980 self._append_error( FESyntaxErrors.AS_IDENT )1981 return True1982 #-------------------------------------------------------------------------1983 def _import_as_names(self) -> bool:1984 #=======================================================================1985 # <import as names> ::= <import as name> <import as names'>1986 #=======================================================================1987 if self._import_as_name():1988 self._import_as_names1() ## (notice: always returns True)1989 return True1990 else:1991 return False1992 #-------------------------------------------------------------------------1993 def _import_as_names1(self) -> bool:1994 #=======================================================================1995 # <import as names'> ::= ',' <import as name> <import as names'>1996 # | EPS1997 #=======================================================================1998 while self._current.is_COMMA():1999 self._append_syntaxic_node()2000 self._next_token_node()2001 if not self._import_as_name():2002 self._append_error( FESyntaxErrors.IMPORT_IDENT )2003 return True2004 #-------------------------------------------------------------------------2005 def _import_but(self) -> bool:2006 #===============================================================================2007 # <import but> ::= 'but' <identifier> <import but'>2008 # | EPS2009 #===============================================================================2010 if self._current.is_BUT():2011 self._append_syntaxic_node()2012 self._next_token_node()2013 if not self._identifier():2014 self._append_error( FESyntaxErrors.IMPORT_BUT_IDENT )2015 return self._import_but1()2016 return True2017 #-------------------------------------------------------------------------2018 def _import_but1(self) -> bool:2019 #===============================================================================2020 # <import but'> ::= ',' <identifier> <import but'>2021 # | EPS2022 #===============================================================================2023 while self._current.is_COMMA():2024 self._append_syntaxic_node()2025 self._next_token_node()2026 if not self._identifier():2027 self._append_error( FESyntaxErrors.IMPORT_BUT_COMMA_IDENT )2028 return True2029 #-------------------------------------------------------------------------2030 def _import_from(self) -> bool:2031 #=======================================================================2032 # <import from> ::= 'from' <import from'>2033 #=======================================================================2034 if self._current.is_FROM():2035 self._append_syntaxic_node()2036 self._next_token_node()2037 self._import_from1() ## (notice: always returns True)2038 return True2039 else:2040 return False2041 #-------------------------------------------------------------------------2042 def _import_from1(self) -> bool:2043 #=======================================================================2044 # <import from'> ::= '.' <import from'>2045 # | <import from''>2046 #=======================================================================2047 while self._current.is_DOT():2048 self._append_syntaxic_node()2049 self._next_token_node()2050 return self._import_from2() ## (notice: always returns True)2051 #-------------------------------------------------------------------------2052 def _import_from2(self) -> bool:2053 #=======================================================================2054 # <import from''> ::= <dotted name> 'import' <import from'''>2055 #=======================================================================2056 if not self._dotted_name():2057 self._append_error( FESyntaxErrors.FROM_IDENT_IMPORT )2058 if self._current.is_IMPORT():2059 self._append_syntaxic_node()2060 self._next_token_node()2061 else:2062 self._append_error( FESyntaxErrors.FROM_IMPORT )2063 if not self._import_from3():2064 self._append_error( FESyntaxErrors.FROM_IMPORT_IDENT )2065 return True2066 #-------------------------------------------------------------------------2067 def _import_from3(self) -> bool:2068 #=======================================================================2069 # <import from'''> ::= 'all' <import but>2070 # | '(' <import as names> ')'2071 # | <import as names>2072 #=======================================================================2073 if self._current.is_ALL():2074 self._append_syntaxic_node()2075 self._next_token_node()2076 return self._import_but()2077 elif self._current.is_PAROP():2078 self._append_syntaxic_node()2079 self._next_token_node()2080 if not self._import_as_names():2081 self._append_error( FESyntaxErrors.FROM_IMPORT_LIST )2082 if self._current.is_PARCL():2083 self._append_syntaxic_node()2084 self._next_token_node()2085 else:2086 self._append_error( FESyntaxErrors.UNPAIRED_PAROP )2087 return True2088 elif self._import_as_names():2089 return True2090 else:2091 return False2092 #-------------------------------------------------------------------------2093 def _import_name(self) -> bool:2094 #=======================================================================2095 # <import name> ::= 'import' <dotted as names>2096 #=======================================================================2097 if self._current.is_IMPORT():2098 self._append_syntaxic_node()2099 self._next_token_node()2100 if not self._dotted_as_names():2101 self._append_error( FESyntaxErrors.IMPORT_MODULE )2102 return True2103 else:2104 return False2105 #-------------------------------------------------------------------------2106 def _import_statement(self) -> bool:2107 #=======================================================================2108 # <import statement> ::= <import name>2109 # | <import from>2110 #=======================================================================2111 return self._import_name() or self._import_from()2112 #-------------------------------------------------------------------------2113 def _incr_or_decr(self) -> bool:2114 #=======================================================================2115 # <incr or decr> ::= '--' | '++' | EPS2116 #=======================================================================2117 if self._current.is_INCR() or self._current.is_DECR():2118 self._append_syntaxic_node()2119 self._next_token_node()2120 return True2121 #-------------------------------------------------------------------------2122 def _inheritance(self) -> bool:2123 #=======================================================================2124 # <inheritance> ::= ':' <inheritance item> <inheritance'>2125 # | EPS2126 #=======================================================================2127 if self._current.is_COLON():2128 self._append_syntaxic_node()2129 self._next_token_node()2130 if not self._inheritance_item():2131 self._append_error( FESyntaxErrors.INHERITANCE_CLASS )2132 self._inheritance1()2133 return True2134 2135 #-------------------------------------------------------------------------2136 def _inheritance1(self) -> bool:2137 #=======================================================================2138 # <inheritance'> ::= ',' <inheritence item> <inheritance'>2139 # | EPS2140 #=======================================================================2141 while self._current.is_COMMA():2142 self._append_syntaxic_node()2143 self._next_token_node()2144 if not self._inheritance_item():2145 self._append_error( FESyntaxErrors.INHERITANCE_CLASS )2146 return True2147 #-------------------------------------------------------------------------2148 def _inheritance_item(self) -> bool:2149 #=======================================================================2150 # <inheritance item> ::= <access qualifier> <inheritance item'>2151 # | <inheritance item'>2152 #=======================================================================2153 if self._access_qualifier():2154 return self._inheritance_item1()2155 else:2156 return self._inheritance_item1()2157 #-------------------------------------------------------------------------2158 def _inheritance_item1(self) -> bool:2159 #=======================================================================2160 # <inheritance item'> ::= <dotted name> <template args>2161 #=======================================================================2162 if self._dotted_name():2163 self._template_args()2164 return True2165 else:2166 return False2167 #-------------------------------------------------------------------------2168 def _integer_number(self) -> bool:2169 #=======================================================================2170 # <integer number> ::= '1'...'9' <integer number'>2171 # | <octal hexa binary number>2172 #=======================================================================2173 if self._current.is_INTEGER(): ## (notice: previously scanned by Scanner)2174 self._append_syntaxic_node()2175 self._next_token_node()2176 return True2177 else:2178 return False2179 2180 #-------------------------------------------------------------------------2181 def _is_instance_of(self) -> bool:2182 #=======================================================================2183 # <is instance of> ::= '->' <dotted name>2184 #=======================================================================2185 if self._current.is_ISOF():2186 self._append_syntaxic_node()2187 self._next_token_node()2188 if not self._dotted_name():2189 self._append_error( FESyntaxErrors.INSTANCE_OF )2190 return True2191 else:2192 return False2193 #-------------------------------------------------------------------------2194 def _is_operator(self) -> bool:2195 #=======================================================================2196 # <is operator> ::= 'is' <is operator'>2197 #=======================================================================2198 if self._current.is_IS():2199 self._append_syntaxic_node()2200 self._next_token_node()2201 return self._is_operator1()2202 else:2203 return False2204 #-------------------------------------------------------------------------2205 def _is_operator1(self) -> bool:2206 #=======================================================================2207 # <is operator'> ::= 'not'2208 # | EPS2209 #=======================================================================2210 if self._current.is_NOT():2211 self._append_syntaxic_node()2212 self._next_token_node()2213 return True2214 #-------------------------------------------------------------------------2215 def _iter_comprehension(self) -> bool:2216 #=======================================================================2217 # <iter comprehension> ::= <for comprehension>2218 # | <if comprehension>2219 # | EPS2220 #=======================================================================2221 if self._for_comprehension():2222 return True2223 elif self._if_comprehension():2224 return True2225 else:2226 return True2227 #-------------------------------------------------------------------------2228 def _language(self) -> bool:2229 #=======================================================================2230 # <language> ::= 'cpp' | 'java' | 'python' | 'py' | 'javascript' | 'm6809'2231 #=======================================================================2232 if self._current.is_LANGUAGE(): ## (notice: previously scanned by the Scanner)2233 self._append_syntaxic_node()2234 self._next_token_node()2235 return True2236 else:2237 return False2238 #-------------------------------------------------------------------------2239 def _list_form(self) -> bool:2240 #=======================================================================2241 # <list form> ::= '[' <expression> <list or comprehension> ']'2242 #=======================================================================2243 if self._current.is_BRACKETOP():2244 self._append_syntaxic_node()2245 self._next_token_node()2246 if not self._expression():2247 self._append_error( FESyntaxErrors.LIST_EXPR )2248 self._list_or_comprehension()2249 if self._current.is_BRACKETCL():2250 self._append_syntaxic_node()2251 self._next_token_node()2252 else:2253 self._append_error( FESyntaxErrors.LIST_END )2254 return True2255 else:2256 return False2257 #-------------------------------------------------------------------------2258 def _list_or_comprehension(self) -> bool:2259 #=======================================================================2260 # <list or comprehension> ::= <expr list'>2261 # | <for comprehension>2262 # | EPS2263 #=======================================================================2264 if self._expr_list1() or self._for_comprehension():2265 return True2266 else:2267 return True2268 #-------------------------------------------------------------------------2269 def _list_or_map_form(self) -> bool:2270 #=======================================================================2271 # <list or map form> ::= <list form>2272 # | <map form>2273 #=======================================================================2274 return self._list_form() or self._map_form()2275 #-------------------------------------------------------------------------2276 def _list_type(self) -> bool:2277 #=======================================================================2278 # <list type> ::= "list" <contained type>2279 #=======================================================================2280 if self._current.is_LIST():2281 self._append_syntaxic_node()2282 self._next_token_node()2283 self._contained_type() ## (notice: always returns True)2284 return True2285 else:2286 return False2287 #-------------------------------------------------------------------------2288 def _list_type1(self) -> bool:2289 #=======================================================================2290 # <list type'> ::= <declared contained type>2291 # | EPS2292 #=======================================================================2293 if self._declared_contained_type():2294 return True2295 else:2296 return True2297 #-------------------------------------------------------------------------2298 def _map_form(self) -> bool:2299 #=======================================================================2300 # <map form> ::= ':' <expression> <map list or comprehension>2301 #=======================================================================2302 if self._current.is_COLON():2303 self._append_syntaxic_node()2304 self._next_token_node()2305 if not self._expression():2306 self._append_error( FESyntaxErrors.MAP_EXPR )2307 if not self._map_list_or_comprehension():2308 self._append_error( FESyntaxErrors.MAP_LIST_COMPR )2309 return True2310 else:2311 return False2312 #-------------------------------------------------------------------------2313 def _map_item(self) -> bool:2314 #=======================================================================2315 # <map item> ::= <expression> ':' <expression>2316 #=======================================================================2317 if self._expression():2318 if self._current.is_COLON():2319 self._append_syntaxic_node()2320 self._next_token_node()2321 else:2322 self._append_error( FESyntaxErrors.MAP_ITEM_SEP )2323 if not self._expression():2324 self._append_error( FESyntaxErrors.MAP_EXPR )2325 return True2326 else:2327 return False2328 #-------------------------------------------------------------------------2329 def _map_list(self) -> bool:2330 #=======================================================================2331 # <map list> ::= ',' <map item> <map list>2332 # | EPS2333 #=======================================================================2334 while self._current.is_COMMA():2335 self._append_syntaxic_node()2336 self._next_token_node()2337 if not self._map_item():2338 self._append_error( FESyntaxErrors.MAP_LIST_ITEM )2339 return True2340 #-------------------------------------------------------------------------2341 def _map_list_or_comprehension(self) -> bool:2342 #=======================================================================2343 # <map list or comprehension> ::= ',' <map item> <map list>2344 # | <for comprehension>2345 #=======================================================================2346 if self._current.is_COMMA():2347 self._append_syntaxic_node()2348 self._next_token_node()2349 if not self._map_item():2350 self._append_error( FESyntaxErrors.MAP_LIST_ITEM )2351 self._map_list()2352 return True2353 else:2354 return self._for_comprehension()2355 #-------------------------------------------------------------------------2356 def _map_contained_types(self) -> bool:2357 #=======================================================================2358 # <map contained types> ::= '<' <TYPE> <map contained types'>2359 # | EPS2360 #=======================================================================2361 if self._current.is_LT():2362 self._append_syntaxic_node()2363 self._next_token_node()2364 if not self._TYPE():2365 self._append_error( FESyntaxErrors.MAP_CONTAINED_TYPE )2366 return self._map_contained_types_1()2367 else:2368 return False2369 #-------------------------------------------------------------------------2370 def _map_contained_types_1(self) -> bool:2371 #=======================================================================2372 # <map contained types'> ::= ',' <TYPE> '>'2373 # | '>'2374 #=======================================================================2375 if self._current.is_COMMA():2376 self._append_syntaxic_node()2377 self._next_token_node()2378 if not self._TYPE():2379 self._append_error( FESyntaxErrors.MAP_CONTAINED_VALUE_TYPE )2380 if self._current.is_GT():2381 self._append_syntaxic_node()2382 self._next_token_node()2383 else:2384 self._append_error( FESyntaxErrors.MAP_CONTAINED_TYPE_END )2385 return True2386 #-------------------------------------------------------------------------2387 def _map_type(self) -> bool:2388 #=======================================================================2389 # <<map type> ::= "map" <map contained types>2390 #=======================================================================2391 if self._current.is_MAP():2392 self._append_syntaxic_node()2393 self._next_token_node()2394 self._map_contained_types() ## (notice: always returns True)2395 return True2396 else:2397 return False2398 #-------------------------------------------------------------------------2399 def _me(self) -> bool:2400 #=======================================================================2401 # <ME> ::= 'me'2402 #=======================================================================2403 if self._current.is_ME():2404 self._append_syntaxic_node()2405 self._next_token_node()2406 return True2407 else:2408 return False2409 #-------------------------------------------------------------------------2410 def _memory_address(self) -> bool:2411 #=======================================================================2412 # <memory address> ::= '@' <integer number>2413 # | EPS2414 #=======================================================================2415 if self._current.is_AROBASE():2416 self._append_syntaxic_node()2417 self._next_token_node()2418 if not self._integer_number():2419 self._append_error( FESyntaxErrors.VOLATILE_MEM_ADDR )2420 return True2421 #-------------------------------------------------------------------------2422 def _method_or_operator_definition(self) -> bool:2423 #=======================================================================2424 # <method or operator definition> ::= <returned type> <method or operator definition'>2425 #=======================================================================2426 if self._returned_type():2427 if not self._method_or_operator_definition1():2428 self._append_error( FESyntaxErrors.METHOD_OPERATOR )2429 return True2430 else:2431 return False2432 #-------------------------------------------------------------------------2433 def _method_or_operator_definition1(self) -> bool:2434 #=======================================================================2435 # <method or operator definition'> ::= <operator definition>2436 # | <identifier> <function definition>2437 #=======================================================================2438 if self._operator_definition():2439 return True2440 elif self._current.is_IDENT():2441 self._append_syntaxic_node()2442 self._next_token_node()2443 self._function_definition() ## (notice: always returns True)2444 return True2445 else:2446 return False2447 #-------------------------------------------------------------------------2448 def _new_line(self) -> bool:2449 if self._current.is_NL():2450 self._append_syntaxic_node()2451 self._next_token_node()2452 return True2453 else:2454 return False2455 #-------------------------------------------------------------------------2456 def _none(self) -> bool:2457 #=======================================================================2458 # <NONE> ::= "None"2459 # | "none"2460 #=======================================================================2461 if self._current.is_NONE():2462 self._append_syntaxic_node()2463 self._next_token_node()2464 return True2465 else:2466 return False2467 #-------------------------------------------------------------------------2468 def _nop_statement(self) -> bool:2469 #=======================================================================2470 # <nop statement> ::= 'nop'2471 # | 'pass'2472 #=======================================================================2473 if self._current.is_NOP():2474 self._append_syntaxic_node()2475 self._next_token_node()2476 return True2477 else:2478 return False2479 #-------------------------------------------------------------------------2480 def _not_test(self) -> bool:2481 #=======================================================================2482 # <not test> ::= 'not' <not test>2483 # | <comparison>2484 #=======================================================================2485 if self._current.is_NOT():2486 while self._current.is_NOT():2487 self._append_syntaxic_node()2488 self._next_token_node()2489 if not self._comparison():2490 self._append_error( FESyntaxErrors.NOT_COND )2491 return True2492 else:2493 return self._comparison()2494 #-------------------------------------------------------------------------2495 def _operator(self) -> bool:2496 #=======================================================================2497 # <operator> ::= '<=' | '==' | '!=' | '>='2498 # | '+' | '-' | '*' | '/' | '%' | '**' | '^^'2499 # | '&' | '|' | '^' | '@'2500 # | '@@' | '><' | '<>' | '::' | '!!'2501 # | '++' | '--' | '#'2502 # | 'in'2503 # | <assign op>2504 # | <cast op>2505 #=======================================================================2506 if isinstance( self._current, (ICTokenNode_LE , ICTokenNode_EQ ,2507 ICTokenNode_NE , ICTokenNode_GE ,2508 ICTokenNode_PLUS , ICTokenNode_MINUS ,2509 ICTokenNode_MUL , ICTokenNode_DIV ,2510 ICTokenNode_MOD , ICTokenNode_POWER ,2511 ICTokenNode_BITAND , ICTokenNode_BITOR ,2512 ICTokenNode_BITXOR , ICTokenNode_AROBASE ,2513 ICTokenNode_OP_2AROB, ICTokenNode_OP_GRLE ,2514 ICTokenNode_OP_LEGR , ICTokenNode_OP_2COLN,2515 ICTokenNode_OP_2EXCL, ICTokenNode_INCR ,2516 ICTokenNode_DECR , ICTokenNode_HASH ,2517 ICTokenNode_IN ) ):2518 self._append_syntaxic_node()2519 self._next_token_node()2520 return True2521 elif self._assign_op():2522 return True2523 elif self._cast_op():2524 return True2525 else:2526 return False2527 #-------------------------------------------------------------------------2528 def _operator1(self) -> bool:2529 #=======================================================================2530 # <operator'> ::= '<' | '>' | '<<' | '<<<' | '>>' | '>>>' | '<=>'2531 #=======================================================================2532 if isinstance( self._current, (ICTokenNode_LT , ICTokenNode_GT ,2533 ICTokenNode_SHIFTL, ICTokenNode_SHIFT0L,2534 ICTokenNode_SHIFTR, ICTokenNode_SHIFT0R,2535 ICTokenNode_LEG ) ):2536 self._append_syntaxic_node()2537 self._next_token_node()2538 return True2539 else:2540 return False2541 #-------------------------------------------------------------------------2542 def _operator_definition(self) -> bool:2543 #=======================================================================2544 # <operator definition> ::= 'operator' <operator definition'>2545 #=======================================================================2546 if self._current.is_OPERATOR():2547 self._append_syntaxic_node()2548 self._next_token_node()2549 if not self._operator_definition1():2550 self._append_error( FESyntaxErrors.OPERATOR_OP )2551 return True2552 else:2553 return False2554 #-------------------------------------------------------------------------2555 def _operator_definition1(self) -> bool:2556 #=======================================================================2557 # <operator definition'> ::= <operator> <template def> <function args declaration> <statements block>2558 # | <operator'> <spaced template def> <function args declaration> <statements block>2559 # | <call operator> <template def> <statements block>2560 #=======================================================================2561 def _my_cont(check_args:bool) -> bool:2562 if check_args and not self._function_args_declaration():2563 self._append_error( FESyntaxErrors.OPERATOR_ARGS )2564 if not self._statements_block():2565 self._append_error( FESyntaxErrors.OPERATOR_BODY )2566 return True2567 if self._operator():2568 self._template_def()2569 return _my_cont( True )2570 elif self._operator1():2571 self._spaced_template_def()2572 return _my_cont( True )2573 elif self._call_operator():2574 self._template_def()2575 return _my_cont( False )2576 else:2577 return False2578 #-------------------------------------------------------------------------2579 def _or_test(self) -> bool:2580 #=======================================================================2581 # <or test> ::= <and test> <or test'>2582 #=======================================================================2583 return self._and_test() and self._or_test1()2584 #-------------------------------------------------------------------------2585 def _or_test1(self) -> bool:2586 #=======================================================================2587 # <or test'> ::= 'or' <and test>2588 # | EPS2589 #=======================================================================2590 if self._current.is_OR():2591 self._append_syntaxic_node()2592 self._next_token_node()2593 if not self._and_test():2594 self._append_error( FESyntaxErrors.OR_TEST )2595 return True2596 else:2597 return True2598 #-------------------------------------------------------------------------2599 def _parenthesis_form(self) -> bool:2600 #=======================================================================2601 # <parenthesis form> ::= '(' <expr list> ')'2602 #=======================================================================2603 if self._current.is_PAROP():2604 self._append_syntaxic_node()2605 self._next_token_node()2606 if not self._expr_list():2607 self._append_error( FESyntaxErrors.PARENTH_EXPR )2608 if self._current.is_PARCL():2609 self._append_syntaxic_node()2610 self._next_token_node()2611 else:2612 self._append_error( FESyntaxErrors.UNPAIRED_PAROP )2613 return True2614 else:2615 return False2616 #-------------------------------------------------------------------------2617 def _parse_code_file(self) -> tuple(FEICTree,int):2618 #=======================================================================2619 # <code file> ::= <statements list> <ENDOFFILE>2620 #=======================================================================2621 # first, initializations2622 self._out_syntax_ic = FEICTree()2623 self._errors_count = 02624 2625 # then, let's parse the module file2626 self._statements_list()2627 if not self._end_of_file():2628 self._append_error( FESyntaxErrors.END_OF_FILE )2629 2630 # finally, let's return the parsing results2631 return (self._out_syntax_ic, self._errors_count)2632 #-------------------------------------------------------------------------2633 def _raise_statement(self) -> bool:2634 #=======================================================================2635 # <raise statement> ::= 'raise' <expression> <raise statement'>2636 #=======================================================================2637 if self._current.is_RAISE():2638 self._append_syntaxic_node()2639 self._next_token_node()2640 if not self._expression():2641 self._append_error( FESyntaxErrors.RAISE_EXPR )2642 self._raise_statement1() ## (notice: always returns True)2643 return True2644 else:2645 return False2646 #-------------------------------------------------------------------------2647 def _raise_statement1(self) -> bool:2648 #=======================================================================2649 # <raise statement'> ::= 'from' <expression>2650 # | EPS2651 #=======================================================================2652 if self._current.is_FROM():2653 self._append_syntaxic_node()2654 self._next_token_node()2655 if not self._expression():2656 self._append_error( FESyntaxErrors.RAISE_FROM_EXPR )2657 return True2658 else:2659 return True2660 #-------------------------------------------------------------------------2661 def _reference(self) -> bool:2662 #=======================================================================2663 # <reference> ::= '@' <dotted name>2664 #=======================================================================2665 if self._current.is_AROBASE():2666 self._append_syntaxic_node()2667 self._next_token_node()2668 if not self._dotted_name():2669 self._append_error( FESyntaxErrors.REF_IDENT )2670 return True2671 else:2672 return False2673 #-------------------------------------------------------------------------2674 def _repeat_statement(self) -> bool:2675 #=======================================================================2676 # <repeat statement> ::= 'repeat' <statements block> 'until' '(' <expression> ')' <simple statement end>2677 #=======================================================================2678 if self._current.is_REPEAT():2679 self._append_syntaxic_node()2680 self._next_token_node()2681 if not self._statements_block():2682 self._append_error( FESyntaxErrors.REPEAT_BODY )2683 if self._current.is_UNTIL():2684 self._append_syntaxic_node()2685 self._next_token_node()2686 else:2687 self._append_error( FESyntaxErrors.REPEAT_UNTIL )2688 if self._current.is_PAROP():2689 self._append_syntaxic_node()2690 self._next_token_node()2691 else:2692 self._append_error( FESyntaxErrors.UNTIL_BEGIN )2693 if not self._expression():2694 self._append_error( FESyntaxErrors.UNTIL_EXPR )2695 if self._current.is_PARCL():2696 self._append_syntaxic_node()2697 self._next_token_node()2698 else:2699 self._append_error( FESyntaxErrors.UNTIL_END )2700 if self._simple_statement_end():2701 self._append_syntaxic_node()2702 self._next_token_node()2703 else:2704 self._append_error( FESyntaxErrors.UNTIL_STATEMENT_END )2705 return True2706 else:2707 return False2708 #-------------------------------------------------------------------------2709 def _require_statement(self) -> bool:2710 #=======================================================================2711 # <require statement> ::= 'require' <expression> <require statement'>2712 #=======================================================================2713 if self._current.is_REQUIRE():2714 self._append_syntaxic_node()2715 self._next_token_node()2716 if not self._expression():2717 self._append_error( FESyntaxErrors.REQUIRE_EXPR )2718 self._require_statement1() ## (notice: always returns True)2719 return True2720 else:2721 return False2722 #-------------------------------------------------------------------------2723 def _require_statement1(self) -> bool:2724 #=======================================================================2725 # <require statement'> ::= ',' <expression>2726 # | EPS2727 #=======================================================================2728 if self._current.is_COMMA():2729 self._append_syntaxic_node()2730 self._next_token_node()2731 if not self._expression():2732 self._append_error( FESyntaxErrors.REQUIRE_COMMA_EXPR )2733 return True 2734 #-------------------------------------------------------------------------2735 def _return_statement(self) -> bool:2736 #=======================================================================2737 # <return statement> ::= 'ret' <return statement'>2738 # | 'return' <return statement'>2739 #=======================================================================2740 if self._current.is_RETURN():2741 self._append_syntaxic_node()2742 self._next_token_node()2743 self._return_statement1() ## (notice: always returns True)2744 return True2745 else:2746 return False2747 #-------------------------------------------------------------------------2748 def _return_statement1(self) -> bool:2749 #=======================================================================2750 # <return statement'> ::= <expr list>2751 # | EPS2752 #=======================================================================2753 self._expr_list()2754 return True2755 #-------------------------------------------------------------------------2756 def _returned_type(self) -> bool:2757 #=======================================================================2758 # <returned type> ::= <TYPE>2759 # | EPS2760 #=======================================================================2761 if self._TYPE():2762 return True2763 else:2764 return True2765 #-------------------------------------------------------------------------2766 def _scalar(self) -> bool:2767 #=======================================================================2768 # <scalar> ::= <decimal number>2769 # | <octal hexa binary number>2770 #=======================================================================2771 if self._current.is_INTEGER() or self._current.is_FLOAT(): ## (notice: previously scanned by Scanner)2772 self._append_syntaxic_node()2773 self._next_token_node()2774 return True2775 else:2776 return False2777 #-------------------------------------------------------------------------2778 def _scalar_type(self) -> bool:2779 #=======================================================================2780 # <scalar type> ::= <scalar type'> | <generic scalar type>2781 #=======================================================================2782 return self._scalar_type1() or self._generic_scalar_type()2783 #-------------------------------------------------------------------------2784 def _scalar_type1(self) -> bool:2785 #=======================================================================2786 # <scalar type'> ::= "bool"2787 # | "char"2788 # | "char16"2789 # | "float32"2790 # | "float64"2791 # | "int8"2792 # | "int16"2793 # | "int32"2794 # | "int64"2795 # | "slice"2796 # | "str"2797 # | "str16"2798 # | "uint8"2799 # | "uint16"2800 # | "uint32"2801 # | "uint64"2802 # | "_float_"2803 # | "_int_"2804 # | "_numeric_"2805 # | "_uint_"2806 #=======================================================================2807 if self._current.is_SCALAR_TYPE(): ## (notice: previously scanned by Front-End Scanner)2808 self._append_syntaxic_node()2809 self._next_token_node()2810 return True2811 else:2812 return False2813 #-------------------------------------------------------------------------2814 def _scalar_type_or_dotted_name(self) -> bool:2815 #=======================================================================2816 # <scalar type or dotted name> ::= <scalar type>2817 # | <dotted name>2818 #=======================================================================2819 return self._scalar_type() or self._dotted_name()2820 #-------------------------------------------------------------------------2821 def _set_type(self) -> bool:2822 #=======================================================================2823 # <set type> ::= "set" <contained type>2824 #=======================================================================2825 if self._current.is_SET():2826 self._append_syntaxic_node()2827 self._next_token_node()2828 self._contained_type() ## (notice: always returns True)2829 return True2830 else:2831 return False2832 #-------------------------------------------------------------------------2833 def _shift_expr(self) -> bool:2834 #=======================================================================2835 # <shift expr> ::= <arithmetic expr> <shift expr'>2836 #=======================================================================2837 if self._arithmetic_expr():2838 return self._shift_expr1()2839 else:2840 return False2841 #-------------------------------------------------------------------------2842 def _shift_expr1(self) -> bool:2843 #=======================================================================2844 # <shift expr'> ::= '<<' <spaced template args> <arithmetic expr> <shift expr'>2845 # | '>>' <template args> <arithmetic expr> <shift expr'>2846 # | '<<<' <spaced template args> <arithmetic expr> <shift expr'>2847 # | '>>>' <template args> <arithmetic expr> <shift expr'>2848 # | EPS2849 #=======================================================================2850 while True:2851 if self._current.is_SHIFTL() or self._current.is_SHIFT0L():2852 self._append_syntaxic_node()2853 self._next_token_node()2854 self._spaced_template_args()2855 elif self._current.is_SHIFTR() or self._current.is_SHIFT0R():2856 self._append_syntaxic_node()2857 self._next_token_node()2858 self._template_args()2859 else:2860 break2861 if not self._arithmetic_expr():2862 self._append_error( FESyntaxErrors.SHIFT_EXPR )2863 return True2864 #-------------------------------------------------------------------------2865 def _simple_statement(self) -> bool:2866 #=======================================================================2867 # <simple statement> ::= <assert statement> <simple statement end>2868 # | <del statement> <simple statement end>2869 # | <ensure statement> <simple statement end>2870 # | <file endianness>2871 # | <file flushing>2872 # | <flow statement> <simple statement end>2873 # | <import statement> <simple statement end>2874 # | <nop statement> <simple statement end>2875 # | <access protection statement> <simple statement end>2876 # | <raise statement> <simple statement end>2877 # | <require statement> <simple statement end>2878 #=======================================================================2879 if self._assert_statement() or \2880 self._del_statement() or \2881 self._ensure_statement() or \2882 self._file_endianness() or \2883 self._file_flushing() or \2884 self._flow_statement() or \2885 self._import_statement() or \2886 self._nop_statement() or \2887 self._access_protection_statement() or \2888 self._raise_statement() or \2889 self._require_statement():2890 if not self._simple_statement_end():2891 self._append_error( FESyntaxErrors.STATEMENT_END )2892 return True2893 else:2894 return False2895 #-------------------------------------------------------------------------2896 def _simple_statement_end(self) -> bool:2897 #=======================================================================2898 # <simple statement end> ::= ';'2899 #=======================================================================2900 if self._current.is_COMMA():2901 self._append_syntaxic_node()2902 self._next_token_node()2903 return True2904 else:2905 return False 2906 #-------------------------------------------------------------------------2907 def _slice_end(self) -> bool:2908 #=======================================================================2909 # <slice end> ::= ']'2910 # | ')'2911 #=======================================================================2912 if self._current.is_BRACKETCL() or self._current.is_PARCL():2913 self._append_syntaxic_node()2914 self._next_token_node()2915 else:2916 self._append_error( FESyntaxErrors.SLICE_END )2917 return True 2918 #-------------------------------------------------------------------------2919 def _slice_form(self) -> bool:2920 #=======================================================================2921 # <slice form> ::= ':' <slice upper> <slice step>2922 #=======================================================================2923 if self._current.is_COLON():2924 self._append_syntaxic_node()2925 self._next_token_node()2926 self._slice_upper()2927 self._slice_step()2928 return True2929 else:2930 return False2931 #-------------------------------------------------------------------------2932 def _slice_step(self) -> bool:2933 #=======================================================================2934 # <slice step> ::= ':' <slice step'>2935 # | EPS2936 #=======================================================================2937 if self._current.is_COLON():2938 self._append_syntaxic_node()2939 self._next_token_node()2940 self._slice_step1()2941 return True2942 #-------------------------------------------------------------------------2943 def _slice_step1(self) -> bool:2944 #=======================================================================2945 # <slice step'> ::= <expression>2946 # | EPS 2947 #=======================================================================2948 self._expression()2949 return True2950 #-------------------------------------------------------------------------2951 def _slice_upper(self) -> bool:2952 #=======================================================================2953 # <slice upper> ::= <expression>2954 # | EPS2955 #=======================================================================2956 self._expression()2957 return True2958 #-------------------------------------------------------------------------2959 def _spaced_template_args(self) -> bool:2960 #=======================================================================2961 # <spaced template args> ::= ' <' <template args'> '>'2962 # | EPS2963 #=======================================================================2964 return self._template_args() ## (notice: space before < is mandatory and has already be skipped by Scanner)2965 #-------------------------------------------------------------------------2966 def _spaced_template_def(self) -> bool:2967 #=======================================================================2968 # <spaced template def> ::= ' <' <template def'> '>'2969 # | EPS2970 #=======================================================================2971 return self._template_def() ## (notice: space before < is mandatory and has already be skipped by Scanner)2972 #-------------------------------------------------------------------------2973 def _statements_block(self) -> bool:2974 #=======================================================================2975 # <statements block> ::= '{' <statements list> '}'2976 # | <compound statement>2977 # | <empty statement> <statements block>2978 # | <simple statement>2979 #=======================================================================2980 if self._current.is_BRACEOP():2981 self._append_new_block()2982 self._next_token_node()2983 if self._statements_list():2984 if self._current.is_BRACECL():2985 self._append_syntaxic_node()2986 self._next_token_node()2987 else:2988 self._append_error( FESyntaxErrors.BODY_END )2989 self._up_to_parent_block()2990 return True2991 elif self._compound_statement() or self._simple_statement():2992 return True2993 elif self._empty_statement():2994 return self._statements_block()2995 else:2996 return False2997 #-------------------------------------------------------------------------2998 def _statements_list(self) -> bool:2999 #===============================================================================3000 # <statements list> ::= <empty statement> <statements list>3001 # | <compound statement> <statements list>3002 # | <simple statement> <statements list>3003 # | <statements block> <statements list>3004 # | EPS3005 #===============================================================================3006 while self._empty_statement() or \3007 self._compound_statement() or \3008 self._simple_statement() or \3009 self._statements_block():3010 pass3011 return True3012 #-------------------------------------------------------------------------3013 def _static_qualifier(self) -> bool:3014 #=======================================================================3015 # <static qualifier> ::= "static"3016 #=======================================================================3017 if self._current.is_STATIC():3018 self._append_syntaxic_node()3019 self._next_token_node()3020 return True3021 else:3022 return False 3023 #-------------------------------------------------------------------------3024 def _string(self) -> bool:3025 #=======================================================================3026 # <string> ::= <single string> <string'> <string methods>3027 #=======================================================================3028 if self._current.is_STRING(): ## (notice: previously scanned by Scanner)3029 self._append_syntaxic_node()3030 self._next_token_node()3031 self._string1() ## (notice: always returns True)3032 self._string_methods() ## (notice: always returns True)3033 return True3034 else:3035 return False3036 #-------------------------------------------------------------------------3037 def _string1(self) -> bool:3038 #=======================================================================3039 # <string'> ::= <single string> <string'>3040 # | EPS3041 #=======================================================================3042 while self._current.is_STRING(): ## (notice: previously scanned by Scanner)3043 self._append_syntaxic_node()3044 self._next_token_node()3045 return True3046 #-------------------------------------------------------------------------3047 def _string_methods(self) -> bool:3048 #=======================================================================3049 # <string methods> ::= '.' <identifier> <function call> <string methods'>3050 # | EPS3051 #=======================================================================3052 if self._current.is_DOT():3053 self._append_syntaxic_node()3054 self._next_token_node()3055 if not self._identifier():3056 self._append_error( FESyntaxErrors.STRING_FUNC_IDENT )3057 if not self._function_call():3058 self._append_error( FESyntaxErrors.STRING_FUNC_ARGS )3059 return self._string_methods1() ## (notice: always returns True)3060 else:3061 return True3062 #-------------------------------------------------------------------------3063 def _string_methods1(self) -> bool:3064 #=======================================================================3065 # <string methods'> ::= '.' <identifier> <function call> <string methods'>3066 # | EPS3067 #=======================================================================3068 while self._current.is_DOT():3069 self._next_token_node()3070 if not self._identifier():3071 self._append_error( FESyntaxErrors.STRING_FUNC_IDENT )3072 if not self._function_call():3073 self._append_error( FESyntaxErrors.STRING_FUNC_ARGS )3074 return True3075 #-------------------------------------------------------------------------3076 def _subscription_or_slicing(self) -> bool:3077 #=======================================================================3078 # <subscription or slicing> ::= '[' <expression> <subscription or slicing'>3079 #=======================================================================3080 if self._current.is_BRACKETOP():3081 self._append_syntaxic_node()3082 self._next_token_node()3083 if not self._expression():3084 self._append_error( FESyntaxErrors.SUBSCR_SLICE_EXPR )3085 self._subscription_or_slicing1()3086 return True3087 else:3088 return False3089 #-------------------------------------------------------------------------3090 def _subscription_or_slicing1(self) -> bool:3091 #=======================================================================3092 # <subscription or slicing'> ::= <expr list'> ']'3093 # | <if comprehension>3094 # | <slice form> <slice end>3095 #=======================================================================3096 if self._expr_list1():3097 if self._current.is_BRACKETCL():3098 self._append_syntaxic_node()3099 self._next_token_node()3100 else:3101 self._append_error( FESyntaxErrors.SUBCSR_SLICE_END )3102 return True3103 elif self._if_comprehension() or \3104 self._slice_form() and self._slice_end():3105 return True3106 else:3107 return False3108 #-------------------------------------------------------------------------3109 def _switch_block(self) -> bool:3110 #=======================================================================3111 # <switch block> ::= <case> <switch block>3112 # | EPS3113 #=======================================================================3114 while self._case():3115 continue3116 return True3117 #-------------------------------------------------------------------------3118 def _switch_statement(self) -> bool:3119 #=======================================================================3120 # <switch statement> ::= 'switch' '(' <expression> ')' '{' <switch block> '}' <switch statement'>3121 #=======================================================================3122 if self._current.is_SWITCH():3123 self._append_syntaxic_node()3124 self._next_token_node()3125 if self._current.is_PAROP():3126 self._append_syntaxic_node()3127 self._next_token_node()3128 else:3129 self._append_error( FESyntaxErrors.SWITCH_EXPR_BEGIN )3130 if not self._expression():3131 self._append_error( FESyntaxErrors.SWITCH_EXPR )3132 if self._current.is_PARCL():3133 self._append_syntaxic_node()3134 self._next_token_node()3135 else:3136 self._append_error( FESyntaxErrors.SWITCH_EXPR_END )3137 if self._current.is_BRACEOP():3138 self._append_syntaxic_node()3139 self._next_token_node()3140 else:3141 self._append_error( FESyntaxErrors.SWITCH_BODY_BEGIN )3142 self._switch_block() ## (notice: always returns True)3143 if self._current.is_BRACECL():3144 self._append_syntaxic_node()3145 self._next_token_node()3146 else:3147 self._append_error( FESyntaxErrors.SWITCH_BODY_END )3148 self._switch_statement1() ## (notice: always returns True)3149 return True3150 else:3151 return False3152 #-------------------------------------------------------------------------3153 def _switch_statement1(self) -> bool:3154 #=======================================================================3155 # <switch statement'> ::= 'otherwise' <statements block>3156 # | EPS3157 #=======================================================================3158 if self._current.is_OTHERWISE():3159 self._append_syntaxic_node()3160 self._next_token_node()3161 if not self._statements_block():3162 self._append_error( FESyntaxErrors.SWITCH_OTHERWISE_BODY )3163 return True3164 #-------------------------------------------------------------------------3165 def _target(self) -> bool:3166 #=======================================================================3167 # <target> ::= <dotted name> <target'>3168 #=======================================================================3169 if not self._dotted_name():3170 self._append_error( FESyntaxErrors.TARGET_IDENT )3171 return self._target1() ## (notice: always returns True)3172 #-------------------------------------------------------------------------3173 def _target1(self) -> bool:3174 #=======================================================================3175 # <target'> ::= <subscription or slicing> <target'>3176 # | EPS3177 #=======================================================================3178 while self._subscription_or_slicing():3179 continue3180 return True3181 #-------------------------------------------------------------------------3182 def _target_list(self) -> bool:3183 #=======================================================================3184 # <target list> ::= <typed target> <target list'>3185 #=======================================================================3186 if self._typed_target():3187 self._target_list1() ## (notice: always returns True)3188 return True3189 else:3190 return False3191 #-------------------------------------------------------------------------3192 def _target_list1(self) -> bool:3193 #=======================================================================3194 # <target list'> ::= ',' <typed target> <target list'>3195 # | EPS3196 #=======================================================================3197 while self._current.is_COMMA():3198 self._append_syntaxic_node()3199 self._next_token_node()3200 if not self._typed_target():3201 self._append_error( FESyntaxErrors.TARGET_TYPE )3202 return True3203 #-------------------------------------------------------------------------3204 def _template_args(self) -> bool:3205 #=======================================================================3206 # <template args> ::= '<' template args'>3207 # | EPS3208 #=======================================================================3209 if self._current.is_LT():3210 self._append_syntaxic_node()3211 self._next_token_node()3212 if not self._template_args1():3213 self._append_error( FESyntaxErrors.TEMPLATE_ENDING )3214 return True3215 3216 #-------------------------------------------------------------------------3217 def _template_args1(self) -> bool:3218 #=======================================================================3219 # <template args'> ::= <condition> <template args">3220 # | '>'3221 #=======================================================================3222 if self.condition():3223 return self._template_args2()3224 elif self._current.is_GT():3225 self._append_syntaxic_node()3226 self._next_token_node()3227 return True3228 else:3229 return False3230 #-------------------------------------------------------------------------3231 def _template_args2(self) -> bool:3232 #=======================================================================3233 # <template args"> ::= ',' <condition> <template args">3234 # | '>'3235 #=======================================================================3236 while self._current.is_COMMA():3237 self._append_syntaxic_node()3238 self._next_token_node()3239 if not self._condition():3240 self._append_error( FESyntaxErrors.TEMPLATE_COMMA_COND )3241 if self._current.is_GT():3242 self._append_syntaxic_node()3243 self._next_token_node()3244 return True3245 else:3246 return False3247 #-------------------------------------------------------------------------3248 def _template_def(self) -> bool:3249 #=======================================================================3250 # <template def> ::= '<' template def'>3251 # | EPS3252 #=======================================================================3253 if self._current.is_LT():3254 self._append_syntaxic_node()3255 self._next_token_node()3256 if not self._template_def1():3257 self._append_error( FESyntaxErrors.TEMPLATE_ENDING )3258 return True3259 3260 #-------------------------------------------------------------------------3261 def _template_def1(self) -> bool:3262 #=======================================================================3263 # <template def'> ::= <template def''> <template def'''>3264 # | '>'3265 #=======================================================================3266 if self._template_def2():3267 if not self._template_def3():3268 self._append_error( FESyntaxErrors.TEMPLATE_DEF_IDENT_CONST )3269 return True3270 elif self._current.is_GT():3271 self._append_syntaxic_node()3272 self._next_token_node()3273 return True3274 else:3275 return False3276 #-------------------------------------------------------------------------3277 def _template_def2(self) -> bool:3278 #=======================================================================3279 # <template def''> ::= <identifier>3280 # | <const qualifier> <template def const name>3281 #=======================================================================3282 if self._identifier():3283 return True3284 elif self._const_qualifier():3285 if not self._template_def_const_name():3286 self._append_error( FESyntaxErrors.TEMPLATE_DEF_CONST_TYPE)3287 return True3288 else:3289 return False3290 #-------------------------------------------------------------------------3291 def _template_def3(self) -> bool:3292 #=======================================================================3293 # <template def'''> ::= ',' <template def''> <template def'''>3294 # | '>'3295 #=======================================================================3296 while self._current.is_COMMA():3297 self._append_syntaxic_node()3298 self._next_token_node()3299 if not self._template_def2():3300 self._append_error( FESyntaxErrors.TEMPLATE_DEF_IDENT_CONST )3301 if self._current.is_GT():3302 self._append_syntaxic_node()3303 self._next_token_node()3304 return True3305 else:3306 return False3307 #-------------------------------------------------------------------------3308 def _template_def_const_name(self) -> bool:3309 #=======================================================================3310 # <template def const name> ::= <scalar type or dotted name> <identifier> <template def const name'>3311 #=======================================================================3312 if self._scalar_type_or_dotted_name():3313 if not self._identifier():3314 self._append_error( FESyntaxErrors.TEMPLATE_CONST_IDENT )3315 self._template_def_const_name1() ## (notice: always returns True)3316 return True3317 else:3318 return False3319 #-------------------------------------------------------------------------3320 def _template_def_const_name1(self) -> bool:3321 #=======================================================================3322 # <template def const name'> ::= '=' <expression>3323 # | EPS3324 #=======================================================================3325 if self._current.is_ASSIGN():3326 self._append_syntaxic_node()3327 self._next_token_node()3328 if not self._expression():3329 self._append_error( FESyntaxErrors.TEMPLATE_CONST_EXPR )3330 return True3331 #-------------------------------------------------------------------------3332 def _templated_type(self) -> bool:3333 #=======================================================================3334 # <templated type> ::= <dotted name> <templated type'>3335 #=======================================================================3336 if self._dotted_name():3337 self._templated_type1() ## (notice: always returns True)3338 return True3339 else:3340 return False3341 #-------------------------------------------------------------------------3342 def _templated_type1(self) -> bool:3343 #=======================================================================3344 # <templated type'> ::= '<' <types and exprs list> '>'3345 # | EPS3346 #=======================================================================3347 if self._current.is_LT():3348 self._append_syntaxic_node()3349 self._next_token_node()3350 if not self._types_and_exprs_list():3351 self._append_error( FESyntaxErrors.TEMPLATE_SPECIFICATION )3352 if self._current.is_GT():3353 self._append_syntaxic_node()3354 self._next_token_node()3355 else:3356 self._append_error( FESyntaxErrors.TEMPLATE_ENDING )3357 return True3358 #-------------------------------------------------------------------------3359 def _term(self) -> bool:3360 #=======================================================================3361 # <term> ::= <factor> <term'>3362 #=======================================================================3363 if self._factor():3364 return self._term1() ## (notice: always returns True)3365 else:3366 return False3367 #-------------------------------------------------------------------------3368 def _term1(self) -> bool:3369 #=======================================================================3370 # <term'> ::= '*' <template args> <factor> <term'>3371 # | '/' <template args> <factor> <term'>3372 # | '%' <template args> <factor> <term'>3373 # | '@' <template args> <factor> <term'>3374 # | '><' <spaced template args> <factor> <term'>3375 # | '!!' <template args> <factor> <term'>3376 # | '::' <template args> <factor> <term'>3377 # | EPS3378 #=======================================================================3379 while True:3380 if self._current.is_MUL() or \3381 self._current.is_DIV() or \3382 self._current.is_MOD() or \3383 self._current.is_AROBASE() or \3384 self._current.is_OP_2EXCL() or \3385 self._current.is_OP_2COLN():3386 self._append_syntaxic_node()3387 self._next_token_node()3388 self._template_args()3389 elif self._current.is_OP_GRLE():3390 self._append_syntaxic_node()3391 self._next_token_node()3392 self._spaced_template_args()3393 else:3394 break3395 self._factor()3396 return True3397 #-------------------------------------------------------------------------3398 def _true(self) -> bool:3399 #=======================================================================3400 # <TRUE> ::= 'True'3401 # | 'true'3402 #=======================================================================3403 if self._current.is_TRUE():3404 self._append_syntaxic_node()3405 self._next_token_node()3406 return True3407 else:3408 return False3409 #-------------------------------------------------------------------------3410 def _try_except(self) -> bool:3411 #=======================================================================3412 # <try except> ::= 'except' <try except'>3413 #=======================================================================3414 if self._current.is_EXCEPT():3415 self._append_syntaxic_node()3416 self._next_token_node()3417 self._try_except1()3418 return True3419 else:3420 return False3421 #-------------------------------------------------------------------------3422 def _try_except1(self) -> bool:3423 #=======================================================================3424 # <try except'> ::= '(' <try except''> ')'3425 # | EPS3426 #=======================================================================3427 if self._current.is_PAROP():3428 self._append_syntaxic_node()3429 self._next_token_node()3430 self._try_except2()3431 if self._current.is_PARCL():3432 self._append_syntaxic_node()3433 self._next_token_node()3434 else:3435 self._append_error( FESyntaxErrors.EXCEPT_EXPR_END )3436 return True3437 else:3438 return False 3439 #-------------------------------------------------------------------------3440 def _try_except2(self) -> bool:3441 #=======================================================================3442 # <try except''> ::= <expression> <try except'''> <try except''''>3443 # | 'all' <try except'''>3444 # | EPS3445 #=======================================================================3446 if self._expression():3447 self._try_except3() ## (notice: always returns True)3448 self._try_except4() ## (notice: always returns True)3449 elif self._current.is_ALL():3450 self._append_syntaxic_node()3451 self._next_token_node()3452 self._try_except3()3453 return True3454 #-------------------------------------------------------------------------3455 def _try_except3(self) -> bool:3456 #=======================================================================3457 # <try except'''> ::= ',' <expression> <try except'''>3458 # | EPS3459 #=======================================================================3460 while self._current.is_COMMA():3461 self._append_syntaxic_node()3462 self._next_token_node()3463 if not self._identifier():3464 self._append_error( FESyntaxErrors.TRY_EXCEPT_LIST )3465 self._try_except3()3466 return True3467 #-------------------------------------------------------------------------3468 def _try_except4(self) -> bool:3469 #=======================================================================3470 # <try except''''> ::= 'as' <identifier>3471 # | EPS3472 #=======================================================================3473 if self._current.is_AS():3474 self._append_syntaxic_node()3475 self._next_token_node()3476 if not self._identifier():3477 self._append_error( FESyntaxErrors.TRY_AS_IDENT )3478 return True3479 3480 #-------------------------------------------------------------------------3481 def _try_finally(self) -> bool:3482 #=======================================================================3483 # <try finally> ::= 'finally'3484 #=======================================================================3485 if self._current.is_FINALLY():3486 self._append_syntaxic_node()3487 self._next_token_node()3488 return True3489 else:3490 return False3491 #-------------------------------------------------------------------------3492 def _try_otherwise(self) -> bool:3493 #=======================================================================3494 # <try otherwise> ::= 'otherwise' '(' <try otherwise'> ')' 3495 #=======================================================================3496 if self._current.is_OTHERWISE():3497 self._append_syntaxic_node()3498 self._next_token_node()3499 if self._current.is_PAROP():3500 self._append_syntaxic_node()3501 self._next_token_node()3502 else:3503 self._append_error( FESyntaxErrors.TRY_OTHER_PAROP )3504 self._try_otherwise()3505 if self._current.is_PARCL():3506 self._append_syntaxic_node()3507 self._next_token_node()3508 else:3509 self._append_error( FESyntaxErrors.TRY_OTHER_PARCL )3510 return True3511 else:3512 return False3513 #-------------------------------------------------------------------------3514 def _try_otherwise1(self) -> bool:3515 #===============================================================================3516 # <try otherwise'> ::= 'Exception' 'as' <identifier>3517 # | EPS3518 #===============================================================================3519 if self._current.is_IDENT():3520 self._append_syntaxic_node()3521 self._next_token_node()3522 if self._current.is_AS():3523 self._append_syntaxic_node()3524 self._next_token_node()3525 else:3526 self._append_error( FESyntaxErrors.TRY_OTHER_AS )3527 if self._current.is_IDENT():3528 self._append_syntaxic_node()3529 self._next_token_node()3530 else:3531 self._append_error( FESyntaxErrors.TRY_OTHER_IDENT )3532 return True3533 #-------------------------------------------------------------------------3534 def _try_statement(self) -> bool:3535 #=======================================================================3536 # <try statement> ::= 'try' <statements block> <try statement excepts>3537 # <try statement otherwise> <try statement finally>3538 #=======================================================================3539 if self._current.is_TRY():3540 self._append_syntaxic_node()3541 self._next_token_node()3542 if not self._statements_block():3543 self._append_error( FESyntaxErrors.TRY_BODY )3544 if not self._try_statement_excepts():3545 self._append_error( FESyntaxErrors.TRY_EXCEPTS )3546 self._try_statement_otherwise()3547 self._try_statement_finally()3548 return True3549 else:3550 return False3551 #-------------------------------------------------------------------------3552 def _try_statement_otherwise(self) -> bool:3553 #=======================================================================3554 # <try statement otherwise> ::= <try otherwise> <statements block> ##3555 # | EPS ##3556 #=======================================================================3557 if self._try_otherwise():3558 if not self._statements_block():3559 self._append_error( FESyntaxErrors.TRY_OTHER_BODY )3560 return True3561 #-------------------------------------------------------------------------3562 def _try_statement_excepts(self) -> bool:3563 #=======================================================================3564 # <try statement excepts> ::= <try except> <statements block> <try statements excepts'>3565 #=======================================================================3566 if self._try_except():3567 if not self._statements_block():3568 self._append_error( FESyntaxErrors.TRY_EXCEPT_BODY )3569 return self._try_statement_excepts1()3570 else:3571 return False3572 #-------------------------------------------------------------------------3573 def _try_statement_excepts1(self) -> bool:3574 #=======================================================================3575 # <try statement excepts'> ::= <try except> <statements block> <try statement excepts'> ##3576 # | EPS ##3577 #=======================================================================3578 while self._try_except():3579 if not self._statements_block():3580 self._append_error( FESyntaxErrors.TRY_EXCEPT_BODY )3581 return True3582 #-------------------------------------------------------------------------3583 def _try_statement_finally(self) -> bool:3584 #=======================================================================3585 # <try statement finally> ::= <try finally> <statements block> ##3586 # | EPS ##3587 #=======================================================================3588 if self._try_finally():3589 if not self._statements_block():3590 self._append_error( FESyntaxErrors.TRY_FINALLY_BODY )3591 return True3592 #-------------------------------------------------------------------------3593 def _TYPE(self) -> bool:3594 #=======================================================================3595 # <TYPE> ::= <const qualifier> <type>3596 # | <type>3597 #=======================================================================3598 if self._const_qualifier():3599 if not self._type():3600 self._append_error( FESyntaxErrors.CONST_TYPE )3601 return True3602 else:3603 return self._type()3604 #-------------------------------------------------------------------------3605 def _TYPE1(self) -> bool:3606 #=======================================================================3607 # <TYPE'> ::= <const qualifier> <type>3608 # | <type'>3609 #=======================================================================3610 if self._const_qualifier():3611 if not self._type():3612 self._append_error( FESyntaxErrors.CONST_TYPE )3613 return True3614 else:3615 return self._type1()3616 #-------------------------------------------------------------------------3617 def _type(self) -> bool:3618 #=======================================================================3619 # <type> ::= <type'>3620 # | <templated type> <dimensions>3621 #=======================================================================3622 if self._type1():3623 return True3624 elif self._templated_type():3625 self._dimensions() ## (notice: always returns True)3626 return True3627 else:3628 return False 3629 #-------------------------------------------------------------------------3630 def _type1(self) -> bool:3631 #=======================================================================3632 # <type> ::= <auto type>3633 # | (' <types list> ')'3634 # | <container type>3635 # | <file type>3636 # | <NONE>3637 # | <scalar type> <dimensions>3638 #=======================================================================3639 if self._current.is_PAROP():3640 self._append_syntaxic_node()3641 self._next_token_node()3642 if not self._types_list():3643 self._append_error( FESyntaxErrors.TYPES_LIST )3644 if self._current.is_PARCL():3645 self._append_syntaxic_node()3646 self._next_token_node()3647 else:3648 self._append_error( FESyntaxErrors.TYPES_LIST_END )3649 return True3650 elif self._current.is_SCALAR_TYPE():3651 self._append_syntaxic_node()3652 self._next_token_node()3653 self._dimensions() ## (notice: always returns True)3654 return True3655 elif self._file_type() or self._none():3656 return True3657 elif self._auto_type():3658 return True3659 elif self._container_type():3660 return True3661 else:3662 return False3663 #-------------------------------------------------------------------------3664 def _type_alias(self) -> bool:3665 #=======================================================================3666 # <type alias> ::= 'type' <type alias"> <type alias'>3667 #=======================================================================3668 if self._current.is_TYPE_ALIAS():3669 self._append_syntaxic_node()3670 self._next_token_node()3671 if not self._type_alias2():3672 self._append_error( FESyntaxErrors.TYPE_ALIAS )3673 return self._type_alias1() ## (notice: always returns True)3674 else:3675 return False3676 #-------------------------------------------------------------------------3677 def _type_alias1(self) -> bool:3678 #=======================================================================3679 # <type alias'> ::= ',' <type alias"> <type alias'>3680 # | EPS3681 #=======================================================================3682 while self._current.is_COMMA():3683 self._append_syntaxic_node()3684 self._next_token_node()3685 if not self._type_alias2():3686 self._append_error( FESyntaxErrors.TYPE_ALIAS )3687 return True3688 #-------------------------------------------------------------------------3689 def _type_alias2(self) -> bool:3690 #=======================================================================3691 # <type alias"> ::= <TYPE> 'as' <identifier>3692 #=======================================================================3693 if self._TYPE():3694 if self._current.is_AS():3695 self._append_syntaxic_node()3696 self._next_token_node()3697 else:3698 self._append_error( FESyntaxErrors.TYPE_AS )3699 if not self._identifier():3700 self._append_error( FESyntaxErrors.TYPE_AS_IDENT )3701 return True3702 else:3703 return False3704 #-------------------------------------------------------------------------3705 def _typed_target(self) -> bool:3706 #=======================================================================3707 # <typed target> ::= <type'> <target>3708 # | <dotted name> <typed target'>3709 #=======================================================================3710 if self._type1():3711 if not self._target():3712 self._append_error( FESyntaxErrors.TYPED_TARGET_IDENT )3713 return True3714 elif self._dotted_name():3715 return self._typed_target1() ## (notice: always returns True)3716 else:3717 return False3718 #-------------------------------------------------------------------------3719 def _typed_target1(self) -> bool:3720 #=======================================================================3721 # <typed target'> ::= <dotted name> <target'>3722 # | <target'>3723 # | <templated type'> <target'>3724 #=======================================================================3725 if self._dotted_name() or self._templated_type1():3726 pass3727 return self._target1() ## (notice: always returns True)3728 #-------------------------------------------------------------------------3729 def _types_and_exprs_list(self) -> bool:3730 #=======================================================================3731 # <types and exprs list> ::= <expression> <types and exprs list'>3732 # | <templated type> <types and exprs list'>3733 #=======================================================================3734 if self._expression() or self._templated_type():3735 self._types_and_exprs_list1() ## (notice: always returns True)3736 return True3737 else:3738 return False3739 #-------------------------------------------------------------------------3740 def _types_and_exprs_list1(self) -> bool:3741 #=======================================================================3742 # <types and exprs list'> ::= ',' <types and exprs list"> <types and exprs list'>3743 # | EPS3744 #=======================================================================3745 while self._current.is_COMMA():3746 self._append_syntaxic_node()3747 self._next_token_node()3748 if not self._types_and_exprs_list2():3749 self._append_error( FESyntaxErrors.TEMPLATE_TYPES_LIST )3750 return True3751 #-------------------------------------------------------------------------3752 def _types_and_exprs_list2(self) -> bool:3753 #=======================================================================3754 # <types and exprs list"> ::= <expression>3755 # | <templated type>3756 #=======================================================================3757 return self._expression() or self._templated_type()3758 #-------------------------------------------------------------------------3759 def _typed_args_list(self) -> bool:3760 #=======================================================================3761 # <typed args list> ::= <TYPE> <identifier> <typed args list'>3762 # | EPS3763 #=======================================================================3764 if self._TYPE():3765 if not self._identifier():3766 self._append_error( FESyntaxErrors.TYPE_LIST_IDENT )3767 self.typed_args_list1()3768 return True3769 else:3770 return False3771 #-------------------------------------------------------------------------3772 def _typed_args_list1(self) -> bool:3773 #=======================================================================3774 # <typed args list'> ::= ',' <TYPE> <identifier> <typed args list'>3775 # | EPS3776 #=======================================================================3777 while self._current.is_COMMA():3778 self._append_syntaxic_node()3779 self._next_token_node()3780 if not self._TYPE():3781 self._append_error( FESyntaxErrors.TYPES_LIST_TYPE )3782 if not self._identifier():3783 self._append_error( FESyntaxErrors.TYPE_LIST_IDENT )3784 return True3785 #-------------------------------------------------------------------------3786 def _type_casting(self) -> bool:3787 #=======================================================================3788 # <scalar type casting> ::= '(' <expression> ')'3789 #=======================================================================3790 if self._current.is_PAROP():3791 self._append_syntaxic_node()3792 self._next_token_node()3793 if not self._expression():3794 self._append_error( FESyntaxErrors.CASTING_EXPR )3795 if self._current.is_PARCL():3796 self._append_syntaxic_node()3797 self._next_token_node()3798 else:3799 self._append_error( FESyntaxErrors.CASTING_PARCL )3800 return True3801 else:3802 return False3803 #-------------------------------------------------------------------------3804 def _types_list(self) -> bool:3805 #=======================================================================3806 # <types list> ::= <TYPE> <types list'>3807 #=======================================================================3808 if self._TYPE():3809 self._types_list1() ## (notice: always returns True)3810 return True3811 else:3812 return False3813 #-------------------------------------------------------------------------3814 def _types_list1(self) -> bool:3815 #=======================================================================3816 # <types list'> ::= ',' <TYPE> <types list'>3817 # | EPS3818 #=======================================================================3819 while self._current.is_COMMA():3820 self._append_syntaxic_node()3821 self._next_token_node()3822 if not self._TYPE():3823 self._append_error( FESyntaxErrors.TYPES_LIST_TYPE )3824 return True3825 #-------------------------------------------------------------------------3826 def _unary_expr(self) -> bool:3827 #=======================================================================3828 # <unary expr> ::= <factor>3829 # | '+' <factor>3830 # | '-' <factor>3831 # | '~' <factor>3832 # | '#' <factor>3833 #=======================================================================3834 if self._current.is_PLUS() or \3835 self._current.is_MINUS() or \3836 self._current.is_TILD() or \3837 self._current.is_HASH():3838 self._append_syntaxic_node()3839 self._next_token_node()3840 return self._factor()3841 #-------------------------------------------------------------------------3842 def _unnamed(self) -> bool:3843 #=======================================================================3844 # <unnamed> ::= 'unnamed'3845 # | 'lambda'3846 #=======================================================================3847 if self._current.is_UNNAMED():3848 self._append_syntaxic_node()3849 self._next_token_node()3850 return True3851 else:3852 return False3853 #-------------------------------------------------------------------------3854 def _unnamed_func(self) -> bool:3855 #=======================================================================3856 # <unnamed func> ::= <unnamed> <returned type> <function args declaration> <statements block>3857 #=======================================================================3858 if self._unnamed():3859 if not self._returned_type(): ## (notice: always returns True)3860 self._append_error( FESyntaxErrors.UNNAMED_TYPE ) ## (notice: never reached statement)3861 if not self._function_args_declaration():3862 self._append_error( FESyntaxErrors.UNNAMED_ARGS )3863 if not self._statements_block():3864 self._append_error( FESyntaxErrors.UNNAMED_BODY )3865 return True3866 else:3867 return False3868 #-------------------------------------------------------------------------3869 def _var_declaration_or_assignment(self) -> bool:3870 #=======================================================================3871 # <var declaration or assignment> ::= '=' <expression> <var declaration or assignment'>3872 # | ',' <identifier> <var declaration or assignment>3873 # | EPS3874 #=======================================================================3875 while self._current.is_COMMA():3876 self._append_syntaxic_node()3877 self._next_token_node()3878 if not self._identifier():3879 self._append_error( FESyntaxErrors.DECL_COMMA_IDENT )3880 if self._current.is_ASSIGN():3881 self._append_syntaxic_node()3882 self._next_token_node()3883 if not self._expression():3884 self._append_error( FESyntaxErrors.ASSIGN_EXPR )3885 self._var_declaration_or_assignment1() ## (notice: always returns True)3886 return True3887 #-------------------------------------------------------------------------3888 def _var_declaration_or_assignment1(self) -> bool:3889 #=======================================================================3890 # <var declaration or assignment'> ::= ',' <identifier> <var declaration or assignment>3891 # | EPS3892 #=======================================================================3893 if self._current.is_COMMA():3894 self._append_syntaxic_node()3895 self._next_token_node()3896 if not self._identifier():3897 self._append_error( FESyntaxErrors.DECL_COMMA_IDENT )3898 self._var_declaration_or_assignment()3899 return True3900 #-------------------------------------------------------------------------3901 def _volatile_qualifier(self) -> bool:3902 #=======================================================================3903 # <volatile qualifier> ::= 'volatile'3904 #=======================================================================3905 if self._current.is_VOLATILE():3906 self._append_syntaxic_node()3907 self._next_token_node()3908 return True3909 else:3910 return False3911 #-------------------------------------------------------------------------3912 def _while_statement(self) -> bool:3913 #=======================================================================3914 # <while statement> ::= 'while' '(' <expression> ')' <statements block> <while statement'>3915 #=======================================================================3916 if self._current.is_WHILE():3917 self._append_syntaxic_node()3918 self._next_token_node()3919 if self._current.is_PAROP():3920 self._append_syntaxic_node()3921 self._next_token_node()3922 else:3923 self._append_error( FESyntaxErrors.WHILE_COND_BEGIN )3924 if not self._expression():3925 self._append_error( FESyntaxErrors.WHILE_COND )3926 if self._current.is_PARCL():3927 self._append_syntaxic_node()3928 self._next_token_node()3929 else:3930 self._append_error( FESyntaxErrors.WHILE_COND_END )3931 if not self._statements_block():3932 self._append_error( FESyntaxErrors.WHILE_BODY )3933 self._while_statement1() ## (notice: always returns True)3934 return True3935 else:3936 return False3937 #-------------------------------------------------------------------------3938 def _while_statement1(self) -> bool:3939 #=======================================================================3940 # <while statement'> ::= 'otherwise' <statements block>3941 # | EPS3942 #=======================================================================3943 if self._current.is_OTHERWISE():3944 self._append_syntaxic_node()3945 self._next_token_node()3946 if not self._statements_block():3947 self._append_error( FESyntaxErrors.WHILE_OTHERWISE_BODY )3948 return True3949 #-------------------------------------------------------------------------3950 def _with_item(self) -> bool:3951 #=======================================================================3952 # <with item> ::= <expression> <with item'>3953 #=======================================================================3954 if self._expression():3955 self._with_item1() ## (notice: always returns True)3956 return True3957 else:3958 return False3959 #-------------------------------------------------------------------------3960 def _with_item1(self) -> bool:3961 #=======================================================================3962 # <with item'> ::= 'as' <with item">3963 # | EPS3964 #=======================================================================3965 if self._current.is_AS():3966 self._append_syntaxic_node()3967 self._next_token_node()3968 if not self._with_item2():3969 self._append_error( FESyntaxErrors.WITH_AS_IDENT )3970 return True3971 #-------------------------------------------------------------------------3972 def _with_item2(self) -> bool:3973 #=======================================================================3974 # <with item"> ::= <target>3975 # | <type'> <target>3976 #=======================================================================3977 if self._target():3978 return True3979 elif self._type1():3980 if not self._target():3981 self._append_error( FESyntaxErrors.WITH_AS_TYPED_IDENT )3982 return True3983 else:3984 return False3985 #-------------------------------------------------------------------------3986 def _with_items_list(self) -> bool:3987 #=======================================================================3988 # <with items list> ::= <with item> <with items list'>3989 #=======================================================================3990 if not self._with_item():3991 self._append_error( FESyntaxErrors.WITH_EXPR )3992 self._with_items_list1() ## (notice: always returns True)3993 return True3994 #-------------------------------------------------------------------------3995 def _with_items_list1(self) -> bool:3996 #=======================================================================3997 # <with items list'> ::= ',' <with item> <with items list'>3998 # | EPS3999 #=======================================================================4000 while self._current.is_COMMA():4001 self._append_syntaxic_node()4002 self._next_token_node()4003 if not self._with_item():4004 self._append_error( FESyntaxErrors.WITH_LIST_COMMA )4005 return True4006 #-------------------------------------------------------------------------4007 def _with_statement(self) -> bool:4008 #=======================================================================4009 # <with statement> ::= 'with' <with items list> <statements block>4010 #=======================================================================4011 if self._current.is_WITH():4012 self._append_syntaxic_node()4013 self._next_token_node()4014 self._with_items_list() ## (notice: always returns True)4015 if not self._statements_block():4016 self._append_error( FESyntaxErrors.WITH_BODY )4017 return True4018 else:4019 return False4020 4021 #=========================================================================4022 #-------------------------------------------------------------------------4023 def _append_error(self, err_data=None) -> None:4024 self._errors_count += 14025 err_node = ICTokenNode_UNEXPECTED( data=err_data or self._current.tk_data )4026 err_node.num_line = self._current.num_line4027 err_node.num_coln = self._current.num_coln4028 self._append_syntaxic_node( err_node )4029 #-------------------------------------------------------------------------4030 def _append_new_block(self) -> None:4031 self._out_syntax_ic += FEICBlock()4032 self._append_syntaxic_node()4033 #-------------------------------------------------------------------------4034 def _append_syntaxic_node(self, s_node: FEICodeTokenNode = None) -> bool:4035 self._out_syntax_ic += FEICLeaf( self._current if s_node is None else s_node )4036 return True4037 #-------------------------------------------------------------------------...
pipeline.py
Source:pipeline.py
...87 pertinente aplicada88 """89 raise NotImplementedError90 # pylint: disable=W061391 def _append_error(self, msg, *_, **__):92 self.errors.append({93 'error': msg94 })95class Pagination(BaseOperation):96 """Agrega paginación de resultados a una búsqueda"""97 def run(self, query, args):98 start = args.get(constants.PARAM_START,99 constants.API_DEFAULT_VALUES[constants.PARAM_START])100 limit = args.get(constants.PARAM_LIMIT,101 constants.API_DEFAULT_VALUES[constants.PARAM_LIMIT])102 self.validate_arg(start, name=constants.PARAM_START)103 self.validate_arg(limit, min_value=1, name=constants.PARAM_LIMIT)104 if self.errors:105 return106 start = int(start)107 limit = int(limit)108 query.add_pagination(start, limit)109 def validate_arg(self, arg, min_value=0, name=constants.PARAM_LIMIT):110 try:111 parsed_arg = int(arg)112 except ValueError:113 parsed_arg = None114 if parsed_arg is None or parsed_arg < min_value:115 self._append_error(strings.INVALID_PARAMETER.format(name, arg))116 return117 max_value = settings.MAX_ALLOWED_VALUES[name]118 if parsed_arg > max_value:119 msg = strings.PARAMETER_OVER_LIMIT.format(name, max_value, parsed_arg)120 self._append_error(msg)121class DateFilter(BaseOperation):122 def __init__(self):123 BaseOperation.__init__(self)124 self.start = None125 self.end = None126 def run(self, query, args):127 self.start = args.get(constants.PARAM_START_DATE)128 self.end = args.get(constants.PARAM_END_DATE)129 self.validate_start_end_dates()130 if self.errors:131 return132 start_date, end_date = None, None133 if self.start:134 start_date = str(iso8601.parse_date(self.start).date())135 if self.end:136 end_date = iso8601.parse_date(self.end).date()137 if '-' not in self.end: # Solo especifica año138 end_date = datetime.date(end_date.year, 12, 31)139 if self.end.count('-') == 1: # Especifica año y mes140 # Obtengo el último dÃa del mes, monthrange devuelve141 # tupla (month, last_day)142 days = monthrange(end_date.year, end_date.month)[1]143 end_date = datetime.date(end_date.year, end_date.month, days)144 query.add_filter(start_date, end_date)145 def validate_start_end_dates(self):146 """Valida el intervalo de fechas (start, end). Actualiza la147 lista de errores de ser necesario.148 """149 parsed_start, parsed_end = None, None150 if self.start:151 try:152 parsed_start = self.validate_date(self.start,153 constants.PARAM_START_DATE)154 except ValueError:155 pass156 if self.end:157 try:158 parsed_end = self.validate_date(self.end,159 constants.PARAM_END_DATE)160 except ValueError:161 pass162 if parsed_start and parsed_end:163 if parsed_start > parsed_end:164 self._append_error(strings.INVALID_DATE_FILTER)165 def validate_date(self, _date, param):166 """Valida y parsea la fecha pasada.167 Args:168 _date (str): date string, ISO 8601169 param (str): Parámetro siendo parseado170 Returns:171 date con la fecha parseada172 Raises:173 ValueError: si el formato no es válido174 """175 try:176 parsed_date = iso8601.parse_date(_date)177 except iso8601.ParseError:178 self._append_error(strings.INVALID_DATE.format(param, _date))179 raise ValueError180 return parsed_date181class IdsField(BaseOperation):182 """Asigna las series_ids, con sus modos de representación y modos de agregación,183 a base de el parseo el parámetro 'ids', que contiene datos de varias series a la vez184 """185 def __init__(self):186 BaseOperation.__init__(self)187 # Lista EN ORDEN de las operaciones de collapse a aplicar a las series188 self.aggs = []189 def run(self, query, args):190 # Ejemplo de formato del parámetro 'ids':191 # serie1:rep_mode1:agg1,serie2:repmode2:agg2,serie3:agg3,serie4:rep_mode3192 # rep_mode y agg son opcionales, hay un valor default, dado por otros parámetros193 # 'representation_mode' y 'collapse_aggregation'194 # Parseamos esa string y agregamos a la query las series pedidas195 ids = args.get(constants.PARAM_IDS)196 rep_mode = args.get(constants.PARAM_REP_MODE,197 constants.API_DEFAULT_VALUES[constants.PARAM_REP_MODE])198 collapse_agg = args.get(constants.PARAM_COLLAPSE_AGG,199 constants.API_DEFAULT_VALUES[constants.PARAM_COLLAPSE_AGG])200 if not ids:201 self._append_error(strings.NO_TIME_SERIES_ERROR)202 return203 delim = ids.find(',')204 series = ids.split(',') if delim > -1 else [ids]205 limit = settings.MAX_ALLOWED_VALUES[constants.PARAM_IDS]206 if len(series) > limit:207 self._append_error(strings.SERIES_OVER_LIMIT.format(limit))208 return209 for serie_string in series:210 self.process_serie_string(query, serie_string, rep_mode, collapse_agg)211 if self.errors:212 return213 def process_serie_string(self, query, serie_string, default_rep_mode, default_agg):214 name, rep_mode, collapse_agg = self._parse_single_series(serie_string)215 if not rep_mode:216 rep_mode = default_rep_mode217 if rep_mode not in constants.REP_MODES:218 error = strings.INVALID_PARAMETER.format(constants.PARAM_REP_MODE,219 rep_mode)220 self._append_error(error)221 return222 if not collapse_agg:223 collapse_agg = default_agg224 if collapse_agg not in constants.AGGREGATIONS:225 error = strings.INVALID_PARAMETER.format(constants.PARAM_COLLAPSE_AGG,226 collapse_agg)227 self._append_error(error)228 return229 if self.errors:230 return231 self.add_series(query, name, rep_mode, collapse_agg)232 if self.errors:233 return234 def add_series(self, query, series_id, rep_mode, collapse_agg):235 field_model = self._get_model(series_id)236 if not field_model:237 return238 query.add_series(field_model, rep_mode, collapse_agg)239 def _get_model(self, series_id):240 """Valida si el 'series_id' es válido, es decir, si la serie241 pedida es un ID contenido en la base de datos. De no242 encontrarse, llena la lista de errores según corresponda.243 """244 field_model = SeriesRepository.get_available_series(identifier=series_id).first()245 if field_model is None:246 self._append_error(SERIES_DOES_NOT_EXIST.format(series_id), series_id=series_id)247 return None248 index_start_metadata = meta_keys.get(field_model, meta_keys.INDEX_START)249 if index_start_metadata is None:250 self._append_error(SERIES_DOES_NOT_EXIST.format(series_id), series_id=series_id)251 return None252 return field_model253 def _parse_single_series(self, serie):254 """Parsea una serie invididual. Actualiza la lista de errores255 en caso de encontrar alguno, y la lista de operaciones de collapse256 Args:257 serie (str): string con formato de tipo 'id:rep_mode'258 Returns:259 nombre, rep_mode y aggregation parseados, o None en el caso de los260 dos últimos si el string no contenÃa valor alguno para ellos261 """262 colon_index = serie.find(':')263 if colon_index < 0: # Se asume que el valor es el serie ID, sin transformaciones264 return serie, None, None265 return self.find_rep_mode_and_agg(serie)266 def find_rep_mode_and_agg(self, serie):267 parts = serie.split(':')268 if len(parts) > 3:269 self.errors.append(strings.INVALID_SERIES_IDS_FORMAT)270 return None, None, None271 name = parts[0]272 rep_mode = None273 agg = None274 for part in parts[1:]:275 if not part:276 self.errors.append(strings.INVALID_SERIES_IDS_FORMAT)277 return None, None, None278 if part in constants.REP_MODES and rep_mode is None:279 rep_mode = part280 elif part in constants.AGGREGATIONS:281 agg = part282 else:283 self.errors.append(strings.INVALID_TRANSFORMATION.format(part))284 return None, None, None285 return name, rep_mode, agg286 def _append_error(self, msg, *args, **kwargs):287 series_id = kwargs.get('series_id')288 super(IdsField, self)._append_error(msg, *args, **kwargs)289 if series_id:290 self.failed_series.append(series_id)291class Collapse(BaseOperation):292 """Maneja las distintas agregaciones (suma, promedio)"""293 def run(self, query, args):294 collapse = args.get(constants.PARAM_COLLAPSE)295 if not collapse:296 return297 if collapse not in constants.COLLAPSE_INTERVALS:298 msg = strings.INVALID_PARAMETER.format(constants.PARAM_COLLAPSE,299 collapse)300 self._append_error(msg)301 return302 try:303 query.update_collapse(collapse=collapse)304 except CollapseError:305 msg = strings.INVALID_COLLAPSE.format(collapse)306 self._append_error(msg)307class Metadata(BaseOperation):308 def run(self, query, args):309 self.check_meta(query, args)310 if args.get(constants.PARAM_FLATTEN) is not None:311 query.flatten_metadata_response()312 def check_meta(self, query, args):313 metadata = args.get(constants.PARAM_METADATA)314 if not metadata:315 return316 if metadata not in constants.METADATA_SETTINGS:317 msg = strings.INVALID_PARAMETER.format(constants.PARAM_METADATA, metadata)318 self._append_error(msg)319 else:320 query.set_metadata_config(metadata)321class Sort(BaseOperation):322 def run(self, query, args):323 sort = args.get(constants.PARAM_SORT, constants.API_DEFAULT_VALUES[constants.PARAM_SORT])324 if sort not in constants.SORT_VALUES:325 msg = strings.INVALID_PARAMETER.format(constants.PARAM_SORT, sort)326 self._append_error(msg)327 else:328 query.sort(sort)329class Format(BaseOperation):330 """Valida el parámetro de formato de la respuesta. No realiza331 operación332 """333 def run(self, query, args):334 sort = args.get(constants.PARAM_FORMAT,335 constants.API_DEFAULT_VALUES[constants.PARAM_FORMAT])336 if sort not in constants.FORMAT_VALUES:337 msg = strings.INVALID_PARAMETER.format(constants.PARAM_FORMAT, format)338 self._append_error(msg)339class Header(BaseOperation):340 """Valida el parámetro de header de la respuesta CSV. No realiza341 operación"""342 def run(self, query, args):343 header = args.get(constants.PARAM_HEADER, constants.API_DEFAULT_VALUES[constants.PARAM_HEADER])344 if header not in constants.VALID_CSV_HEADER_VALUES:345 msg = strings.INVALID_PARAMETER.format(constants.PARAM_HEADER, header)346 self._append_error(msg)347class Delimiter(BaseOperation):348 """Valida el parámetro delimitador de la respuesta CSV. No realiza operación"""349 def run(self, query, args):350 delim = args.get(constants.PARAM_DELIM, constants.API_DEFAULT_VALUES[constants.PARAM_DELIM])351 if len(delim) != 1:352 msg = strings.INVALID_PARAM_LENGTH.format(constants.PARAM_DELIM)353 self._append_error(msg)354class DecimalChar(BaseOperation):355 """Valida el parámetro para cambiar el caracter decimal de los números del CSV."""356 def run(self, query, args):357 dec_char = args.get(constants.PARAM_DEC_CHAR)358 if dec_char and len(dec_char) != 1:359 msg = strings.INVALID_PARAM_LENGTH.format(constants.PARAM_DEC_CHAR)360 self._append_error(msg)361class Last(BaseOperation):362 def run(self, query: Query, args):363 last = args.get(constants.PARAM_LAST)364 if last is None:365 return366 self.validate(last, args)367 if self.errors:368 return369 query.add_pagination(start=0, limit=int(last))370 query.sort(constants.SORT_DESCENDING)371 query.reverse()372 def validate(self, last: str, args: dict):373 sort = args.get(constants.PARAM_SORT)374 start = args.get(constants.PARAM_START)375 limit = args.get(constants.PARAM_LIMIT)376 if sort or start or limit:377 params = ', '.join([constants.PARAM_SORT, constants.PARAM_START, constants.PARAM_LIMIT])378 self._append_error(strings.EXCLUSIVE_PARAMETERS.format(constants.PARAM_LAST, params))379 return380 try:381 last = validate_positive_int(last)382 except ValueError:383 self._append_error(strings.INVALID_PARAMETER.format(constants.PARAM_LAST, last))384 return385 max_value = settings.MAX_ALLOWED_VALUES[constants.PARAM_LIMIT]386 if last > max_value:387 msg = strings.PARAMETER_OVER_LIMIT.format(constants.PARAM_LIMIT, max_value, last)...
_append_error.py
Source:_append_error.py
...4description = 'Verify _append_error adds an error to the last step'5def test(data):6 # append error when there are no steps7 with expected_exception(Exception, 'there is no last step to append error'):8 actions._append_error('error message', description='error description')9 # add a step and append an error to it10 actions._add_step('step message')11 actions._append_error('error message', description='error description')12 expected = {'message': 'error message', 'description': 'error description'}13 assert execution.steps[-1]['error'] == expected14 # append error when last step already contains an error15 with expected_exception(Exception, 'last step already contains an error'):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!