Пример #1
0
def generate(options):
    parser = AnokyParser()
    try:
        if "filename" not in options:
            print("No filename specified.")
            return
        filename = options.filename
        stream = FileStream(filename)

        file_node = parser.parse(stream)
        parsed = indented_lisp_printer(file_node)

        expander = DefaultExpander()
        ec = expander.expand_unit(file_node)
        expanded = indented_lisp_printer(file_node)

        generator = DefaultGenerator()
        py_module = generator.generate_unit(
            file_node,
            # provide expansion context to generation context
            EC=ec)

        if options.verbose:
            print(parsed)
            print("\n〰〰〰〰〰〰 After macro expansion 〰〰〰〰〰〰")
            print(expanded)
            print("\n〰〰〰〰〰〰 Generated Python code 〰〰〰〰〰〰\n")
            astpp.parseprint(py_module)
            print("\n〰〰〰〰〰〰 Python retrosource 〰〰〰〰〰〰\n")
            print(ASTFormatter().format(py_module))

        return py_module

    except CompilerError as e:
        print(e.trace)
Пример #2
0
def anoky_expand(parsed_node, options):
    code_expander.expand_unit(parsed_node,
                              macros=__macros__,
                              id_macros=__id_macros__)
    if options.print_macro_expanded_code:
        print('\n——›–  Parsed source after macro expansion  –‹——', end='')
        print(indented_lisp_printer(parsed_node))
Пример #3
0
def expand(options):
    parser = AnokyParser()
    try:
        if "filename" not in options:
            print("No filename specified.")
            return
        filename = options.filename

        stream = FileStream(filename)

        file_node = parser.parse(stream)
        print(indented_lisp_printer(file_node))

        expander = DefaultExpander()
        ec = expander.expand_unit(file_node)
        print("\nAfter macro expansion:")
        print(indented_lisp_printer(file_node))

    except CompilerError as e:
        print(e.trace)
Пример #4
0
def expand(options):
    parser = AnokyParser()
    try:
        if "filename" not in options:
            print("No filename specified.")
            return
        filename = options.filename

        stream = FileStream(filename)

        file_node = parser.parse(stream)
        print(indented_lisp_printer(file_node))

        expander = DefaultExpander()
        ec = expander.expand_unit(file_node)
        print("\nAfter macro expansion:")
        print(indented_lisp_printer(file_node))

    except CompilerError as e:
        print(e.trace)
Пример #5
0
def arrange(options):
    parser = LycParser()
    try:
        filename = options.filename

        stream = FileStream(filename)

        file_node = parser.parse(stream)
        print(indented_lisp_printer(file_node))

    except CompilerError as e:
        print(e.trace)
Пример #6
0
def apply_transducer_chain(transducer_chain: List[TreeTransducer], form: Code):
    """
    Applies each tree transducer in a given list, in turn.
    """
    for tt in transducer_chain:
        if isinstance(form, Node) and len(form) > 0:
            tt.transduce(form)
            if G.Options.PRINT_TREE_TRANSDUCER_OUTPUTS is True:
                if G.Options.PRINT_TREE_TRANSDUCER_OUTPUTS_LIST is None or tt.name in G.Options.PRINT_TREE_TRANSDUCER_OUTPUTS_LIST:
                    print(
                        indent_string(
                            "After transducer: " + tt.name + "\n" +
                            indented_lisp_printer(form), 4))
Пример #7
0
def arrange(options):
    parser = AnokyParser()
    try:
        if "filename" not in options:
            print("No filename specified.")
            return
        filename = options.filename

        stream = FileStream(filename)

        file_node = parser.parse(stream)
        print(indented_lisp_printer(file_node))

    except CompilerError as e:
        print(e.trace)
Пример #8
0
def arrange(options):
    parser = AnokyParser()
    try:
        if "filename" not in options:
            print("No filename specified.")
            return
        filename = options.filename

        stream = FileStream(filename)

        file_node = parser.parse(stream)
        print(indented_lisp_printer(file_node))

    except CompilerError as e:
        print(e.trace)
Пример #9
0
def anoky_transduce(node, options):
    __parser__.transduce(node)
    if options.print_parse:
        print('\n——›–  Parsed source before macro expansion  –‹——', end='')
        print(indented_lisp_printer(node))
Пример #10
0
def anoky_expand(parsed_node,options):
    code_expander.expand_unit(parsed_node, macros=__macros__, id_macros=__id_macros__)
    if options.print_macro_expanded_code:
        print('\n——›–  Parsed source after macro expansion  –‹——', end='')
        print(indented_lisp_printer(parsed_node))
Пример #11
0
def anoky_transduce(node,options):
    __parser__.transduce(node)
    if options.print_parse:
        print('\n——›–  Parsed source before macro expansion  –‹——', end='')
        print(indented_lisp_printer(node))