| 48 | |
| 49 | |
| 50 | class Python3Parser(PythonParser): |
| 51 | def __init__(self, debug_parser=PARSER_DEFAULT_DEBUG): |
| 52 | self.added_rules = set() |
| 53 | super(Python3Parser, self).__init__(SyntaxTree, "stmts", debug=debug_parser) |
| 54 | self.new_rules = set() |
| 55 | |
| 56 | def p_comprehension3(self, args): |
| 57 | """ |
| 58 | # Python3 scanner adds LOAD_LISTCOMP. Python3 does list comprehension like |
| 59 | # other comprehensions (set, dictionary). |
| 60 | |
| 61 | # Our "continue" heuristic - in two successive JUMP_BACKS, the first |
| 62 | # one may be a continue - sometimes classifies a JUMP_BACK |
| 63 | # as a CONTINUE. The two are kind of the same in a comprehension. |
| 64 | |
| 65 | comp_for ::= expr for_iter store comp_iter CONTINUE |
| 66 | comp_for ::= expr for_iter store comp_iter JUMP_BACK |
| 67 | |
| 68 | list_comp ::= BUILD_LIST_0 list_iter |
| 69 | lc_body ::= expr LIST_APPEND |
| 70 | list_for ::= expr_or_arg |
| 71 | FOR_ITER |
| 72 | store list_iter jb_or_c |
| 73 | |
| 74 | # This is seen in PyPy, but possibly it appears on other Python 3? |
| 75 | list_if ::= expr jmp_false list_iter COME_FROM |
| 76 | list_if_not ::= expr jmp_true list_iter COME_FROM |
| 77 | |
| 78 | jb_or_c ::= JUMP_BACK |
| 79 | jb_or_c ::= CONTINUE |
| 80 | jb_cfs ::= JUMP_BACK _come_froms |
| 81 | |
| 82 | stmt ::= set_comp_func |
| 83 | |
| 84 | # TODO this can be simplified |
| 85 | set_comp_func ::= BUILD_SET_0 LOAD_ARG FOR_ITER store comp_iter |
| 86 | JUMP_BACK ending_return |
| 87 | set_comp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter |
| 88 | JUMP_BACK ending_return |
| 89 | set_comp_func ::= BUILD_SET_0 LOAD_ARG FOR_ITER store comp_iter |
| 90 | COME_FROM JUMP_BACK ending_return |
| 91 | |
| 92 | comp_body ::= dict_comp_body |
| 93 | comp_body ::= set_comp_body |
| 94 | dict_comp_body ::= expr expr MAP_ADD |
| 95 | set_comp_body ::= expr SET_ADD |
| 96 | |
| 97 | expr_or_arg ::= LOAD_ARG |
| 98 | expr_or_arg ::= expr |
| 99 | # See also common Python p_list_comprehension |
| 100 | """ |
| 101 | |
| 102 | def p_dict_comp3(self, args): |
| 103 | """ " |
| 104 | expr ::= dict_comp |
| 105 | stmt ::= dict_comp_func |
| 106 | dict_comp_func ::= BUILD_MAP_0 LOAD_ARG FOR_ITER store |
| 107 | comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST |