Get() public static method

public static Get ( String input, kOS.ExecutionContext context ) : Command
input String
context kOS.ExecutionContext
return Command
Ejemplo n.º 1
0
        public void Run(File file)
        {
            this.file = file;

            State = ExecutionState.WAIT;

            int lineNumber = 0;

            foreach (String line in file)
            {
                commandBuffer += line;

                string cmd;
                while (parseNext(ref commandBuffer, out cmd))
                {
                    try
                    {
                        Command cmdObj = Command.Get(cmd, this);
                        cmdObj.LineNumber = lineNumber;
                        commands.Add(cmdObj);
                    }
                    catch (kOSException e)
                    {
                        StdOut("Error on line " + lineNumber + ": " + e.Message);
                        State = ExecutionState.DONE;
                        return;
                    }
                }

                lineNumber++;
                accumulator++;
            }
        }
Ejemplo n.º 2
0
        public override void Evaluate()
        {
            expression    = new Expression(RegexMatch.Groups[1].Value, ParentContext);
            targetCommand = Command.Get(RegexMatch.Groups[2].Value, ParentContext);

            ParentContext.Lock(this);

            State = ExecutionState.DONE;
        }
Ejemplo n.º 3
0
        private void RunBlock(List <String> block)
        {
            foreach (String rawLine in block)
            {
                String line = stripComment(rawLine);
                commandBuffer += line + "\n";
            }

            string cmd;
            int    lineNumber       = 0;
            int    commandLineStart = 0;

            while (parseNext(ref commandBuffer, out cmd, ref lineNumber, out commandLineStart))
            {
                try
                {
                    Line = commandLineStart;
                    Command cmdObj = Command.Get(cmd, this, commandLineStart);
                    commands.Add(cmdObj);
                }
                catch (kOSException e)
                {
                    if (ParentContext.FindClosestParentOfType <ContextRunProgram>() != null)
                    {
                        // Error occurs in a child of another running program
                        StdOut("Error in '" + e.Program.Filename + "' on line " + e.LineNumber + ": " + e.Message);
                        State = ExecutionState.DONE;
                        return;
                    }
                    else
                    {
                        // Error occurs in the top level program
                        StdOut("Error on line " + e.LineNumber + ": " + e.Message);
                        State = ExecutionState.DONE;
                        return;
                    }
                }
                catch (Exception e)
                {
                    // Non-kos exception! This is a bug, but no reason to kill the OS
                    StdOut("Flagrant error on line " + lineNumber);
                    UnityEngine.Debug.Log("Program error");
                    UnityEngine.Debug.Log(e);
                    State = ExecutionState.DONE;
                    return;
                }
            }

            if (commandBuffer.Trim() != "")
            {
                StdOut("End of file reached inside unterminated statement");
                State = ExecutionState.DONE;
            }
        }
Ejemplo n.º 4
0
        public override void Evaluate()
        {
            waitExpression = new Expression(RegexMatch.Groups[1].Value, ParentContext);

            int numLinesChild = Utils.NewLineCount(Input.Substring(0, RegexMatch.Groups[2].Index));

            targetCommand = Command.Get(RegexMatch.Groups[2].Value, this, Line + numLinesChild);

            //commandString = RegexMatch.Groups[2].Value;

            State = ExecutionState.WAIT;
        }
Ejemplo n.º 5
0
        public override void Evaluate()
        {
            targetVariable = ParentContext.FindOrCreateVariable(RegexMatch.Groups[1].Value);
            targetCommand  = Command.Get(RegexMatch.Groups[2].Value, ParentContext);

            if (!objToBool(targetVariable.Value, out originalValue))
            {
                throw new Exception("Value type error");
            }

            ParentContext.Lock(this);

            State = ExecutionState.DONE;
        }
Ejemplo n.º 6
0
        public override void Evaluate()
        {
            String innerText = RegexMatch.Groups[1].Value;
            String cmd;

            commandBuffer = innerText;

            while (parseNext(ref innerText, out cmd))
            {
                commands.Add(Command.Get(cmd, this));
            }

            State = (commands.Count == 0) ? ExecutionState.DONE : ExecutionState.WAIT;
        }
Ejemplo n.º 7
0
        public override void Evaluate()
        {
            expression    = new Expression(RegexMatch.Groups[1].Value, ParentContext);
            targetCommand = Command.Get(RegexMatch.Groups[2].Value, this);

            if (expression.IsTrue())
            {
                targetCommand.Evaluate();
                Push(targetCommand);
                State = ExecutionState.WAIT;
            }
            else
            {
                State = ExecutionState.DONE;
            }
        }
Ejemplo n.º 8
0
        public void Add(string cmdString)
        {
            commandBuffer += cmdString;
            string nextCmd;

            while (parseNext(ref commandBuffer, out nextCmd))
            {
                try
                {
                    Command cmd = Command.Get(nextCmd, this);
                    Queue.Enqueue(cmd);
                }
                catch (kOSException e)
                {
                    StdOut(e.Message);
                    Queue.Clear(); // HALT!!
                }
            }
        }
Ejemplo n.º 9
0
        public override void Evaluate()
        {
            expression = new Expression(RegexMatch.Groups[1].Value, ParentContext);

            int numLinesChild = Utils.NewLineCount(Input.Substring(0, RegexMatch.Groups[2].Index));

            targetCommand = Command.Get(RegexMatch.Groups[2].Value, this, Line + numLinesChild);

            if (expression.IsTrue())
            {
                targetCommand.Evaluate();
                Push(targetCommand);
                State = ExecutionState.WAIT;
            }
            else
            {
                State = ExecutionState.DONE;
            }
        }
Ejemplo n.º 10
0
        public override void Update(float time)
        {
            base.Update(time);

            if (ChildContext == null)
            {
                if (waitExpression.IsTrue())
                {
                    State = ExecutionState.DONE;
                }
                else
                {
                    ChildContext = Command.Get(commandString, this);
                    ((Command)ChildContext).Evaluate();
                }
            }
            else
            {
                if (ChildContext.State == ExecutionState.DONE)
                {
                    ChildContext = null;
                }
            }
        }