public override string ToPySyncsFromString(string Code, Logger.Logger logger)
        {
            var compiler = new Cache.EvenMessierCache(_tSet);

            compiler.Logger = logger;
            compiler.LoadString(Code);

            for (compiler.CurrentLine = 0;
                 compiler.StillProcessing();
                 compiler.CurrentLine++)
            {
                logger.Debug.WriteLine(this, compiler, "Starting new line");

                // Parse our current line of code etc into a
                // more usable format.
                // - line  = The untouched code
                // - trim  = The code that has whitespace removed.
                // - trims = The code that has only the starting whitespace removed
                string line  = compiler.GetCurrentLine(),
                       trim  = "",
                       trims = "";

                // Support for a multiline comment
                if (compiler.commentML)
                {
                    line = SubString(line, compiler.offsetIndex, line.Length);
                }

                // Trim the code
                trim  = line.Trim();
                trims = line.TrimStart();

                ParseCS_String(line, trim, trims, compiler);

                // Reset comment index
                compiler.offsetIndex = 0;
            }
            return(compiler.Output);
        }
示例#2
0
 public abstract string ToPySyncsFromString(string Code, Logger.Logger logger);
示例#3
0
        public override string ToPySyncsFromString(string Code, Logger.Logger logger)
        {
            var compiler = new Cache.MessyCompilerCache(_tSet);

            compiler.LoadString(Code);

            for (compiler.CurrentLine = 0;
                 compiler.StillProcessing();
                 compiler.CurrentLine++)
            {
                logger.Debug.WriteLine(this, compiler, "Parsing Line: " + compiler.CurrentLine);

                // Parse our current line of code etc into a
                // more usable format.
                // - line  = The untouched code
                // - trim  = The code that has whitespace removed.
                // - trims = The code that has only the starting whitespace removed
                string line  = compiler.GetCurrentLine(),
                       trim  = "",
                       trims = "";

                // Support for a multiline comment
                if (compiler.commentML)
                {
                    line = SubString(line, compiler.offsetIndex, line.Length);
                }

                // Trim the code
                trim  = line.Trim();
                trims = line.TrimStart();

                if (string.IsNullOrWhiteSpace(trim))
                {
                    // Whitespaced line, append new line with correct tabulation/whitespace.
                    compiler.WriteLine("", true);
                    continue;
                }

                /* 0. Check for starting comment such as // or /* */
                {
                    if (trim.StartsWith("//"))
                    {
                        // Just add the line to the file
                        // - Add the comment to the file with indentation
                        compiler.WriteLine(trim, true);
                        continue;
                    }
                    else if (trim.StartsWith("/*") && trim.Contains("*/"))
                    {
                        // The line contains a multi line comment but it stops on the
                        // same line. TODO: CHECK FOR CODE.

                        int comStart = trim.IndexOf("/*"),
                            comEnd   = trim.IndexOf("*/") + 2;


                        string s1  = SubString(trim, 0, comStart),
                               com = SubString(trim, comStart, comEnd),
                               s2  = SubString(trim, comEnd, trim.Length - 2);                    // What?

                        // Process s1, write the comment, Process s2.
                        if (!string.IsNullOrWhiteSpace(s1))
                        {
                            s_ProcessBraces(s1, s1, compiler);
                        }
                        compiler.WriteLine(com, true);
                        if (!string.IsNullOrWhiteSpace(s2))
                        {
                            s_ProcessBraces(s2, s2, compiler);
                        }
                    }
                    else if (trim.StartsWith("/*"))
                    {
                        // This is when the line consists of just a multi line comment
                        // - Let the compiler process the multi line comment automatically.
                        compiler.WriteLine(compiler.GetMultiLineComment().Trim(), true);
                        continue;
                    }
                    else if (trim.Contains("/*"))
                    {
                        // This means there is code or a character before the comment
                        // Display code
                        //   - Trim the text to get the code before a multiline comment
                        //   - Write the code
                        //   - Parse multi line comments
                        var code = SubString(trim, 0, line.IndexOf("/*")).Replace(";", "");
                        compiler.Write(code, false, true);
                        compiler.GetMultiLineComment();

                        continue;
                    }
                }


                /* 1. Check for semi-colons */
                {
                    // Count the amount of colons there are on the line
                    var colcnt = countOcc(";", line);

                    // If there is more than one colon
                    if (colcnt >= 1)
                    {
                        // If there is 1 colon
                        if (colcnt == 1)
                        {
                            string res1 = trim.Replace(";", ""),
                                   res2 = RemoveNL(res1);

                            compiler.WriteLine(res2, true);
                        }

                        // More than one
                        else
                        {
                            // Multiple instructions
                            // - Split them into a array
                            // - Add each instruction on a new line
                            string[] instructions = line.Split(';');
                            foreach (string inst in instructions)
                            {
                                compiler.WriteLine(RemoveNL(inst.Trim()), true);
                            }
                        }
                    }
                    else
                    {
                        if (s_ProcessBraces(trim, trims, compiler))
                        {
                            continue;
                        }
                    }
                }
            }



            return(compiler.Output);
        }