/** * 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 { ISourceText } from '../../text/ISourceText'; import { ISyntaxNode } from './ISyntaxNode'; import { ISyntaxToken, SyntaxTokenFilter } from './ISyntaxToken'; import { ISyntaxTriviaList } from './ISyntaxTriviaList'; import { SyntaxTriviaFilter } from './ISyntaxTrivia'; import { TextSpan } from '../../text/TextSpan'; import { TokenKind } from '../TokenKind'; /** * Represents a terminal node in a syntax tree. */ export declare class SyntaxToken implements ISyntaxToken { /** * @inheritDoc */ readonly parent: ISyntaxNode; /** * @todo Experimental. */ protected readonly index: number; /** * An object containing the metadata for this token. */ protected readonly node: INode | null; /** * The absolute location of this token in the source text. * * @see SyntaxToken.span * @see SyntaxToken.fullSpan */ protected readonly offset: number; /** * Constructs a `SyntaxToken` object. */ constructor(node: INode | null, parent: ISyntaxNode, offset: number, index: number); /** * @todo Unused. */ protected get endOffset(): number; /** * @inheritDoc */ get containsDiagnostics(): boolean; /** * @inheritDoc */ get fullSpan(): TextSpan; /** * @inheritDoc */ get isMissing(): boolean; /** * @inheritDoc */ get isToken(): boolean; /** * @inheritDoc */ get leadingTrivia(): ISyntaxTriviaList | null; /** * @inheritDoc */ get kind(): TokenKind; /** * @inheritDoc */ get span(): TextSpan; /** * Determines if the token has a width (not including trivia). */ static hasWidth(token: ISyntaxToken): boolean; /** * Gets the text of a token. * * @param {ISyntaxToken} token * A token in a syntax tree. * @param {ISourceText} text * The text of the syntax tree that contains the token. */ static getText(token: ISyntaxToken, text: ISourceText): string; /** * Attempts to get the first token matching the given filter(s). * * @param {ISyntaxToken} token * The token to search. * @param {SyntaxTokenFilter=} tokenFilter * A callback used to limit what tokens are returned. This filter is * applied to the current token and tokens found within structured * trivia, if any. If not provided, any token will match. * @param {SyntaxTriviaFilter=} triviaFilter * A callback used to limit what structured trivia nodes are searched. * If not provided, trivia is not searched. */ static tryGetFirstToken(token: ISyntaxToken, tokenFilter?: SyntaxTokenFilter, triviaFilter?: SyntaxTriviaFilter): ISyntaxToken | null; /** * Attempts to get the last token matching the given filter(s). * * @param {ISyntaxToken} token * The token to search. * @param {SyntaxTokenFilter=} tokenFilter * A callback used to limit what tokens are returned. This filter is * applied to the current token and tokens found within structured * trivia, if any. If not provided, any token will match. * @param {SyntaxTriviaFilter=} triviaFilter * A callback used to limit what structured trivia nodes are searched. * If not provided, trivia is not searched. */ static tryGetLastToken(token: ISyntaxToken, tokenFilter?: SyntaxTokenFilter, triviaFilter?: SyntaxTriviaFilter): ISyntaxToken | null; /** * Attempts to get the next token matching the given filter(s). * * @param {ISyntaxToken} token * The token to search. * @param {SyntaxTokenFilter=} tokenFilter * A callback used to limit what tokens are returned. This filter is * applied to the current token and tokens found within structured * trivia, if any. If not provided, any token will match. * @param {SyntaxTriviaFilter=} triviaFilter * A callback used to limit what structured trivia nodes are searched. * If not provided, trivia is not searched. */ static tryGetNextToken(token: ISyntaxToken, tokenFilter?: SyntaxTokenFilter, triviaFilter?: SyntaxTriviaFilter): ISyntaxToken | null; /** * Attempts to get the previous token matching the given filter(s). * * @param {ISyntaxToken} token * The token to search. * @param {SyntaxTokenFilter=} tokenFilter * A callback used to limit what tokens are returned. This filter is * applied to the current token and tokens found within structured * trivia, if any. If not provided, any token will match. * @param {SyntaxTriviaFilter=} triviaFilter * A callback used to limit what structured trivia nodes are searched. * If not provided, trivia is not searched. */ static tryGetPreviousToken(token: ISyntaxToken, tokenFilter?: SyntaxTokenFilter, triviaFilter?: SyntaxTriviaFilter): ISyntaxToken | null; /** * @inheritDoc */ equals(value: SyntaxToken): boolean; /** * @inheritDoc */ nextToken(includeZeroWidth?: boolean): ISyntaxToken | null; /** * @inheritDoc */ previousToken(includeZeroWidth?: boolean): ISyntaxToken | null; }