def script2gist(input_stream):
    print input_stream
    lexer = GistScriptLexer(input_stream)
    token_stream = CommonTokenStream(lexer)
    parser = GistScriptParser(token_stream)
    tree = parser.gistscript()
    lisp_tree_str = tree.toStringTree(recog=parser)
    print(lisp_tree_str)

    walker = ParseTreeWalker()

    listner = GistScriptListener()
    walker.walk(listner, tree)

    root = etree.XML('<?xml version="1.0" ?>' + listner.output)
    pretty_print(root)
    alternatives(root)

    newroot = xslt(root, 'xslt/script2gist.xsl')
    print "###### script2gist ######"
    pretty_print(newroot)

    name_temporarys(newroot)
    #name_unmapped(newroot)
    # print "###### name temps ######"
    # pretty_print(newroot)

    newroot = xslt(newroot, 'xslt/script2gist2.xsl')

    write(newroot, 'graph.xml')

    return newroot
def convert(input_stream):
    lexer = CalcLexer(input_stream)
    token_stream = CommonTokenStream(lexer)
    parser = CalcParser(token_stream)
    tree = parser.calcfile()
    lisp_tree_str = tree.toStringTree(recog=parser)
    print(lisp_tree_str)

    walker = ParseTreeWalker()

    listner = CalcListener()
    walker.walk(listner, tree)

    root = etree.XML('<?xml version="1.0" ?>' + listner.output)
    print "##ParseTreeWalker##"
    pretty_print(root)

    resolve_vars(root, use_tke='-tps' not in sys.argv)
    assign_ids(root)

    accumulations(root)
    difference(root)
    multiplications(root)
    multicopy_accumulation(root)

    # print "## RESOLVE VARS ##"
    # pretty_print(root)

    section = root.xpath('/CALC/Section/@val')[0]

    root = xslt(root, 'xslt/calc2script.xsl')
    print "## calc2script ##"
    pretty_print(root)

    clean_temps(root)
    # print "## CleanTemps ##"
    # pretty_print(root)

    root = xslt(root, 'xslt/calc2script2.xsl')
    print "## calc2script2 ##"
    pretty_print(root)


    text = xslt_text(root, 'xslt/calc2script3.xsl')
    print "## calc2script3 ##"
    print text
    return text
示例#3
0
    def convert_cart(self, xsl: str):
        xslt_params = {}
        for i in self.template_vars:
            spec = self.template_vars[i]
            xslt_params[i] = spec.val or ''
            pass

        try:
            res = xslt(
                self.cart_cxml.val,
                os.path.join(os.path.dirname(__file__), 'xsl', xsl),
                **xslt_params
            )

            self.cxml.val = self.preprocess_cxml(res)

        except Exception as e:
            flash(e)
            self.cxml_status_code.val = '500'
        pass
    if debug:
        print "##ParseTreeWalker##"
        pretty_print(root)

    process_converter(settings['cvt_filename'], form_xml=root, debug=debug, cl_path=settings['cl_path'])

    resolve_vars(root, use_tke=False)

    fix_self_referencing_assigns(root)

    if debug:
        print "##ParseTreeWalker##"
        pretty_print(root)


    root = xslt(root, 'tps2xref.xsl')

    create_or_blocks(root)

    set_pritool_descriptions(root, pritool_path=settings['formset_dir'], fed_pritool_path=settings['fedformset_dir'])

    if debug:
        print "## tps2xref.xsl ##"
        text = pretty_print(root)

    root = xslt(root, 'tps2xref2.xsl')
    if debug:
        print "## tps2xref2.xsl ###"
        text = pretty_print(root)

    remove_duplicate_gotolines(root)