base.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. """
  16. Python 3.8 base code. We keep non-custom-generated grammar rules out of this file.
  17. """
  18. from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
  19. from decompyle3.parsers.parse_heads import PythonBaseParser
  20. from decompyle3.parsers.reduce_check import (
  21. break_invalid,
  22. for38_invalid,
  23. forelse38_invalid,
  24. pop_return_check,
  25. whilestmt38_check,
  26. whileTruestmt38_check,
  27. )
  28. class Python38BaseParser(PythonBaseParser):
  29. def __init__(self, start_symbol, debug_parser: dict = PARSER_DEFAULT_DEBUG):
  30. super(Python38BaseParser, self).__init__(
  31. start_symbol=start_symbol, debug_parser=debug_parser
  32. )
  33. def customize_grammar_rules38(self, tokens, customize):
  34. self.customize_grammar_rules37(tokens, customize)
  35. self.check_reduce["break"] = "tokens"
  36. self.check_reduce["for38"] = "tokens"
  37. self.check_reduce["forelsestmt38"] = "AST"
  38. self.check_reduce["pop_return"] = "tokens"
  39. self.check_reduce["whileTruestmt38"] = "AST"
  40. self.check_reduce["whilestmt38"] = "tokens"
  41. self.check_reduce["try_elsestmtl38"] = "AST"
  42. self.reduce_check_table["break"] = break_invalid
  43. self.reduce_check_table["for38"] = for38_invalid
  44. self.reduce_check_table["forelsestmt38"] = forelse38_invalid
  45. self.reduce_check_table["pop_return"] = pop_return_check
  46. self.reduce_check_table["whilestmt38"] = whilestmt38_check
  47. self.reduce_check_table["whileTruestmt38"] = whileTruestmt38_check