/** * Copyright 2017 Matt Acosta * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { INode } from '../node/INode'; import { ISyntaxNode } from './ISyntaxNode'; import { ISyntaxNodeOrList } from './ISyntaxNode'; import { ISyntaxToken } from './ISyntaxToken'; import { ISyntaxTriviaList } from './ISyntaxTriviaList'; import { SyntaxDiagnostic } from '../../diagnostics/SyntaxDiagnostic'; import { SyntaxNodeFilter } from './ISyntaxNodeQueryable'; import { TextSpan } from '../../text/TextSpan'; /** * Provides a base class for non-terminal nodes in a syntax tree. */ export declare abstract class SyntaxNodeBase implements ISyntaxNodeOrList { /** * @inheritDoc */ readonly parent: ISyntaxNode | null; /** * An object containing the metadata for this node. */ protected readonly node: INode; /** * The absolute location of this node in the source text. */ protected readonly offset: number; /** * Constructs a `SyntaxNodeBase` object. * * @param {INode} node * An object containing the metadata for this node. * @param {ISyntaxNode|null} parent * The syntax node containing this node, if any. * @param {number} offset * The absolute location of this node in the source text. */ constructor(node: INode, parent: ISyntaxNode | null, offset: number); /** * The number of child nodes and tokens. * * @todo Unused. */ protected get count(): number; /** * The width of the node, including trivia. * * This is a performance optimization to avoid the overhead of creating and * using a `TextSpan` object. * * @todo Unused. */ protected get fullWidth(): number; /** * @inheritDoc */ get hasError(): boolean; /** * Determines if the current node contains a list of child nodes and tokens. * * @todo Unused. */ protected get isList(): boolean; /** * @inheritDoc */ get isToken(): boolean; /** * @inheritDoc */ get containsDiagnostics(): boolean; /** * @inheritDoc */ get containsSkippedText(): boolean; /** * @inheritDoc */ get fullSpan(): TextSpan; /** * Determines if the node contains a child token with leading trivia. */ get hasLeadingTrivia(): boolean; /** * @inheritDoc */ get isMissing(): boolean; /** * The leading trivia of the first token within the node. */ get leadingTrivia(): ISyntaxTriviaList | null; /** * @inheritDoc */ get span(): TextSpan; /** * Finds the child token at the given offset. * * @param {SyntaxNodeBase} parent * The parent node. * @param {number} offset * The offset of the token, relative to the start of the syntax tree. * * @todo Experimental. */ protected static getToken(parent: SyntaxNodeBase, offset: number): ISyntaxToken; /** * Gets a descendant node or token based on a relative index. * * @param {SyntaxNodeBase} parent * The parent node. * @param {number} relativeIndex * The child index relative to any lists contained in the parent. * * @todo Experimental. */ protected static relativeChildAt(parent: SyntaxNodeBase, relativeIndex: number): ISyntaxNode | ISyntaxToken; /** * @inheritDoc */ allChildren(): Array; /** * @inheritDoc */ ancestors(): ISyntaxNodeOrList[]; /** * @inheritDoc */ ancestorsAndSelf(): ISyntaxNodeOrList[]; /** * @inheritDoc */ childNodes(): ISyntaxNode[]; /** * @inheritDoc */ childTokens(): ISyntaxToken[]; /** * @inheritDoc */ contains(node: ISyntaxNode | null): boolean; /** * @inheritDoc */ equals(value: ISyntaxNodeOrList): boolean; /** * @inheritDoc */ findChildNode(span: TextSpan, innermostNode?: boolean): ISyntaxNodeOrList; /** * @inheritdoc */ findChildToken(offset: number): ISyntaxToken; /** * @inheritDoc */ firstAncestorOrSelf(nodeFilter?: SyntaxNodeFilter): ISyntaxNodeOrList | null; /** * @inheritDoc */ firstToken(includeZeroWidth?: boolean): ISyntaxToken | null; /** * @inheritDoc */ getAllChildren(): IterableIterator; /** * @inheritDoc */ getAllChildrenReversed(): IterableIterator; /** * @inheritDoc */ getAncestors(): IterableIterator; /** * @inheritDoc */ getAncestorsAndSelf(): IterableIterator; /** * @inheritDoc */ getChildNodes(): IterableIterator; /** * @inheritDoc */ getChildTokens(): IterableIterator; /** * @inheritDoc */ getDiagnostics(): IterableIterator; /** * @inheritDoc */ lastToken(includeZeroWidth?: boolean): ISyntaxToken | null; /** * Gets the child node at the given index, if it has been created. * * @see SyntaxNodeBase.defineChildAt() */ protected abstract childAt(index: number): ISyntaxNodeOrList | null; /** * Gets the child node at the given index, creating it, if necessary. * * @todo Merge into `childAt()` by adding a `createNode` parameter? */ protected abstract defineChildAt(index: number): ISyntaxNodeOrList | null; /** * Calculates the offset of the child at the given index. */ protected offsetAt(index: number): number; /** * Determines the relative index of a child. */ protected relativeIndexAt(index: number): number; /** * @todo Document getTriviaDiagnostics(). */ private getTriviaDiagnostics; }