Beispiel #1
0
        public IList<String> Parse(string input, bool showOutput)
        {
            Context.Parser = this;
            Context.Object = null;
            Context.IndirectObject = null;
            
            parserResults = new List<string>();

            Library L = new Library();
            bool wasLit = L.IsLit();

            var userInput = new UserInput();
            var inputResult = userInput.Parse(input);
            isAll = inputResult.IsAll;

            if (inputResult.HasError)
            {
                parserResults.Add(inputResult.Error);
            }
            else
            {
                HandleInputResult(inputResult);
            }

            if (!wasLit && L.IsLit())
                L.Look(true);

            return GetResults(showOutput);
        }
Beispiel #2
0
        public IList <String> Parse(string input, bool showOutput)
        {
            Context.Parser         = this;
            Context.Object         = null;
            Context.IndirectObject = null;

            parserResults = new List <string>();

            Library L      = new Library();
            bool    wasLit = L.IsLit();

            var userInput   = new UserInput();
            var inputResult = userInput.Parse(input);

            isAll = inputResult.IsAll;

            if (inputResult.HasError)
            {
                parserResults.Add(inputResult.Error);
            }
            else
            {
                HandleInputResult(inputResult);
            }

            if (!wasLit && L.IsLit())
            {
                L.Look(true);
            }

            return(GetResults(showOutput));
        }
Beispiel #3
0
        private IList <String> Parse(string input, bool showOutput)
        {
            Context.Parser         = this;
            Context.Object         = null;
            Context.IndirectObject = null;

            results = new List <ParserResult>();

            var  L      = new Library();
            bool wasLit = L.IsLit();

            var userInput = new UserInput();

            if (inputResult != null && inputResult.IsAskingQuestion)
            {
                var tokenizer = new InputTokenizer();
                var tokens    = tokenizer.Tokenize(input);

                if (!tokens.StartsWithVerb())
                {
                    string temp = null;
                    if (inputResult.Verb.IsNull == false)
                    {
                        temp += inputResult.Verb.Name + " ";
                    }
                    if (inputResult.Objects.Count > 0)
                    {
                        temp += inputResult.Objects[0].Synonyms[0] + " ";
                    }
                    if (!string.IsNullOrEmpty(inputResult.Preposition))
                    {
                        temp += inputResult.Preposition + " ";
                    }
                    if (inputResult.IndirectObject != null)
                    {
                        temp += inputResult.IndirectObject.Name + " ";
                    }
                    if (temp != null)
                    {
                        input = temp + input;
                    }
                }
            }

            inputResult = userInput.Parse(input);

            if (!inputResult.Handled)
            {
                HandleInputResult();
            }

            if (!wasLit && L.IsLit())
            {
                L.Look(true);
            }

            return(GetResults(showOutput, inputResult.ParserResults));
        }
Beispiel #4
0
        protected void Execute(string input)
        {
            var userInput   = new UserInput();
            var inputResult = userInput.Parse(input);
            var builder     = new CommandBuilder(inputResult);
            var commands    = builder.Build();

            foreach (var command in commands)
            {
                Context.Parser.ExecuteCommand(command);
            }
        }