Example #1
0
        /// <summary>
        /// Inspects a head while at the end of the input
        /// </summary>
        /// <param name="head">The head to inspect</param>
        /// <param name="offset">The current offset from the original index</param>
        private void InspectAtEnd(Head head, int offset)
        {
            AutomatonState stateData = automaton.GetState(head.State);

            // is it a matching state
            if (stateData.TerminalsCount != 0 && stateData.GetTerminal(0).Index != separator)
            {
                OnMatchingHead(head, offset);
            }
            if (head.Distance >= maxDistance || stateData.IsDeadEnd)
            {
                // cannot stray further
                return;
            }
            // lookup the transitions
            ExploreTransitions(head, stateData, offset, true);
            ExploreInsertions(head, offset, true, '\0');
        }
Example #2
0
        /// <summary>
        /// Runs the lexer's DFA to match a terminal in the input ahead
        /// </summary>
        /// <param name="index">The current start index in the input text</param>
        /// <returns>The matching DFA state and length</returns>
        internal TokenMatch RunDFA(int index)
        {
            if (text.IsEnd(index))
            {
                // At the end of input
                // The only terminal matched at state index 0 is $
                return(new TokenMatch(0, 0));
            }

            TokenMatch result = new TokenMatch(0);
            int        state  = 0;
            int        i      = index;

            while (state != Automaton.DEAD_STATE)
            {
                AutomatonState stateData = automaton.GetState(state);
                // Is this state a matching state ?
                if (stateData.TerminalsCount != 0)
                {
                    result = new TokenMatch(state, i - index);
                }
                // No further transition => exit
                if (stateData.IsDeadEnd)
                {
                    break;
                }
                // At the end of the buffer
                if (text.IsEnd(i))
                {
                    break;
                }
                char current = text.GetValue(i);
                i++;
                // Try to find a transition from this state with the read character
                state = stateData.GetTargetBy(current);
            }
            return(result);
        }