sequential parser for ITextSnapshot
예제 #1
0
        /// <summary>
        /// tries to close region
        /// </summary>
        /// <param name="parser">parser</param>
        /// <returns>whether region was closed</returns>
        public bool TryComplete(SnapshotParser parser)
        {
            SnapshotPoint point = parser.CurrentPoint;
            //ClassificationSpan span = parser.CurrentSpan;

            //if (span == null)
            {
                char c = point.GetChar();
                if (RegionType == TextRegionType.Block && c == '}')
                {
                    EndPoint = point + 1;
                }
            }

            return Complete;
        }
예제 #2
0
        /// <summary>
        /// parses buffer
        /// </summary>
        /// <param name="parser"></param>
        /// <param name="parent">parent region or null</param>
        /// <returns>a region with its children or null</returns>
        public static TextRegion ParseBuffer(SnapshotParser parser, TextRegion parent)
        {
            for (; !parser.AtEnd(); parser.MoveNext())
            {
                TextRegion r = TextRegion.TryCreateRegion(parser);

                if (r != null)
                {
                    parser.MoveNext();
                    //found the start of the region
                    if (!r.Complete)
                    {
                        //searching for child regions						
                        while (TextRegion.ParseBuffer(parser, r) != null) ;
                        //found everything						
                        r.ExtendStartPoint();
                    }
                    //adding to children or merging with last child
                    r.Parent = parent;
                    parent.Children.Add(r);
                    return r;
                }
                //found parent's end - terminating parsing
                if (parent.TryComplete(parser))
                {
                    parser.MoveNext();
                    return null;
                }
            }
            return null;
        }
예제 #3
0
 /// <summary>
 /// parses input buffer, searches for region start
 /// </summary>
 /// <param name="parser"></param>
 /// <returns>created region or null</returns>
 public static TextRegion TryCreateRegion(SnapshotParser parser)
 {
     SnapshotPoint point = parser.CurrentPoint;
     //ClassificationSpan span = parser.CurrentSpan;
     //if (span == null)
     {
         char c = point.GetChar();
         switch (c)
         {
             case '{':
                 return new TextRegion(point, TextRegionType.Block);
         }
     }
     return null;
 }