/** * 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 { Character } from './Character'; import { ISourceText } from '../text/ISourceText'; import { LexerBase } from './Lexer'; import { PhpLexerState } from './PhpLexerState'; import { PhpVersion } from './PhpVersion'; import { TemplateSpan } from './TemplateSpan'; import { Token } from './Token'; import { TokenKind } from '../language/TokenKind'; /** * Tokenizes PHP source text. * * IMPORTANT: This class is performance critical and must make every effort to * allow native optimization by the V8 engine. */ export declare class PhpLexer extends LexerBase { /** * A map of cast types to their associated tokens. */ protected static readonly CastTokens: ReadonlyMap; /** * A map of keywords to their associated tokens. */ protected static readonly KeywordTokens: ReadonlyMap; /** * Determines if short open tags "*" T_VARIABLE Start LookingForProperty * "${" T_DOLLAR_OPEN_... Start LookingForVariableName * "{$" "{" Start InScript * "\"" "\"" End current state * "ANY" T_ENCAPSED_AND... Continue * * LookingForVariableName * Input Token Transition * "LABEL[" T_STRING_VARNAME End current state, Start InScript * "LABEL}" T_STRING_VARNAME End current state, Start InScript * "ANY" --- End current state, Start Inscript * * LookingForProperty * Input Token Transition * "\s" T_WHITESPACE Continue * "->" T_OBJECT_OPERATOR Continue * "LABEL" T_STRING End current state * "ANY" --- End current state * * InVariableOffset * Input Token Transition Remarks * "\d" T_NUM_STRING Continue Also includes 0x and 0b numbers. * "LABEL" T_STRING Continue * "$LABEL" T_VARIABLE Continue * "TOKEN" "TOKEN" Continue Also includes '{', '}', '"', '`'. * "]" "]" End current state * "\s" T_ENCAPSED_AND... End current state Also includes '\\', '\'', and '#'. * "ANY" --- Throw */ protected scanInterpolatedString(delimiter: Character | string, spans?: TemplateSpan[], startLength?: number): number; /** * Scans the offset of an interpolated variable. * * Unlike PHP's implementation which also attempts to lex a variety of * invalid tokens, this method only scans for a sequence of characters that * result in a valid production. This has several benefits: * * - The lexer doesn't have to try and tokenize a bunch of garbage. * - Invalid characters don't become uncacheable skipped tokens, which * results in a faster parse and fewer objects being created. * - The lexer can immediately go back to scanning the string, which makes it * much more likely to produce the desired tokens (PHP doesn't even try to * recover gracefully). */ protected scanInterpolatedVariableOffset(): number; /** * Scans the remaining portion of a line comment until a line break or close * tag is found. */ protected scanLineComment(): number; /** * Scans the remaining portion of a multiple-line comment. */ protected scanMultipleLineComment(): number; /** * Scans the remaining portion of a nowdoc until the end label is found. */ protected scanNowdoc(label: string): number; /** * Scans for constant text within a nowdoc string. */ protected scanNowdocString(): number; /** * Scans a decimal integer or floating-point number. * * A long consists of: * - One or more digits. * * A double consists of: * - Zero or more digits followed by a decimal point and one or more digits. * - One or more digits followed by a decimal point and zero or more digits. * * A double with exponent consists of: * - A long or double followed by 'e' or 'E', then an optional '+' or '-', and * finally a long. */ protected scanNumber(): number; /** * Scans for the digits of a number. * * @param {(ch: number) => boolean} predicate * A callback used to determine what characters are valid digits in the * number. * * @returns A tuple containing the total length of the scanned digits, and * how many separators were present. */ protected scanNumberPart(predicate: (ch: number) => boolean): [number, number]; /** * Scans a hexadecimal or binary number. If not found, a decimal * or octal number is scanned instead. */ protected scanNumberWithPrefix(): number; /** * Scans for an octal escape sequence. */ protected scanOctalEscape(): number; /** * Scans the contents of a constant string. */ protected scanSingleQuoteString(): number; /** * Scans for constant text within a string template. */ protected scanStringTemplateLiteral(): number; /** * Scans for a unicode escape sequence. */ protected scanUnicodeEscape(): number; /** * Scans any remaining whitespace characters. */ protected scanWhitespace(): number; /** * Determines if an object operator and property name are present at the * scanner's current location. */ protected startsWithObjectProperty(): boolean; /** * Returns a keyword or identifier token for the scanned text. */ protected textToIdentifierToken(): TokenKind; /** * Attempts to scan for a heredoc or nowdoc string. If not found, a left * shift token is scanned instead. */ protected tryScanHeredoc(spans: TemplateSpan[]): number; /** * Attempts to scan for a variable name in a string template that uses "${}" * syntax to explicity specify the name. If not found, nothing is scanned. */ protected tryScanInterpolatedVariableName(): number; /** * Attempts to scan for a PHP script opening tag. If not found, nothing is * scanned. */ protected tryScanOpenTag(): number; /** * Attempts to scan a full type cast token. If not found, only the opening * parenthesis is scanned instead. * * @todo Disabled optimization: Unsupported phi use of const or let variable. */ protected tryScanTypeCast(): number; /** * Attempts to scan for the opening label or a heredoc string. If not found, * nothing is scanned. */ private tryScanHeredocStartLabel; }