Esempio n. 1
0
        private string XlatModule(string pyModule)
        {
            var rdr   = new StringReader(pyModule);
            var lex   = new Syntax.Lexer("foo.py", rdr);
            var flt   = new Syntax.CommentFilter(lex);
            var par   = new Syntax.Parser("foo.py", flt);
            var stm   = par.stmt();
            var unt   = new CodeCompileUnit();
            var gen   = new CodeGenerator(unt, "test", "testModule");
            var types = new TypeReferenceTranslator(new Dictionary <Node, DataType>());
            var xlt   = new StatementTranslator(types, gen, new SymbolGenerator(), new HashSet <string>());

            stm[0].Accept(xlt);
            var pvd    = new CSharpCodeProvider();
            var writer = new StringWriter();

            foreach (CodeNamespace ns in unt.Namespaces)
            {
                foreach (CodeNamespaceImport imp in ns.Imports)
                {
                    writer.WriteLine("using {0};", SanitizeNamespace(imp.Namespace, gen));
                }
                foreach (CodeTypeDeclaration type in ns.Types)
                {
                    pvd.GenerateCodeFromType(
                        type,
                        writer,
                        new CodeGeneratorOptions
                    {
                    });
                }
            }
            return(writer.ToString());
        }
Esempio n. 2
0
        private string XlatStmts(string pyStmt)
        {
            var rdr = new StringReader(pyStmt);
            var lex = new Syntax.Lexer("foo.py", rdr);
            var flt = new Syntax.CommentFilter(lex);
            var par = new Syntax.Parser("foo.py", flt);
            var stm = par.stmt();
            var gen = new CodeGenerator(new CodeCompileUnit(), "", "module");

            gen.SetCurrentMethod(new CodeMemberMethod());
            var types = new TypeReferenceTranslator(new Dictionary <Node, DataType>());
            var xlt   = new StatementTranslator(types, gen, new SymbolGenerator(), new HashSet <string>());

            stm[0].Accept(xlt);
            var pvd    = new CSharpCodeProvider();
            var writer = new StringWriter();

            foreach (CodeStatement csStmt in gen.Scope)
            {
                pvd.GenerateCodeFromStatement(
                    csStmt,
                    writer,
                    new CodeGeneratorOptions
                {
                });
            }
            return(writer.ToString());
        }