Exemplo n.º 1
0
        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}.");
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 protected static string GetTokenText([NotNull] ParseTreeNode parseNode)
 {
     return(parseNode.EnsureNotNull().Token.EnsureNotNull().Text.EnsureNotNull());
 }