Ejemplo n.º 1
0
        /// <summary>
        ///     Specific rule implementation of the match. Which is if one or more children matches.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns><c>true</c> if input is matched, <c>false</c> otherwise.</returns>
        protected internal override bool MatchImpl(ParserState state)
        {
            while (FirstLeaf.MatchImpl(state))
            {
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Specific rule implementation of the match.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns><c>true</c> if input is matched, <c>false</c> otherwise.</returns>
        protected internal override bool MatchImpl(ParserState state)
        {
            if (!Leafs.Any())
            {
                Leafs.Add(RuleFunc());
            }

            return(FirstLeaf.MatchImpl(state));
        }
Ejemplo n.º 3
0
        private T GetValue(ValueNode <T> valueNode)
        {
            var value = FirstLeaf.FirstValue <T>(valueNode.Text);

            if ((Comparer.Compare(Minimum, value) > 0) || (Comparer.Compare(Maximum, value) < 0))
            {
                throw new EvaluatorException($"The value doesn't meet the expected range. Minimum '{Minimum}'. Maximum '{Maximum}'. Actual '{value}'.");
            }

            return(value);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Specific rule implementation of the match. Which inverses the given rule.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns><c>true</c> if input is matched, <c>false</c> otherwise.</returns>
        protected internal override bool MatchImpl(ParserState state)
        {
            var oldState = state.Clone();

            if (!FirstLeaf.MatchImpl(state))
            {
                return(true);
            }

            state.Assign(oldState);
            return(false);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Specific rule implementation of the match. Which caches the result.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns><c>true</c> if input is matched, <c>false</c> otherwise.</returns>
        protected internal override bool MatchImpl(ParserState state)
        {
            var node      = CreateNode(Name, state.Input, state.Position, this);
            var oldChilds = state.Nodes;

            state.Nodes = new List <Node>();

            if (!FirstLeaf.MatchImpl(state))
            {
                state.Nodes = oldChilds;
                return(false);
            }

            node.End   = state.Position;
            node.Leafs = state.Nodes;

            oldChilds.Add(node);
            state.Nodes = oldChilds;
            return(true);
        }