Example #1
0
        private GlobNode Parse(GlobParserContext context)
        {
            context.Accept();

            // Parse the root.
            var items = new List <GlobNode> {
                ParseRoot(context)
            };

            if (items.Count == 1 && items[0] is RelativeRoot)
            {
                items.Add(ParseSegment(context));
            }

            // Parse all path segments.
            while (context.CurrentToken.Kind == GlobTokenKind.PathSeparator)
            {
                context.Accept();
                items.Add(ParseSegment(context));
            }

            // Not an end of text token?
            if (context.CurrentToken.Kind != GlobTokenKind.EndOfText)
            {
                throw new InvalidOperationException("Expected EOT");
            }

            // Return the path node.
            return(GlobNodeRewriter.Rewrite(items));
        }
Example #2
0
        private GlobNode Parse(GlobParserContext context)
        {
            context.Accept();

            // Parse the root.
            var items = new List <GlobNode> {
                ParseRoot(context)
            };

            if (items.Count == 1 && items[0] is RelativeRootNode)
            {
                items.Add(ParseNode(context));
            }

            // Parse all path segments.
            while (context.CurrentToken?.Kind == GlobTokenKind.PathSeparator)
            {
                context.Accept();
                items.Add(ParseNode(context));
            }

            // Rewrite the items into a linked list.
            var result = GlobNodeRewriter.Rewrite(items);

            GlobNodeValidator.Validate(result);
            return(result);
        }