コード例 #1
0
        private string XlatModule(string pyModule, string filename = "module.py")
        {
            var rdr = new StringReader(pyModule);
            var lex = new Lexer(filename, rdr);
            var par = new Parser(filename, lex);
            var stm = par.Parse().ToList();
            var unt = new CodeCompileUnit();
            var gen = new CodeGenerator(unt, "test", Path.GetFileNameWithoutExtension(filename));
            var opt = new Dictionary <string, object> {
                { "quiet", true }
            };
            var ana = new AnalyzerImpl(fs, logger, opt, DateTime.Now);
            var mod = new Module(
                "module",
                new SuiteStatement(stm, filename, 0, 0),
                filename, 0, 0);

            ana.LoadModule(mod);
            var types = new TypeReferenceTranslator(ana.BuildTypeDictionary());
            var xlt   = new ModuleTranslator(types, gen);

            xlt.Translate(stm);

            var pvd    = new CSharpCodeProvider();
            var writer = new StringWriter();

            pvd.GenerateCodeFromCompileUnit(unt, writer, new CodeGeneratorOptions {
            });
            return(writer.ToString());
        }
コード例 #2
0
ファイル: Translator.cs プロジェクト: ggljgg/pytocs
        public void TranslateModuleStatements(IEnumerable <Statement> stm, State moduleScope, TextWriter output)
        {
            var unt = new CodeCompileUnit();
            var gen = new CodeGenerator(unt, nmspace, Path.GetFileNameWithoutExtension(moduleName));
            var xlt = new ModuleTranslator(moduleScope, gen);

            xlt.Translate(stm);
            var pvd = new CSharpCodeProvider();

            pvd.GenerateCodeFromCompileUnit(unt, output, new CodeGeneratorOptions {
            });
        }
コード例 #3
0
ファイル: Translator.cs プロジェクト: weimingtom/pytocs
        public void Translate(string filename, TextReader input, TextWriter output)
        {
            Debug.Print("Translating module {0} in namespace {1}", moduleName, nmspace);
            var lex = new Lexer(filename, input);
            var par = new Parser(filename, lex);
            var stm = par.Parse();
            var unt = new CodeCompileUnit();
            var gen = new CodeGenerator(unt, nmspace, Path.GetFileNameWithoutExtension(moduleName));
            var xlt = new ModuleTranslator(gen);

            xlt.Translate(stm);
            var pvd = new CSharpCodeProvider();

            pvd.GenerateCodeFromCompileUnit(unt, output, new CodeGeneratorOptions {
            });
        }
コード例 #4
0
 public void TranslateModuleStatements(
     IEnumerable <Statement> stm,
     TypeReferenceTranslator types,
     TextWriter output)
 {
     try
     {
         var unt = new CodeCompileUnit();
         var gen = new CodeGenerator(unt, nmspace, Path.GetFileNameWithoutExtension(moduleName));
         var xlt = new ModuleTranslator(types, gen);
         xlt.Translate(stm);
         var pvd = new CSharpCodeProvider();
         pvd.GenerateCodeFromCompileUnit(unt, output, new CodeGeneratorOptions {
         });
     }
     catch (NodeException nex)
     {
         logger.Error($"{nex.Node.Filename}({nex.Node.Start}): {nex.Message}");
     }
 }
コード例 #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.Parse();;
            var unt = new CodeCompileUnit();
            var gen = new CodeGenerator(unt, "test", "testModule");
            var xlt = new ModuleTranslator(gen);

            xlt.Translate(stm);

            var pvd    = new CSharpCodeProvider();
            var writer = new StringWriter();

            pvd.GenerateCodeFromCompileUnit(
                unt,
                writer,
                new CodeGeneratorOptions
            {
            });
            return(writer.ToString());
        }
コード例 #6
0
        private string XlatModule(string pyModule)
        {
            var rdr   = new StringReader(pyModule);
            var lex   = new Lexer("foo.py", rdr);
            var par   = new Parser("foo.py", lex);
            var stm   = par.Parse();
            var unt   = new CodeCompileUnit();
            var gen   = new CodeGenerator(unt, "test", "testModule");
            var types = new TypeReferenceTranslator(new Dictionary <Node, DataType>());
            var xlt   = new ModuleTranslator(types, gen);

            xlt.Translate(stm);

            var pvd    = new CSharpCodeProvider();
            var writer = new StringWriter();

            pvd.GenerateCodeFromCompileUnit(
                unt,
                writer,
                new CodeGeneratorOptions
            {
            });
            return(writer.ToString());
        }