Beispiel #1
0
        /// <summary>
        /// Visits all items in the given order
        /// </summary>
        /// <param name="item">The item to visit</param>
        /// <param name="start">The state to use</param>
        /// <returns>All items, including the start item, in the given order</returns>
        private static IEnumerable <VisitedItem> All(ParsedItem item, VisitedItem start, TraverseOrder order)
        {
            start = start ?? new VisitedItem();

            if (order == TraverseOrder.DepthFirstPostOrder)
            {
                start.Parents.Add(item);

                foreach (var n in item.Children)
                {
                    foreach (var c in All(n, start, order))
                    {
                        yield return(c);
                    }
                }

                start.Parents.RemoveAt(start.Parents.Count - 1);

                start.Current = item;
                yield return(start);
            }
            else //if (order == TraverseOrder.DepthFirstPreOrder)
            {
                start.Current = item;
                yield return(start);

                start.Parents.Add(item);

                foreach (var n in item.Children)
                {
                    foreach (var c in All(n, start, order))
                    {
                        yield return(c);
                    }
                }

                start.Parents.RemoveAt(start.Parents.Count - 1);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Visits all items in the given order
 /// </summary>
 /// <param name="item">The item to visit</param>
 /// <param name="order">The order to visit in</param>
 /// <returns>All items, including the start item, in the given order</returns>
 public static IEnumerable <VisitedItem> All(this ParsedItem item, TraverseOrder order = TraverseOrder.DepthFirstPreOrder)
 {
     return(All(item, new VisitedItem(), order));
 }
Beispiel #3
0
 /// <summary>
 /// Constructs a new parserexception
 /// </summary>
 /// <param name="message">The error message</param>
 /// <param name="source">The item with the problem</param>
 public ParserException(string message, AST.ParsedItem source)
     : this(message, source.SourceToken)
 {
     Item = source;
 }