Beispiel #1
0
        internal static void Exit(bool revertAll = false)
        {
            var trail = current;

            if (revertAll)
            {
                while (trail.Depth > 0)
                {
                    trail.Backtrack();
                }
            }
            else if (trail.parent is Trail parent)
            {
                foreach (var frame in trail.frames.Reverse())
                {
                    parent.frames.Push(frame);
                }
            }

            current = trail.parent;
        }
Beispiel #2
0
        public static IEnumerable AsEnumerable(this Query query, bool revertAll = false)
        {
            try
            {
                Trail.Enter();

                Query nextQuery = query;

                while (nextQuery != null)
                {
                    var currentQuery = nextQuery;
                    var result       = currentQuery.Run();

                    switch (result)
                    {
                    case QueryResult.ChoicePoint:
                        nextQuery = currentQuery.Continuation;
                        Trail.Current.ChoicePoint(currentQuery.Alternate);
                        break;

                    case QueryResult.Success:
                        yield return(null);

                        nextQuery = Trail.Current.Backtrack();
                        break;

                    default:
                        nextQuery = Trail.Current.Backtrack();
                        break;
                    }
                }
            }
            finally
            {
                Trail.Exit(revertAll);
            }
        }
Beispiel #3
0
 public Trail(Trail parent)
 {
     this.parent = parent;
     this.frames = new Stack <ChoiceFrame>();
 }
Beispiel #4
0
        internal static void Enter()
        {
            current = new Trail(Current);

            current.ChoicePoint(null);
        }
Beispiel #5
0
 public Trail(Trail parent)
 {
     this.parent = parent;
 }