コード例 #1
0
ファイル: PageCalcViewModel.cs プロジェクト: kaby76/OpenCalc
        private bool CheckForErrorToken(string plain_ole_command, calculatorParser parser, IParseTree tree, IParseTree[] all_nodes)
        {
            IEnumerable <IParseTree> eni_nodes_iterator = all_nodes.Where((IParseTree n) =>
            {
                ErrorNodeImpl nn = n as ErrorNodeImpl;
                return(nn != null);
            });

            IParseTree[] all_eni_nodes_iterator = eni_nodes_iterator.ToArray();
            if (!all_eni_nodes_iterator.Any())
            {
                return(false);
            }

            // For now, report nothing if there isn't an equal.
            foreach (var en in all_eni_nodes_iterator)
            {
                ErrorNodeImpl eni = en as ErrorNodeImpl;
                if (eni != null)
                {
                    if (eni.GetText() == "<missing '='>")
                    {
                        return(false);
                    }
                }
            }

            var enn = all_eni_nodes_iterator.First() as ErrorNodeImpl;

            if (enn == null)
            {
                return(false);
            }

            int ErrorPos = enn.Payload.StartIndex;

            if (ErrorPos < 0)
            {
                ErrorPos = 0;
            }

            string result = "Extraneous input.";

            Results[Results.Count - 1].result.Text = BuildFormattedCommandAndResult(plain_ole_command, ErrorPos, result);
            NotifyPropertyChanged("Results");

            return(true);
        }