示例#1
0
        /// <summary>
        /// Iterate of parsing for the rule.
        /// </summary>
        /// <param name="iterate">Current iterate</param>
        /// <returns>Next iterate</returns>
        public IEnumerable<SyntacticParseIterateResult> Parse(SyntacticParseIterateResult iterate)
        {
            if (!iterate.NodeTypes.Any())
            {
                return Enumerable.Repeat(iterate, 1);
            }

            var nodeType = iterate.NodeTypes.First();
            return nodeType.Parse(iterate.TokenNodes, this)
                .Select(res => new SyntacticParseIterateResult(
                    iterate.Nodes.Concat(Enumerable.Repeat(res.Node, 1)),
                    iterate.NodeTypes.Skip(1), res.TokenNodes))
                .SelectMany(it => Parse(it));
        }
        public void Parse_EmptyNodeTypes_SingleIterate()
        {
            var iterate = new SyntacticParseIterateResult(
                Enumerable.Empty<ISyntacticNode>(),
                Enumerable.Empty<ISyntacticNodeType>(),
                Enumerable.Empty<TokenSyntacticNode>());

            var rules = Enumerable.Empty<IBlock>();
            var analyzer = new SyntacticAnalyzer(rules);
            var result = analyzer.Parse(iterate).ToArray();

            Assert.That(result.Count(),Is.EqualTo(1));
            Assert.That(result.First(), Is.EqualTo(iterate));
        }