antlr-ng
Version:
Next generation ANTLR Tool
50 lines (49 loc) • 2.48 kB
TypeScript
import { IntervalSet } from "antlr4ng";
import type { IPosition } from "../support/helpers.js";
import type { Grammar } from "../tool/Grammar.js";
export declare class CharSupport {
/** When converting ANTLR char and string literals, here is the value set of escape chars. */
static readonly ANTLRLiteralEscapedCharValue: Map<string, number>;
/** Given a char, we need to be able to show as an ANTLR literal. */
static readonly ANTLRLiteralCharValueEscape: Map<number, string>;
private static readonly hexRegex;
/**
* @param c The code point to convert to an ANTLR char literal.
*
* @returns a string representing the escaped char for code c. E.g., if c has value 0x100, you will get "\\u0100".
* ASCII gets the usual char (non-hex) representation. Non-ASCII characters are spit out as \\uXXXX or
* \\u{XXXXXX} escapes.
*/
static getANTLRCharLiteralForChar(c: number): string;
/**
* Given a literal like (the 3 char sequence with single quotes) 'a', returns the int value of 'a'. Converts
* escape sequences here also.
*
* @param literal The char literal to convert.
*
* @returns the code point value of the char literal or -1 if not a single char literal.
*/
static getCharValueFromGrammarCharLiteral(literal: string): number;
/**
* Scans the given literal for escape sequences and returns the string.
*
* @param literal The string literal to examine.
* @param grammar The grammar with details for error reporting.
* @param position The position of the literal in the input string (needed for error reporting).
*
* @returns the string value of the literal or null if the literal is invalid.
*/
static getStringFromGrammarStringLiteral(literal: string, grammar?: Grammar, position?: IPosition): string | null;
/**
* Given char x or \\t or \\u1234 returns the char value. Unnecessary escapes like '\{' yield -1.
*
* @param cstr The char to convert.
*
* @returns the code point value of the char or -1 if not a single char literal.
*/
static getCharValueFromCharInGrammarLiteral(cstr: string): number;
static parseHexValue(cstr: string, startOff: number, endOff: number): number;
static capitalize(s: string): string;
static getIntervalSetEscapedString(intervalSet: IntervalSet): string;
static getRangeEscapedString(codePointStart: number, codePointEnd: number): string;
}