protected static void AssertChildCount([NotNull] ParseTreeNode parseNode, int expectedChildCount) { var actualChildCount = parseNode.EnsureNotNull().ChildNodes.Count; if (actualChildCount != expectedChildCount) { throw new InvalidOperationException( $@"The expected child node count is {expectedChildCount} while actual is {actualChildCount}."); } }
protected static TNode[] GetChildren <TNode>([NotNull] ParseTreeNode parseNode) where TNode : AstNodeBase { var result = parseNode .EnsureNotNull() .ChildNodes .Select(obj => obj.EnsureNotNull().AstNode.EnsureNotNull()) .Cast <TNode>() .ToArray(); return(result); }
protected static TNode GetChildNode <TNode>([NotNull] ParseTreeNode parseNode, int index) where TNode : AstNodeBase { if (!(parseNode.EnsureNotNull().ChildNodes[index].AstNode is TNode result)) { throw new InvalidOperationException( $@"The child node at index {index} is expected to be of type '{ typeof(TNode).GetQualifiedName()}'."); } return(result); }
protected static string GetTokenText([NotNull] ParseTreeNode parseNode) { return(parseNode.EnsureNotNull().Token.EnsureNotNull().Text.EnsureNotNull()); }