示例#1
0
        /*
        Core parsing
        */
        public string parseCommands(Language language, string[] commandsRaw)
        {
            if (commandsRaw.Length == 0 || (commandsRaw.Length == 1 && commandsRaw[0].Length == 0))
            {
                return "";
            }

            string output = "";
            int numTabs = 0;
            int lastTabRequest = 0;
            bool lastLineSkipped = true;
            object[] command;
            int i;
            int j;

            for (i = 0; i < commandsRaw.Length; i += 1)
            {
                command = this.parseCommand(language, commandsRaw[i], false);

                // Each command is an even-length [string, int, ...]
                for (j = 0; j < command.Length; j += 2)
                {
                    // Special case: a blank line after an inline command is ignored
                    // This is useful for things like lambda types that aren't in every language
                    if (lastTabRequest == Language.INT_MIN && command.Length == 2 && (string)command[0] == "")
                    {
                        lastLineSkipped = true;
                        continue;
                    }

                    if ((int)command[1] == Language.INT_MIN)
                    {
                        if ((string)command[0] != "")
                        {
                            output += " " + command[0];
                        }
                    }
                    else
                    {
                        // Just "\0" changes numTabs without adding a line
                        if ((string)command[j] != "\0" && !lastLineSkipped)
                        {
                            output += "\n";
                        }

                        if ((int)command[j + 1] < 0)
                        {
                            numTabs += (int)command[j + 1];
                            output += this.generateTabs(numTabs);
                            if ((int)command[j] != '\0')
                            {
                                output += command[j];
                            }
                        }
                        else
                        {
                            output += this.generateTabs(numTabs);
                            if ((string)command[j] != "\0")
                            {
                                output += command[j];
                            }
                            numTabs += (int)command[j + 1];
                        }
                    }

                    lastTabRequest = (int)command[command.Length - 1];
                    lastLineSkipped = false;
                }
            }

            return output;
        }
示例#2
0
        public string[] parseArguments(Language language, string argumentsRaw, bool isInline)
        {
            // Directly putting '{' in GLSC code is tough see #79
            char commandStarter = '{';
            int numArgs = 0;
            string[] argumentsConverted;
            string argument;
            char starter;
            int end;
            int i;

            // Until native array pushing is supported, this is required...
            for (i = 0; i < argumentsRaw.Length; i += 1)
            {
                starter = argumentsRaw[i];

                if (this.isCharacterSpace(starter))
                {
                    continue;
                }

                if (this.SearchEnds.ContainsKey(starter))
                {
                    end = this.findSearchEnd(argumentsRaw, starter, i);
                    i += 1;
                }
                else
                {
                    end = this.findNextSpace(argumentsRaw, i);
                }

                if (end == -1)
                {
                    end = argumentsRaw.Length;
                }

                i = end;
                numArgs += 1;
            }

            argumentsConverted = new string[numArgs];
            numArgs = 0;

            for (i = 0; i < argumentsRaw.Length; i += 1)
            {
                starter = argumentsRaw[i];

                if (this.isCharacterSpace(starter))
                {
                    continue;
                }

                if (this.SearchEnds.ContainsKey(starter))
                {
                    end = this.findSearchEnd(argumentsRaw, starter, i);
                    i += 1;
                }
                else
                {
                    end = this.findNextSpace(argumentsRaw, i);
                }

                if (end == -1)
                {
                    end = argumentsRaw.Length;
                }

                argument = argumentsRaw.Substring(i, end - 1);
                i = end;

                if (starter == commandStarter)
                {
                    argument = (string)this.parseCommand(language, argument, true)[0];
                }

                argumentsConverted[numArgs] = argument;
                numArgs += 1;
            }

            return argumentsConverted;
        }
示例#3
0
        public object[] parseCommand(Language language, string commandRaw, bool isInline)
        {
            if (this.isStringSpace(commandRaw))
            {
                return new object[] { "", 0 };
            }

            int colonIndex = commandRaw.IndexOf(":");
            string[] functionArgs;
            string functionName;
            string argumentsRaw;

            // Arguments only exist if there is a colon separating them from the command
            if (colonIndex == -1)
            {
                functionName = this.trimString(commandRaw);
                functionArgs = new string[] { };
            }
            else
            {
                functionName = this.trimString(commandRaw.Substring(0, colonIndex));
                argumentsRaw = this.trimString(commandRaw.Substring(colonIndex + 1));
                functionArgs = this.parseArguments(language, argumentsRaw, isInline);
            }

            return language.print(functionName, functionArgs, isInline);
        }