Пример #1
0
        protected bool MatchEdge(string text, int pos, IFsmTransition transition)
        {
            // Console.WriteLine("Trying to match '{0}' character at {1} against {2}", text[pos], pos, transition.Condition);

            bool ok;

            if (transition.Condition.CheckFsmOrNull != null)
            {
                var runner = _checkRunnerFabric(transition.Fsm);
                ok = runner.IsMatch(text.Substring(pos)) == transition.Condition.CheckCondition;
            }
            else if (transition.Condition.ClassTestOrNull != null)
            {
                ok = transition.Condition.ClassTestOrNull(text[pos]);
            }
            else if (transition.Condition.Character.HasValue)
            {
                ok = transition.Condition.Character.Value == text[pos];
            }
            else
            {
                throw new NotSupportedException("Dfa cannot use sigma-transitions!");
            }

            return(ok);
        }
Пример #2
0
            public int CompareTo(IFsmTransition other)
            {
                var r = this.From.CompareTo(other.From);

                if (r != 0)
                {
                    return(r);
                }

                r = this.To.CompareTo(other.To);
                if (r != 0)
                {
                    return(r);
                }

                r = this.Condition.Character.HasValue.CompareTo(other.Condition.Character.HasValue);
                if (r != 0)
                {
                    return(r);
                }

                if (this.Condition.Character.HasValue && other.Condition.Character.HasValue)
                {
                    r = this.Condition.Character.Value.CompareTo(other.Condition.Character.Value);
                    if (r != 0)
                    {
                        return(r);
                    }
                }
                else if (this.Condition.Character.HasValue)
                {
                    return(1);
                }
                else
                {
                    return(-1);
                }

                r = Comparer <Func <char, bool> > .Default.Compare(this.Condition.ClassTestOrNull, other.Condition.ClassTestOrNull);

                if (r != 0)
                {
                    return(r);
                }

                return(0);
            }