Esempio n. 1
0
        public TreeWalker(RenpyScriptBuilder scriptBuilder)
        {
            this.functionLookup = new FunctionHandlerLookup();
            this.numAliasDictionary = new IgnoreCaseDictionary<int>();
            this.stringAliasDictionary = new IgnoreCaseDictionary<int>();
            this.scriptBuilder = scriptBuilder;

            // Variables used for jumpf command
            this.sawJumpfCommand = false;
            this.jumpfTargetCount = 0;

            this.gotIfStatement = false;

            this.forNextStatementIncrementString = new Stack<string>();

            //Register function handlers
            this.functionLookup.RegisterSystemFunction(new NumAliasHandler());
            this.functionLookup.RegisterSystemFunction(new StringAliasHandler());
            this.functionLookup.RegisterSystemFunction(new MovHandler());
            this.functionLookup.RegisterSystemFunction(new AddHandler());
            this.functionLookup.RegisterSystemFunction(new IncHandler());
            this.functionLookup.RegisterSystemFunction(new DecHandler());
            this.functionLookup.RegisterSystemFunction(new DefSubHandler());
            this.functionLookup.RegisterSystemFunction(new GetParamHandler());
            this.functionLookup.RegisterSystemFunction(new JumpfHandler());
            this.functionLookup.RegisterSystemFunction(new GotoHandler());
            this.functionLookup.RegisterSystemFunction(new GoSubHandler());
            this.functionLookup.RegisterSystemFunction(new DimHandler());
            this.functionLookup.RegisterSystemFunction(new NextHandler());
            this.functionLookup.RegisterSystemFunction(new LspHandler());
            this.functionLookup.RegisterSystemFunction(new SpbtnExbtnHandler());
            this.functionLookup.RegisterSystemFunction(new Btnwait2Handler());
            this.functionLookup.RegisterSystemFunction(new BtndefHandler());
        }
Esempio n. 2
0
        /// <summary>
        /// Dump top level of nodes for processing in another application or debugging
        /// NOTE: Since this only dumps the top level, only the first token of each node will be printed
        /// eg function arguments will have text as their function name, but the arguments won't be present in the output
        /// TODO: print all info in output, alternatively dump allLines structure as JSON or something
        /// </summary>
        /// <param name="lines"></param>
        /// <param name="subroutineDatabase"></param>
        /// <param name="savePath"></param>
        static bool DumpTopLevelNodes(string[] lines, SubroutineDatabase subroutineDatabase, string savePath)
        {
            RenpyScriptBuilder scriptBuilder = new RenpyScriptBuilder();

            bool error = ParseSection(lines, subroutineDatabase, isProgramBlock: true, out List <List <Node> > allLines);

            if (lines.Length != allLines.Count())
            {
                throw new Exception("lines weren't decoded correctly");
            }

            using (StreamWriter writer = File.CreateText(savePath))
            {
                foreach (var line in allLines)
                {
                    foreach (Node n in line)
                    {
                        writer.Write($"{n.GetLexeme().type}\0{n.GetLexeme().text}\0");
                    }
                    writer.WriteLine();
                }
            }

            return(error);
        }
Esempio n. 3
0
        static bool CompileScript(string[] lines, SubroutineDatabase subroutineDatabase)
        {
#if true
            RenpyScriptBuilder scriptBuilder = new RenpyScriptBuilder();
            TreeWalker         walker        = new TreeWalker(scriptBuilder);

            //CodeBlocks cbs = ReadSegments(lines);

            StringBuilder    simpleWriter   = new StringBuilder();
            StringBuilder    debugBuilder   = new StringBuilder();
            HashSet <string> modified_lines = new HashSet <string>();

            bool error = ParseSection(lines, subroutineDatabase, isProgramBlock: true, out List <List <Node> > allLines);
            if (error)
            {
                return(error);
            }

            if (lines.Length != allLines.Count())
            {
                throw new Exception("lines weren't decoded correctly");
            }

            string debugPath = @"C:\drojf\large_projects\ponscripter_parser\renpy\ponscripty\game\debug.txt";
            string savePath  = @"C:\drojf\large_projects\ponscripter_parser\renpy\ponscripty\game\script.rpy";
            scriptBuilder.SaveFile("prelude.rpy", savePath);

            using (StreamWriter writer = File.CreateText(savePath))
            {
                writer.Write(simpleWriter.ToString());
            }

            using (StreamWriter writer = File.CreateText(debugPath))
            {
                writer.WriteLine("Unique Modified Lines:");
                foreach (string s in modified_lines)
                {
                    writer.WriteLine(s.ToString());
                }
                writer.WriteLine("\n\n");

                writer.WriteLine("Possibly Missed lines:");
                writer.Write(debugBuilder.ToString());
            }
#else
            RenpyScriptBuilder scriptBuilder = new RenpyScriptBuilder();
            TreeWalker         walker        = new TreeWalker(scriptBuilder);

            CodeBlocks cbs = ReadSegments(lines);

            StringBuilder    simpleWriter   = new StringBuilder();
            StringBuilder    debugBuilder   = new StringBuilder();
            HashSet <string> modified_lines = new HashSet <string>();

            // Write to Init Region
            //scriptBuilder.SetBodyRegion();
            foreach (string line in cbs.header)
            {
                AppendSLToForwardSlashAndBlankLine(line, subroutineDatabase, scriptBuilder, walker, simpleWriter, debugBuilder, modified_lines, isProgramBlock: true);
            }

            foreach (string line in cbs.definition)
            {
                AppendSLToForwardSlashAndBlankLine(line, subroutineDatabase, scriptBuilder, walker, simpleWriter, debugBuilder, modified_lines, isProgramBlock: true);
            }

            // Write to Body Region
            //scriptBuilder.SetBodyRegion();
            foreach (string line in cbs.program)
            {
                AppendSLToForwardSlashAndBlankLine(line, subroutineDatabase, scriptBuilder, walker, simpleWriter, debugBuilder, modified_lines, isProgramBlock: true);
            }

            string debugPath = @"C:\drojf\large_projects\ponscripter_parser\renpy\ponscripty\game\debug.txt";
            string savePath  = @"C:\drojf\large_projects\ponscripter_parser\renpy\ponscripty\game\script.rpy";
            scriptBuilder.SaveFile("prelude.rpy", savePath);

            using (StreamWriter writer = File.CreateText(savePath))
            {
                writer.Write(simpleWriter.ToString());
            }

            using (StreamWriter writer = File.CreateText(debugPath))
            {
                writer.WriteLine("Unique Modified Lines:");
                foreach (string s in modified_lines)
                {
                    writer.WriteLine(s.ToString());
                }
                writer.WriteLine("\n\n");

                writer.WriteLine("Possibly Missed lines:");
                writer.Write(debugBuilder.ToString());
            }
#endif
            return(true);
        }