Example #1
0
        public override bool Equals(object obj)
        {
            MatchRangeTransition other = obj as MatchRangeTransition;

            if (other == null)
            {
                return(false);
            }

            return(Range == other.Range &&
                   base.Equals(other));
        }
Example #2
0
        private Transition MergeTransitions(Transition first, Transition second)
        {
            Contract.Requires(first != null);
            Contract.Requires(second != null);

            Contract.Ensures(Contract.Result <Transition>().SourceState == null);
            Contract.Ensures(Contract.Result <Transition>().IsRecursive == second.IsRecursive);

            Contract.Assert(!first.IsRecursive);
            Contract.Assert(first.IsEpsilon || !second.IsRecursive);

            if (first.IsMatch)
            {
                if (!second.IsEpsilon)
                {
                    throw new InvalidOperationException();
                }

                MatchRangeTransition matchRangeTransition = first as MatchRangeTransition;
                if (matchRangeTransition != null)
                {
                    return(new MatchRangeTransition(second.TargetState, matchRangeTransition.Range));
                }

                throw new NotImplementedException("Unknown match transition type.");
            }

            if (first.IsEpsilon)
            {
                if (second.IsEpsilon)
                {
                    return(new EpsilonTransition(second.TargetState));
                }

                MatchRangeTransition matchRangeTransition = second as MatchRangeTransition;
                if (matchRangeTransition != null)
                {
                    return(new MatchRangeTransition(second.TargetState, matchRangeTransition.Range));
                }

                PopContextTransition popContextTransition = second as PopContextTransition;
                if (popContextTransition != null)
                {
                    var transition = new PopContextTransition(second.TargetState, popContextTransition.ContextIdentifiers);
                    //transition.PushTransitions.UnionWith(popContextTransition.PushTransitions);
                    //Contract.Assert(Contract.ForAll(transition.PushTransitions, i => i.SourceState != null));
                    return(transition);
                }

                PushContextTransition pushContextTransition = second as PushContextTransition;
                if (pushContextTransition != null)
                {
                    var transition = new PushContextTransition(second.TargetState, pushContextTransition.ContextIdentifiers);
                    //transition.PopTransitions.UnionWith(pushContextTransition.PopTransitions);
                    //Contract.Assert(Contract.ForAll(transition.PopTransitions, i => i.SourceState != null));
                    return(transition);
                }

                throw new NotSupportedException();
            }

            PopContextTransition popFirst = first as PopContextTransition;

            if (popFirst != null)
            {
                if (second.IsEpsilon)
                {
                    var transition = new PopContextTransition(second.TargetState, popFirst.ContextIdentifiers);
                    //transition.PushTransitions.UnionWith(popFirst.PushTransitions);
                    //Contract.Assert(Contract.ForAll(transition.PushTransitions, i => i.SourceState != null));
                    return(transition);
                }

                PopContextTransition popSecond = second as PopContextTransition;
                if (popSecond != null)
                {
                    var transition = new PopContextTransition(popSecond.TargetState, popFirst.ContextIdentifiers.Concat(popSecond.ContextIdentifiers));
                    ////transition.PushTransitions.UnionWith(popFirst.PushTransitions);
                    //transition.PushTransitions.UnionWith(popSecond.PushTransitions);
                    //Contract.Assert(Contract.ForAll(transition.PushTransitions, i => i.SourceState != null));
                    return(transition);
                }

                if (second is PushContextTransition)
                {
                    throw new InvalidOperationException();
                }

                if (second.IsMatch)
                {
                    throw new NotSupportedException();
                }

                throw new NotImplementedException();
            }

            PushContextTransition pushFirst = first as PushContextTransition;

            if (pushFirst != null)
            {
                if (second.IsEpsilon)
                {
                    var transition = new PushContextTransition(second.TargetState, pushFirst.ContextIdentifiers);
                    //transition.PopTransitions.UnionWith(pushFirst.PopTransitions);
                    //Contract.Assert(Contract.ForAll(transition.PopTransitions, i => i.SourceState != null));
                    return(transition);
                }

                PushContextTransition pushSecond = second as PushContextTransition;
                if (pushSecond != null)
                {
                    var transition = new PushContextTransition(pushSecond.TargetState, pushFirst.ContextIdentifiers.Concat(pushSecond.ContextIdentifiers));
                    //transition.PopTransitions.UnionWith(pushFirst.PopTransitions);
                    ////transition.PopTransitions.UnionWith(pushSecond.PopTransitions);
                    //Contract.Assert(Contract.ForAll(transition.PopTransitions, i => i.SourceState != null));
                    return(transition);
                }

                if (second is PopContextTransition)
                {
                    throw new InvalidOperationException();
                }

                if (second.IsMatch)
                {
                    throw new NotSupportedException();
                }

                throw new NotImplementedException();
            }

            throw new NotImplementedException();
        }