コード例 #1
0
        private static PythonModule GenerateModuleAsSnippets(SystemState state, CompilerContext context, Stmt body, string moduleName)
        {
            SuiteStmt           suite = body as SuiteStmt;
            SnippetModuleRunner smr   = new SnippetModuleRunner(moduleName, state);

            Debug.Assert(suite != null, "invalid statement");

            //  Convert document string into assignment
            if (suite.stmts.Length > 0)
            {
                ExprStmt es = suite.stmts[0] as ExprStmt;
                if (es != null)
                {
                    ConstantExpr ce = es.expr as ConstantExpr;
                    if (ce != null && ce.value is string)
                    {
                        suite.stmts[0] = new AssignStmt(new Expr[] { new NameExpr(Name.Make("__doc__")) }, ce);
                    }
                }
            }

            foreach (Stmt stmt in suite.stmts)
            {
                // GenerateSnippet will do the binding
                smr.AddSnippet(GenerateSnippet(context, stmt, moduleName, true));
            }
            return(smr.Module);
        }
コード例 #2
0
        private static PythonModule GenerateModuleAsSnippets(SystemState state, CompilerContext context, Statement body, string moduleName)
        {
            SuiteStatement suite = body as SuiteStatement;
            SnippetModuleRunner smr = new SnippetModuleRunner(moduleName, state);

            Debug.Assert(suite != null, "invalid statement");

            //  Convert document string into assignment
            if (suite.Statements.Count > 0) {
                ExpressionStatement es = suite.Statements[0] as ExpressionStatement;
                if (es != null) {
                    ConstantExpression ce = es.Expression as ConstantExpression;
                    if (ce != null && ce.Value is string) {
                        suite.Statements[0] = new AssignStatement(new Expression[] { new NameExpression(SymbolTable.Doc) }, ce);
                    }
                }
            }

            foreach (Statement stmt in suite.Statements) {
                // GenerateSnippet will do the binding
                smr.AddSnippet(GenerateSnippet(context, stmt, moduleName, true, false));
            }
            return smr.Module;
        }