heads.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. """
  2. All of the specific kinds of canned parsers for Python 3.8
  3. These are derived from "compile-modes" but we have others that
  4. can be used to parse common part of a larger grammar.
  5. For example:
  6. * a basic-block expression (no branching)
  7. * an unadorned expression (no POP_TOP needed afterwards)
  8. * A non-compound statement
  9. """
  10. from decompyle3.parsers.p38.full import Python38Parser
  11. from decompyle3.parsers.p38.lambda_expr import Python38LambdaParser
  12. from decompyle3.parsers.parse_heads import (
  13. PythonParserEval,
  14. PythonParserExec,
  15. PythonParserExpr,
  16. PythonParserLambda,
  17. PythonParserSingle,
  18. # FIXME: add
  19. # PythonParserSimpleStmt
  20. # PythonParserStmt
  21. )
  22. # Make sure to list Python38... classes first so we prefer to inherit methods from that first.
  23. # In particular methods like reduce_is_invalid() need to come from there rather than
  24. # a more generic place.
  25. class Python38ParserEval(Python38LambdaParser, PythonParserEval):
  26. def __init__(self, debug_parser):
  27. PythonParserEval.__init__(self, debug_parser)
  28. class Python38ParserExec(Python38Parser, PythonParserExec):
  29. def __init__(self, debug_parser):
  30. PythonParserExec.__init__(self, debug_parser)
  31. class Python38ParserExpr(Python38Parser, PythonParserExpr):
  32. def __init__(self, debug_parser):
  33. PythonParserExpr.__init__(self, debug_parser)
  34. # Understand: Python38LambdaParser has to come before PythonParserLambda or we get a
  35. # MRO failure
  36. class Python38ParserLambda(Python38LambdaParser, PythonParserLambda):
  37. def __init__(self, debug_parser):
  38. PythonParserLambda.__init__(self, debug_parser)
  39. # These classes are here just to get parser doc-strings for the
  40. # various classes inherited properly and start_symbols set properly.
  41. class Python38ParserSingle(Python38Parser, PythonParserSingle):
  42. def __init__(self, debug_parser):
  43. PythonParserSingle.__init__(self, debug_parser)