Пример #1
0
        protected Parser(string text)
        {
            Evaluate  = new LiteralParse(text);
            Step      = new ComputeStep(Evaluate);
            ParseType = StepType.Parse;

            if (Evaluate.IsEmpty)
            {
                Step.Error        = StepError.EmptyString;
                Step.ParseAborted = true;
            }
            else if (Evaluate.HasUnbalancedQuotes())
            {
                Step.Error        = StepError.UnbalancedQuotes;
                Step.ParseAborted = true;
            }
            else if (Evaluate.HasUnbancedParens())
            {
                Step.Error        = StepError.UnbalancedParens;
                Step.ParseAborted = true;
            }
            else
            {
                TryParse();
            }
        }
Пример #2
0
        private StepState _flags2;      // used by TryResolve()

        #region Constructor  ==================================================
        internal ComputeStep(LiteralParse evaluate)
        {
            StepType = StepType.Parse;
            Evaluate = evaluate;
        }
Пример #3
0
        protected Parser(string text, StepType stepType, bool hasNewLine = false, bool hasParens = false)
        {
            Step      = new ComputeStep(stepType);
            Evaluate  = new LiteralParse(text);
            ParseType = stepType;

            Step.HasParens  = hasParens;
            Step.HasNewLine = hasNewLine;

            switch (stepType)
            {
            case StepType.Parse:
            case StepType.List:
            case StepType.Vector:
                Step.Evaluate = Evaluate;
                TryParse();
                break;

            case StepType.Index:
                break;

            case StepType.String:
                Step.Evaluate = new LiteralString(Step, text);
                break;

            case StepType.Double:
                TryAddLiteralNumber();
                break;

            case StepType.Integer:
                TryAddLiteralNumber();
                break;

            case StepType.BitField:
                TryAddLiteralNumber();
                break;

            case StepType.Property:
                Step.Evaluate = Evaluate;     // the property name is needed by Step.TryValidate()
                break;

            default:
                break;
            }

            #region TryAddLiteralNumber  ==========================================
            bool TryAddLiteralNumber()
            {
                var(ok, isDouble, v, d) = Value.ParseNumber(Evaluate.Text);

                if (ok)
                {
                    if (isDouble)
                    {
                        Step.Evaluate = new LiteralDouble(Step, d, Evaluate.Text);
                    }
                    else
                    {
                        Step.Evaluate = new LiteralInt64(Step, v, Evaluate.Text);
                    }
                    return(true);
                }
                else
                {
                    Step.Error    = StepError.InvalidNumber;
                    Step.Evaluate = Evaluate;
                }
                return(false);
            }

            #endregion
        }