示例#1
0
        public void BuildState(Dictionary <ITokenSource, Captures.ICaptureTokenStructuralItem> sourceReplacementLookup)
        {
            var thisReplacement           = sourceReplacementLookup.ContainsKey(this) ? (ITokenSource)(sourceReplacementLookup[this]) : (ITokenSource)this;
            RegularLanguageNFAState state = null;

            foreach (var expression in this.Cast <InlinedTokenExpression>())
            {
                expression.BuildState(sourceReplacementLookup);
                if (state == null)
                {
                    state = expression.NFAState;
                }
                else
                {
                    state.Union(expression.NFAState);
                }
            }
            List <RegularLanguageNFAState> flatline = new List <RegularLanguageNFAState>();

            RegularLanguageNFAState.FlatlineState(state, flatline);
            foreach (var fState in flatline)
            {
                fState.SetIntermediate(thisReplacement);
            }
            state.SetInitial(thisReplacement);
            foreach (var edge in state.ObtainEdges())
            {
                edge.SetFinal(thisReplacement);
            }
            state.HandleRepeatCycle <RegularLanguageSet, RegularLanguageNFAState, RegularLanguageDFAState, ITokenSource, RegularLanguageNFARootState, IInlinedTokenItem>(this, thisReplacement, OilexerGrammarInliningCore.TokenRootStateClonerCache, OilexerGrammarInliningCore.TokenStateClonerCache);
            this.state = state;
        }
        public void BuildState(Dictionary <ITokenSource, Captures.ICaptureTokenStructuralItem> sourceReplacementLookup)
        {
            var thisReplacement = sourceReplacementLookup.ContainsKey(this) ? (ITokenSource)(sourceReplacementLookup[this]) : (ITokenSource)this;
            var target          = (InlinedTokenExpressionSeries)this.SearchTarget;

            target.BuildState(sourceReplacementLookup);
            RegularLanguageNFAState         current = null;
            Stack <RegularLanguageNFAState> states  = new Stack <RegularLanguageNFAState>(new RegularLanguageNFAState[] { target.State });
            List <RegularLanguageNFAState>  covered = new List <RegularLanguageNFAState>();

            states.Peek().SetInitial(thisReplacement);
            //Step through the sequence until it's finished with the all states
            //associated to the scan operation.
            while (states.Count > 0)
            {
                current = states.Pop();
                if (covered.Contains(current))
                {
                    continue;
                }
                covered.Add(current);
                RegularLanguageSet currentSet = current.OutTransitions.FullCheck;
                if (!currentSet.IsEmpty)
                {
                    foreach (var transition in current.OutTransitions.Values)
                    {
                        foreach (var transitionTarget in transition)
                        {
                            if (!covered.Contains(transitionTarget))
                            {
                                states.Push(transitionTarget);
                            }
                        }
                    }
                    currentSet = currentSet.Complement();
                    if (!(currentSet.IsEmpty))
                    {
                        current.MoveTo(currentSet, target.State);
                    }
                }
            }
            state = target.State;
            List <RegularLanguageNFAState> flatline = new List <RegularLanguageNFAState>();

            RegularLanguageNFAState.FlatlineState(state, flatline);
            foreach (var fState in flatline)
            {
                fState.SetIntermediate(thisReplacement);
            }
            state.SetInitial(thisReplacement);
            foreach (var edge in State.ObtainEdges())
            {
                edge.SetFinal(thisReplacement);
            }
            state.HandleRepeatCycle <RegularLanguageSet, RegularLanguageNFAState, RegularLanguageDFAState, ITokenSource, RegularLanguageNFARootState, IInlinedTokenItem>(this, thisReplacement, OilexerGrammarInliningCore.TokenRootStateClonerCache, OilexerGrammarInliningCore.TokenStateClonerCache);
        }
        public void BuildState(Dictionary <ITokenSource, Captures.ICaptureTokenStructuralItem> sourceReplacementLookup)
        {
            var thisReplacement          = sourceReplacementLookup.ContainsKey(this) ? (ITokenSource)(sourceReplacementLookup[this]) : (ITokenSource)this;
            RegularLanguageNFAState root = new RegularLanguageNFAState();
            RegularLanguageNFAState next = new RegularLanguageNFAState();

            root.SetInitial(thisReplacement);
            root.MoveTo(this.Range, next);
            next.SetFinal(thisReplacement);
            root.HandleRepeatCycle <RegularLanguageSet, RegularLanguageNFAState, RegularLanguageDFAState, ITokenSource, RegularLanguageNFARootState, IInlinedTokenItem>(this, thisReplacement, OilexerGrammarInliningCore.TokenRootStateClonerCache, OilexerGrammarInliningCore.TokenStateClonerCache);
            this.state = root;
        }