Esempio n. 1
0
        /// <summary>
        /// Executes the interpreter.
        /// </summary>
        public void Execute()
        {
            bool quit = false;

            while (!quit)
            {
                _teletypeWithPosition.NewLine();
                _teletypeWithPosition.Write(">");
                var command = _teletypeWithPosition.Read();
                if (command == null)
                {
                    _runEnvironment.KeyboardBreak = false;
                    continue;
                }

                try
                {
                    var parsedLine = _tokeniser.Tokenise(command);
                    if (parsedLine.LineNumber.HasValue)
                    {
                        _programRepository.SetProgramLine(parsedLine);
                    }
                    else
                    {
                        _runEnvironment.CurrentLine = parsedLine;
                        quit = _executor.ExecuteLine();
                    }
                }
                catch (Exceptions.BreakException endError)
                {
                    if (endError.ErrorMessage != string.Empty)
                    {
                        WriteErrorToTeletype(
                            _runEnvironment.CurrentLine.LineNumber,
                            endError.ErrorMessage);
                    }
                }
                catch (Exceptions.BasicException basicError)
                {
                    WriteErrorToTeletype(
                        _runEnvironment.DataErrorLine ?? _runEnvironment.CurrentLine?.LineNumber,
                        "?" + basicError.ErrorMessage + " ERROR");
                }
            }
        }
Esempio n. 2
0
        public void ExecutingSystemCommandReturnsTrue()
        {
            SetupSut();
            _runEnvironment.CurrentLine = new ProgramLine(null, new List <IToken> {
                _mockSystemToken.Object
            });
            var result = _sut.ExecuteLine();

            Assert.IsTrue(result);
        }