import { EventEmitter } from "events"; import * as CC from "./Chunk"; import { ParseError } from "../parser"; import { Token } from "../lexer"; import { BrsError } from "../Error"; /** The results of a Preprocessor's filtering pass. */ export interface FilterResults { /** The tokens remaining after preprocessing. */ processedTokens: ReadonlyArray; /** The encountered during preprocessing. */ errors: ReadonlyArray; } /** * A simple pre-processor that executes BrightScript's conditional compilation directives by * selecting chunks of tokens to be considered for later evaluation. */ export declare class Preprocessor implements CC.Visitor { private constants; /** Allows consumers to observe errors as they're detected. */ readonly events: EventEmitter<[never]>; /** The set of errors encountered when pre-processing conditional compilation directives. */ errors: ParseError[]; /** * Emits an error via this processor's `events` property, then throws it. * @param err the ParseError to emit then throw */ private addError; /** * Filters the tokens contained within a set of chunks based on a set of constants. * @param chunks the chunks from which to retrieve tokens * @param bsConst the set of constants defined in a BrightScript `manifest` file's `bs_const` property * @returns an object containing an array of `errors` and an array of `processedTokens` filtered by conditional * compilation directives included within */ filter(chunks: ReadonlyArray, bsConst: Map): FilterResults; /** * Handles a simple chunk of BrightScript tokens by returning the tokens contained within. * @param chunk the chunk to extract tokens from * @returns the array of tokens contained within `chunk` */ visitBrightScript(chunk: CC.BrightScript): Token[]; /** * Handles a BrightScript `#const` directive, creating a variable in-scope only for the * conditional compilation pass. * @param chunk the `#const` directive, including the name and variable to use for the constant * @returns an empty array, since `#const` directives are always removed from the evaluated script. */ visitDeclaration(chunk: CC.Declaration): never[]; /** * Throws an error, stopping "compilation" of the program. * @param chunk the error to report to users * @throws a JavaScript error with the provided message */ visitError(chunk: CC.Error): never; /** * Produces tokens from a branch of a conditional-compilation `#if`, or no tokens if no branches evaluate to `true`. * @param chunk the `#if` directive, any `#else if` or `#else` directives, and their associated BrightScript chunks. * @returns an array of tokens to include in the final executed script. */ visitIf(chunk: CC.If): Token[]; /** * Resolves a token to a JavaScript boolean value, or throws an error. * @param token the token to resolve to either `true`, `false`, or an error * @throws if attempting to reference an undefined `#const` or if `token` is neither `true`, `false`, nor an identifier. */ evaluateCondition(token: Token): boolean; }