public static NodeArray <Node> ToNodeArray <T>(this IEnumerable <T> nodes) where T : Node { var nodeArray = new NodeArray <Node>(); nodeArray.AddRange(nodes.Cast <Node>()); return(nodeArray); }
private NodeArray <T> ParseDelimitedList <T>(ParsingContext kind, ParseElement <T> parseElement, bool?considerSemicolonAsDelimiter = null) where T : Node { var saveParsingContext = parsingContext; var result = new NodeArray <T>(); var commaStart = -1; parsingContext |= (ParsingContext)(1 << (int)kind); while (true) { if (IsListElement(kind, false)) { result.Add(ParseListElement(kind, parseElement)); commaStart = scanner.TokenPosition; if (ParseOptional(SyntaxKind.CommaToken)) { continue; } commaStart = -1; if (IsListTerminator(kind)) { break; } ParseExpected(SyntaxKind.CommaToken); if (considerSemicolonAsDelimiter.HasValue && considerSemicolonAsDelimiter.Value && this.Token == SyntaxKind.SemicolonToken && !scanner.HasPrecedingLineBreak) { NextToken(); } continue; } if (IsListTerminator(kind)) { break; } if (AbortParsingListOrMoveToNextToken(kind)) { break; } } result.End = GetNodeEnd(); parsingContext = saveParsingContext; return(result); }
private NodeArray <T> ParseList <T>(ParsingContext kind, ParseElement <T> parseElement) where T : Node { var result = new NodeArray <T>(); ParsingContext saveParsingContext = parsingContext; parsingContext |= (ParsingContext)(1 << (int)kind); while (!IsListTerminator(kind)) { if (IsListElement(kind, false)) { var element = ParseListElement <T>(kind, parseElement); result.Add(element); } } return(result); }