Пример #1
0
        private string XlatModule(string pyModule)
        {
            var rdr = new StringReader(pyModule);
            var lex = new Syntax.Lexer("foo.py", rdr);
            var par = new Syntax.Parser("foo.py", lex);
            var stm = par.stmt();
            var unt = new CodeCompileUnit();
            var gen = new CodeGenerator(unt, "test", "testModule");
            var sym = new SymbolGenerator();
            var xlt = new StatementTranslator(gen, sym);

            stm.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());
        }
        private string XlatMember(string pyModule)
        {
            var rdr   = new StringReader(pyModule);
            var lex   = new Syntax.Lexer("foo.py", rdr);
            var par   = new Syntax.Parser("foo.py", lex);
            var stm   = par.stmt();
            var unt   = new CodeCompileUnit();
            var gen   = new CodeGenerator(unt, "test", "testModule");
            var sym   = new SymbolGenerator();
            var types = new TypeReferenceTranslator(new Dictionary <Node, DataType>());
            var xlt   = new StatementTranslator(types, gen, sym, new HashSet <string>());

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

            foreach (CodeNamespace ns in unt.Namespaces)
            {
                foreach (var member in ns.Types[0].Members)
                {
                    pvd.GenerateCodeFromMember(
                        member, writer,
                        new CodeGeneratorOptions
                    {
                    });
                    writer.WriteLine();
                }
            }
            return(writer.ToString());
        }
Пример #3
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());
        }
Пример #4
0
        private string XlatStmts(string pyStmt)
        {
            var rdr = new StringReader(pyStmt);
            var lex = new Syntax.Lexer("foo.py", rdr);
            var par = new Syntax.Parser("foo.py", lex);
            var stm = par.stmt();
            var gen = new CodeGenerator(new CodeCompileUnit(), "", "module");

            gen.SetCurrentMethod(new CodeMemberMethod());
            var xlt = new StatementTranslator(gen, new SymbolGenerator());

            stm.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());
        }
Пример #5
0
 private string XlatModule(string pyModule)
 {
     var rdr = new StringReader(pyModule);
     var lex = new Syntax.Lexer("foo.py", rdr);
     var par = new Syntax.Parser("foo.py", lex);
     var stm = par.stmt();
     var unt = new CodeCompileUnit();
     var gen = new CodeGenerator(unt, "test", "testModule");
     var xlt = new StatementTranslator(gen, new Dictionary<string, LocalSymbol>());
     stm.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();
 }
Пример #6
0
 private string XlatMember(string pyModule)
 {
     var rdr = new StringReader(pyModule);
     var lex = new Syntax.Lexer("foo.py", rdr);
     var par = new Syntax.Parser("foo.py", lex);
     var stm = par.stmt();
     var unt = new CodeCompileUnit();
     var gen = new CodeGenerator(unt, "test", "testModule");
     var xlt = new StatementTranslator(gen, new Dictionary<string, LocalSymbol>());
     stm.Accept(xlt);
     var pvd = new CSharpCodeProvider();
     var writer = new StringWriter();
     foreach (CodeNamespace ns in unt.Namespaces)
     {
         foreach (var member in ns.Types[0].Members)
         {
             pvd.GenerateCodeFromMember(
                 member, writer,
                 new CodeGeneratorOptions
                 {
                 });
             writer.WriteLine();
         }
     }
     return writer.ToString();
 }
Пример #7
0
 private string XlatStmts(string pyStmt)
 {
     var rdr = new StringReader(pyStmt);
     var lex = new Syntax.Lexer("foo.py", rdr);
     var par = new Syntax.Parser("foo.py", lex);
     var stm = par.stmt();
     var gen = new CodeGenerator(new CodeCompileUnit(), "", "module");
     gen.CurrentMethod = new CodeMemberMethod();
     var xlt = new StatementTranslator(gen, new Dictionary<string, LocalSymbol>());
     stm.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();
 }