base.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (c) 2020-2022, 2024 Rocky Bernstein
  2. #
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
  16. from decompyle3.parsers.parse_heads import PythonBaseParser
  17. from decompyle3.parsers.reduce_check import (
  18. break_invalid,
  19. for38_invalid,
  20. forelse38_invalid,
  21. pop_return_check,
  22. whilestmt38_check,
  23. whileTruestmt38_check,
  24. )
  25. class Python38PyPyBaseParser(PythonBaseParser):
  26. def __init__(self, start_symbol, debug_parser: dict = PARSER_DEFAULT_DEBUG):
  27. super(Python38PyPyBaseParser, self).__init__(
  28. start_symbol=start_symbol, debug_parser=debug_parser
  29. )
  30. def customize_grammar_rules38(self, tokens, customize):
  31. self.customize_grammar_rules37(tokens, customize)
  32. self.check_reduce["break"] = "tokens"
  33. self.check_reduce["for38"] = "tokens"
  34. self.check_reduce["forelsestmt38"] = "AST"
  35. self.check_reduce["pop_return"] = "tokens"
  36. self.check_reduce["whileTruestmt38"] = "AST"
  37. self.check_reduce["whilestmt38"] = "tokens"
  38. self.check_reduce["try_elsestmtl38"] = "AST"
  39. self.reduce_check_table["break"] = break_invalid
  40. self.reduce_check_table["for38"] = for38_invalid
  41. self.reduce_check_table["forelsestmt38"] = forelse38_invalid
  42. self.reduce_check_table["pop_return"] = pop_return_check
  43. self.reduce_check_table["whilestmt38"] = whilestmt38_check
  44. self.reduce_check_table["whileTruestmt38"] = whileTruestmt38_check