MCPcopy
hub / github.com/rocky/python-uncompyle6 / python_parser

Function python_parser

uncompyle6/parser.py:879–920  ·  view source on GitHub ↗

Parse a code object to an abstract syntax tree representation. :param version: The python version this code is from as a float, for example 2.6, 2.7, 3.2, 3.3, 3.4, 3.5 etc. :param co: The code object to parse. :param out:

(
    version,
    co,
    out=sys.stdout,
    showasm=False,
    parser_debug=PARSER_DEFAULT_DEBUG,
    is_pypy=False,
)

Source from the content-addressed store, hash-verified

877
878
879def python_parser(
880 version,
881 co,
882 out=sys.stdout,
883 showasm=False,
884 parser_debug=PARSER_DEFAULT_DEBUG,
885 is_pypy=False,
886):
887 """
888 Parse a code object to an abstract syntax tree representation.
889
890 :param version: The python version this code is from as a float, for
891 example 2.6, 2.7, 3.2, 3.3, 3.4, 3.5 etc.
892 :param co: The code object to parse.
893 :param out: File like object to write the output to.
894 :param showasm: Flag which determines whether the disassembled and
895 ingested code is written to sys.stdout or not.
896 :param parser_debug: dict containing debug flags for the spark parser.
897 :param is_pypy: True if we are running PyPY
898
899 :return: Abstract syntax tree representation of the code object.
900 """
901
902 assert iscode(co)
903 from uncompyle6.scanner import get_scanner
904
905 scanner = get_scanner(version, is_pypy)
906 tokens, customize = scanner.ingest(co)
907 maybe_show_asm(showasm, tokens)
908
909 # For heavy grammar debugging
910 # parser_debug = {'rules': True, 'transition': True, 'reduce' : True,
911 # 'showstack': 'full'}
912
913 p = get_python_parser(version, parser_debug)
914
915 # FIXME: have p.insts update in a better way
916 # modularity is broken here
917 p.insts = scanner.insts
918 p.offset2inst_index = scanner.offset2inst_index
919
920 return parse(p, tokens, customize, co)
921
922
923if __name__ == "__main__":

Callers 2

test_dup_ruleFunction · 0.90
parse_testFunction · 0.85

Calls 5

get_scannerFunction · 0.90
maybe_show_asmFunction · 0.90
get_python_parserFunction · 0.85
parseFunction · 0.85
ingestMethod · 0.45

Tested by 1

test_dup_ruleFunction · 0.72