Пример #1
0
        private List <MacroCommandWithArguments> getCommandsWAFromCode()
        {
            MacroCodeInterpreter             interpreter = new MacroCodeInterpreter();
            List <MacroCommandWithArguments> commandsWA  = new List <MacroCommandWithArguments>();
            int lineIndex = 0;

            foreach (string line in commandsEditorTextBox.TextBox.Lines)
            {
                interpreter.Formula = line;
                if (interpreter.HasSyntaxError)
                {
                    throw new Exception(string.Format("Line #{0} has syntax error!", (lineIndex + 1)));
                }
                if (!interpreter.IsComplete && !interpreter.IsEmpty)
                {
                    throw new Exception(string.Format("Line #{0} is incomplete!", (lineIndex + 1)));
                }
                if (!interpreter.IsEmpty)
                {
                    commandsWA.Add(interpreter.GetCommandWithArguments());
                }
                lineIndex++;
            }
            return(commandsWA);
        }
Пример #2
0
        private void interpretLine(int lineIndex)
        {
            if (lineIndex < 0)
            {
                return;
            }
            string line = commandsEditorTextBox.TextBox.Lines[lineIndex];
            MacroCodeInterpreter interpreter = new MacroCodeInterpreter();

            interpreter.Formula = line;
            syntaxHighlightLine(lineIndex, interpreter.Tokens, interpreter.HasSyntaxError, interpreter.SyntaxErrorPosition);
            showPointForLine(lineIndex, interpreter);
        }
Пример #3
0
        private void validateCode()
        {
            MacroCodeInterpreter interpreter = new MacroCodeInterpreter();
            int lineIndex = 0;

            foreach (string line in commandsEditorTextBox.TextBox.Lines)
            {
                interpreter.Formula = line;
                if (interpreter.HasSyntaxError)
                {
                    throw new Exception(string.Format("Line #{0} has syntax error!", (lineIndex + 1)));
                }
                if (!interpreter.IsComplete && !interpreter.IsEmpty)
                {
                    throw new Exception(string.Format("Line #{0} is incomplete!", (lineIndex + 1)));
                }
                lineIndex++;
            }
        }
Пример #4
0
        private void showPointForLine(int lineIndex, MacroCodeInterpreter interpreter)
        {
            RichTextBox rtfBox = commandsEditorTextBox.TextBox;

            if (interpreter.HasSyntaxError)
            {
                string tooltip = string.Format("Syntax error at position {0}.", interpreter.SyntaxErrorPosition);
                commandsEditorTextBox.SetPointColor(lineIndex, POINTCOLOR_SYNTAX_ERROR, tooltip);
                return;
            }

            if (interpreter.IsEmpty)
            {
                commandsEditorTextBox.RemovePoint(lineIndex);
                return;
            }

            if (!interpreter.IsComplete)
            {
                commandsEditorTextBox.SetPointColor(lineIndex, POINTCOLOR_INCOMPLETE, "Line incomplete.");
                return;
            }

            if (!interpreter.CommandExists)
            {
                commandsEditorTextBox.SetPointColor(lineIndex, POINTCOLOR_NOTEXISTS, "Command does not exist.");
                return;
            }

            IMacroCommand command = interpreter.GetCommand();

            if (interpreter.ArgumentCountMismatch)
            {
                string tooltip = string.Format("Command should have {0} arguments.", command.Arguments.Length);
                commandsEditorTextBox.SetPointColor(lineIndex, POINTCOLOR_ARGUMENT_COUNT_MISMATCH, tooltip);
                return;
            }

            List <bool> argumentTypeMatches = new List <bool>(interpreter.ArgumentTypeMatches);

            if (!argumentTypeMatches.TrueForAll(atm => atm))
            {
                string tooltip = "";
                for (int i = 0; i < argumentTypeMatches.Count; i++)
                {
                    if (!argumentTypeMatches[i])
                    {
                        tooltip += string.Format("Argument #{0} should be a {1}.\n", i + 1, command.Arguments[i].KeyType.ToString().ToLower());
                    }
                }
                tooltip = tooltip.Substring(0, tooltip.Length - 1);
                commandsEditorTextBox.SetPointColor(lineIndex, POINTCOLOR_ARGUMENT_TYPE_MISMATCH, tooltip);
                return;
            }

            if (interpreter.IsComplete)
            {
                commandsEditorTextBox.SetPointColor(lineIndex, POINTCOLOR_OK, "OK.");
                return;
            }

            commandsEditorTextBox.SetPointColor(lineIndex, POINTCOLOR_UNKNOWN, "???");
        }