Example #1
0
        private ITerminalToken?LexCommon(Dfa dfa)
        {
            DfaState?state = dfa.Start;
            var      start = index;

            while (!Source.IsEnd(index))
            {
                Debug.Assert(state != null);
                var next = state.Match(Source[index]);
                if (next == null)
                {
                    if (state.Final)
                    {
                        return(MakeResult(state.Payload, start, index));
                    }

                    var msg = Errors.GetExpectedMessage(Location.From(Source, index), Errors.GetSymbols(dfa).ToArray());
                    throw new ParserException(msg);
                }
                state  = next;
                index += 1;
            }

            if (state != null && state.Final)
            {
                return(MakeResult(state.Payload, start, index));
            }

            return(null);
        }
Example #2
0
 public DfaSet(IReadOnlyList <Dfa> dfas, IReadOnlyList <int> stateMap, Dfa spacing)
 {
     Dfas     = dfas;
     StateMap = stateMap;
     Spacing  = spacing;
 }