Example #1
0
        public bool CanTraverse(Matcher.MatchMode mode, 
            string input, int position, bool ignoreCase,
            out Label output, out bool consumedInput)
        {
            consumedInput = false;
            output = null;

            Label matchLabel;
            Label outputLabel;

            switch (mode)
            {
            case Matcher.MatchMode.Analyse:
                matchLabel = _Input;
                outputLabel = _Output;
                break;
            case Matcher.MatchMode.Generate:
                matchLabel = _Output;
                outputLabel = _Input;
                break;
            default:
                throw new Exception("Illegal case constant");
            }

            if (matchLabel.Matches(input, position, ignoreCase))
            {
                consumedInput = matchLabel.IsConsuming;
                output = outputLabel;
                return true;
            }
            else
                return false;
        }
Example #2
0
        /// <summary>
        /// Attempts to traverse the specified transition, given the current match state.
        /// </summary>
        /// <param name="input">The string input</param>
        /// <param name="t">The transition to probe</param>
        /// <param name="mode">The match mode</param>
        /// <returns>The new match state or null if the transition cannot be traversed</returns>
        public MatchState Traverse(string input, FSTTransition t, Matcher.MatchMode mode, bool ignoreCase)
        {
#if false
            bool  consumed;
            Label output;

            if (t.CanTraverse(mode, input, _InputPosition, ignoreCase, out output, out consumed))
            {
                MatchState result = new MatchState(this);
                result._State = t.Target;

                result.AppendOutput(output);

                if (consumed)
                {
                    ++result._ConsumedSymbols;
                    ++result._InputPosition;
                }

                return(result);
            }
            else
            {
                return(null);
            }
#else
            Label matchLabel;
            Label outputLabel;

            switch (mode)
            {
            case Matcher.MatchMode.Analyse:
                matchLabel  = t.Input;
                outputLabel = t.Output;
                break;

            case Matcher.MatchMode.Generate:
                matchLabel  = t.Output;
                outputLabel = t.Input;
                break;

            default:
                throw new Exception("Illegal case constant");
            }

            if (matchLabel.Matches(input, _InputPosition, ignoreCase))
            {
                MatchState result = new MatchState(this);
                result._State = t.Target;

                if (outputLabel.IsConsuming)
                {
                    result._Output.Add(outputLabel);
                }

                if (matchLabel.IsConsuming)
                {
                    ++result._ConsumedSymbols;
                    ++result._InputPosition;
                }

                return(result);
            }
            return(null);
#endif
        }