/** * 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 './INode'; import { NodeList } from './NodeList'; import { TokenNode } from './TokenNode'; import { Node } from './Node'; import { ObjectCache } from './ObjectCache'; import { SkippedTokenNode, TriviaNode } from './TriviaNode'; import { SyntaxDiagnostic } from '../../diagnostics/SyntaxDiagnostic'; import { TokenKind } from '../TokenKind'; /** * Provides a factory service for creating tokens, trivia, and node lists. */ export declare class NodeFactory { /** * A trivia node representing a CRLF token. */ protected static readonly CRLF: TriviaNode; /** * A trivia node representing a LF token. */ protected static readonly LF: TriviaNode; /** * A trivia node representing a single whitespace character. */ protected static readonly SingleWhitespace: TriviaNode; /** * A trivia node representing two whitespace characters. */ protected static readonly DoubleWhitespace: TriviaNode; /** * A trivia node representing four whitespace characters. */ protected static readonly QuadrupleWhitespace: TriviaNode; /** * A list node containing a single whitespace character, used for leading trivia. */ protected static readonly SingleLeadingSpace: NodeList; /** * A list node containing two whitespace characters, used for leading trivia. */ protected static readonly TwoLeadingSpaces: NodeList; /** * A list node containing four whitespace characters, used for leading trivia. */ protected static readonly FourLeadingSpaces: NodeList; /** * A cache for lists of tokens or trivia. * * @todo Merge back into `NodeCache`? */ protected static readonly ListCache: ObjectCache; /** * A cache for tokens and trivia. * * @todo Determine the ideal size: 15=32768, 16=65536. */ protected static readonly NodeCache: ObjectCache; /** * A list of reusable tokens without leading trivia. */ protected static readonly TokensWithNoTrivia: TokenNode[]; /** * A list of reusable tokens with a single leading space. */ protected static readonly TokensWithSingleLeadingSpace: TokenNode[]; /** * The maximum number of children a node may have before being uncachable. */ private static readonly ChildLimit; /** * The maximum list size before lists are created with pre-calculated offsets. * A high value, will increase the compute time to find an offset, while a low * value will increase the memory usage of list nodes. * * @todo Determine the ideal limit. */ private static readonly ShortListLimit; /** * Creates a `NodeFactory` object. */ constructor(); /** * Determines if the token is one of the reusable token kinds. */ protected static isWellKnownKind(kind: TokenKind): boolean; /** * Creates a `NodeList` and caches it, if possible. */ createList(nodes: Node[], diagnostics?: SyntaxDiagnostic[]): NodeList; /** * Creates a missing token node. */ createMissingToken(kind: TokenKind, leadingTrivia: NodeList | null, diagnostics?: SyntaxDiagnostic[]): TokenNode; /** * Creates a skipped token node (which is actually a trivia node). */ createSkippedTokenTrivia(kind: TokenKind, fullWidth: number, diagnostics?: SyntaxDiagnostic[]): SkippedTokenNode; /** * Creates a token node that does not contain any leading trivia. */ createToken(kind: TokenKind, fullWidth: number, diagnostics?: SyntaxDiagnostic[]): TokenNode; /** * Creates a token node that also contains leading trivia. * * @param {TokenKind} kind * The type of token. * @param {number} tokenWidth * The full width of the token node (which at this point does not include * leading trivia). * @param {NodeList} leadingTrivia * A list of trivia nodes that were parsed ahead of the token. * @param {SyntaxDiagnostic[]=} diagnostics * An optional list of diagnostics that should be added to the token node. */ createTokenWithTrivia(kind: TokenKind, tokenWidth: number, leadingTrivia: NodeList, diagnostics?: SyntaxDiagnostic[]): TokenNode; /** * Creates a trivia node. */ createTrivia(kind: TokenKind, fullWidth: number, diagnostics?: SyntaxDiagnostic[]): TriviaNode; /** * @todo Document getCachedList(). * @todo Test performance when merged with `getCachedNode()`. */ protected getCachedList(node: T, hash: number): T; /** * @todo Document getCachedNode(). */ protected getCachedNode(node: T, hash: number): T; /** * Determines if a node containing a list of children is cacheable. */ protected isCacheableList(node: INode): boolean; /** * Determines if a node is cachebale. */ protected isCacheableNode(node: INode): boolean; }