Esempio n. 1
0
        public void ProcessItem(T item)
        {
            //append to lookAhead, since it hasn't
            //been accepted yet
            this.lookAhead.Add(item);

            //when we iterate through we want to track whether
            //we've found an accepting recognizer, the reason
            //is that if multiple accept the same string we
            //break ties by using the first
            bool foundAccepting = false;

            //also track whether any can be accepting, if
            //none then we need to take special action
            bool foundCanBeAccepting = false;

            foreach (TokenType <T> tt in tokenTypes)
            {
                IRecognizerFSA r = tt.Pattern;
                if (r.CanBeAccepting())
                {
                    foundCanBeAccepting = true;
                    r.ProcessChar(item.GetCharProperty());
                    //we only care about whether or not it's accepting
                    //if it's the first
                    if (!foundAccepting && r.IsAccepting())
                    {
                        foundAccepting   = true;
                        acceptingHandler = tt.Handler;
                        //we need to append lookahead to accepted
                        //and clear lookahead
                        foreach (T la in lookAhead)
                        {
                            recognized.Add(la);
                        }
                        lookAhead.Clear();
                    }
                }
            }

            if (!foundCanBeAccepting)
            {
                //we're done with input until we
                //dispatch to some handler and
                //reset state
                DoneWithLookahead();
            }
        }
Esempio n. 2
0
 public TokenType(IRecognizerFSA pattern, Action <IList <T> > handler)
 {
     this.Pattern = pattern;
     this.Handler = handler;
 }