export { translateImportPaths } from "./formatters/index.js"; export { readHeader } from "./readers/index.js"; /** * Position in a source file represented by a line number and a column number. */ export type Pos = { line: number; column: number; }; /** * Source map site containing all necessary information to link a symbol in the output generated by the compiler process back to the original piece of source code. */ export type Site = { file: string; line: number; column: number; /** * Optional range end of the Site */ end: Pos | undefined; /** * The description is used to attach context information to UPLC symbols to provide more detailed stack traces */ description: string | undefined; /** * Outputs "::" */ toString: () => string; /** * Creates a copy of the Site containing the given description */ withDescription: (description: string) => Site; }; export type CompilerErrorKind = "ReferenceError" | "SyntaxError" | "TypeError"; /** * An error thrown by the compiler process. Can be a reference, syntax or type error. */ export type CompilerError = { name: "CompilerError"; kind: CompilerErrorKind; /** * Source code location of error */ site: Site; /** * Displayed message */ message: string; /** * Unformatted message */ originalMessage: string; /** * When an {@link ErrorCollector} has more than 1 error and {@link ErrorCollector.throw} is called, the first error is thrown and the remaining are attached to it. */ otherErrors: CompilerError[] | undefined; }; /** * An `ErrorCollector` accumulates `CompilerError`s so that at the end of the * compilation process all errors are logged at once, and all errors can be * displayed in the IDE. * * Use {@link makeErrorCollector} to create a new `ErrorCollector`. */ export type ErrorCollector = { /** * The list of compiler errors collected */ errors: CompilerError[]; /** * Adds a syntax error */ syntax: (site: Site, msg: string) => void; /** * Adds a type error */ type: (site: Site, msg: string) => void; /** * Adds a reference error */ reference: (site: Site, msg: string) => void; /** * Throws an error if it contains some errors */ throw: () => void; }; /** * The key is the char index in the new source (which is being mapped to the old source using the Site value) */ export type SourceMap = Map; /** * `Source` wraps a string so that it can be passed by reference. * * `Source` can also be given additional context information, which is useful during debugging. * * `Source` is used by textual-Uplc, IR and Helios. * * Instantiate a `Source` instance with {@link makeSource}. */ export type Source = { content: string; /** * provided filename (or script name parsed from script header) */ name: string; /** * optional helios-specific script/module name, parsed from the script header */ moduleName?: string | undefined; /** * optional helios-specific script purpose, parsed from the script header */ purpose?: string | undefined; /** * optional project name in which the module is defined */ project?: string | undefined; /** * optional additional info about the source */ moreInfo?: string | undefined; /** * length is a separate field because of performance */ length: number; lineEndLocations: number[]; getChar: (i: number) => string; getWord: (i: number) => string; getPosition: (i: number) => [number, number]; pretty: () => string; }; /** * `BoolLiteral` is a {@link Token} variant that represents the keywords `true` or `false`. * * Instantiate a `BoolLiteral` token with {@link makeBoolLiteral}. */ export type BoolLiteral = { site: Site; kind: "bool"; value: boolean; isEqual: (other: Token) => boolean; toString: (preserveWhitespace?: boolean) => string; }; /** * Instantiate a `ByteArrayLiteral` token with {@link makeByteArrayLiteral}. */ export type ByteArrayLiteral = { site: Site; kind: "bytes"; value: number[]; isEqual: (other: Token) => boolean; toString: (preserveWhitespace?: boolean) => string; }; /** * Instantiate a `Comment` token with {@link makeComment}. */ export type Comment = { site: Site; kind: "comment"; value: string; isEqual: (other: Token) => boolean; toString: (preserveWhitespace?: boolean) => string; }; export type GroupKind = "(" | "{" | "["; export type GroupCloseKind = ")" | "}" | "]"; export type GenericGroup = { site: Site; kind: GroupKind; fields: F[]; separators: SymbolToken[]; error: string | undefined; isGroup: (kind?: string | undefined, nFields?: number) => boolean; toString: (preserveWhitespace?: boolean) => string; }; /** * Can't alias GenericGroup because that gives a circular reference error */ export type TokenGroup = { site: Site; kind: GroupKind; fields: Token[][]; separators: SymbolToken[]; error: string | undefined; isGroup: (kind?: string | undefined, nFields?: number) => boolean; toString: (preserveWhitespace?: boolean) => string; }; /** * Instantiate a `IntLiteral` token with {@link makeIntLiteral}. */ export type IntLiteral = { site: Site; kind: "int"; value: bigint; isEqual: (other: Token) => boolean; toString: (preserveWhitespace?: boolean) => string; }; /** * `NL` is a {@link Token} variant that represents a newline character. * * Newline characters are used for Automatic Semicolon Insertion. * * Instaniate a `NL` token with {@link makeNL}. */ export type NL = { site: Site; kind: "newline"; isEqual: (other: Token) => boolean; toString: (preserveWhitespace?: boolean) => string; }; /** * Instantiate a `RealLiteral` token with {@link makeRealLiteral}. */ export type RealLiteral = { site: Site; kind: "real"; value: bigint; isEqual: (other: Token) => boolean; toString: (preserveWhitespace?: boolean) => string; }; /** * Instantiate a `StringLiteral` with {@link makeStringLiteral}. */ export type StringLiteral = { site: Site; kind: "string"; value: string; isEqual: (other: Token) => boolean; toString: (preserveWhitespace?: boolean) => string; }; /** * `SymbolToken` is a {@link Token} variant that represent a non-alphanumeric/non-whitespace sequence of characters. * * Instantiate a `SymbolToken` with {@link makeSymbolToken}. */ export type SymbolToken = { site: Site; kind: "symbol"; value: T; isEqual: (other: Token) => other is SymbolToken; matches: (value: string | ReadonlyArray) => boolean; toString: (preserveWhitespace?: boolean) => string; }; /** * Instantiate a `Word` token with {@link makeWord}. */ export type Word = { site: Site; kind: "word"; value: string; isEqual: (other: Token) => boolean; isInternal: () => boolean; isKeyword: () => boolean; matches: (value: string | ReadonlyArray) => boolean; toString: (preserveWhitespace?: boolean) => string; }; export type Token = (BoolLiteral | ByteArrayLiteral | Comment | IntLiteral | NL | RealLiteral | StringLiteral | SymbolToken | TokenGroup | Word); /** * Instantiate a `Tokenizer` with {@link makeTokenizer}. */ export type Tokenizer = { errors: ErrorCollector; tokenize: (nestGroups?: boolean) => Token[]; stream: () => Generator; }; /** * Token matchers are combined with {@link TokenReader} in order to match sequences of tokens. * The following token matchers are available: * - {@link anySymbol} * - {@link anyWord} * - {@link reallit} * - {@link wildcard} (any Token) * - {@link boollit} * - {@link byteslit} * - {@link group} * - {@link intlit} * - {@link oneOf} * - {@link strlit} * - {@link symbol} * - {@link word} */ export type TokenMatcher = { matches: (t: Token) => T | undefined; toString: () => string; }; /** * Maps a tuple of matchers to a tuple of equivalent token types: * - TokenMatcher<{@link BoolLiteral}> is mapped to {@link BoolLiteral} * - TokenMatcher<{@link ByteArrayLiteral}> is mapped to {@link ByteArrayLiteral} * - TokenMatcher<{@link Comment} is mapped to {@link Comment} * - TokenMatcher<{@link IntLiteral} is mapped to {@link IntLiteral} * - TokenMatcher<{@link RealLiteral} is mapped to {@link RealLiteral} * - TokenMatcher<{@link StringLiteral} is mapped to {@link StringLiteral} * - TokenMatcher<{@link SymbolToken} is mapped to {@link SymbolToken} * - TokenMatcher<{@link TokenGroup}> is augmented and mapped {@link GenericGroup}<{@link TokenReader}> * - TokenMatcher<{@link Word}> is mapped to {@link Word} */ export type MapMatchersToTokens = { [M in keyof Matchers]: Matchers[M] extends TokenMatcher ? (T extends GenericGroup ? GenericGroup : T) : never; }; /** * Instantiate a `TokenReader` with {@link makeTokenReader}. */ export type TokenReader = { /** * Current position of `TokenReader` in `tokens`. */ pos: number; /** * Tokens optionally excluding newlines */ tokens: Token[]; /** * Tokens including newlines (can be used for automatic semicolon injection) */ originalTokens: Token[]; /** * Unread tokens optionally excluding newlines */ rest: Token[]; errors: ErrorCollector; assert: (...matchers: [...Matchers]) => TokenReader; end: () => void; findNext: (...matchers: [...Matchers]) => [TokenReader, ...MapMatchersToTokens] | undefined; findNextMatch: (...matchers: [...Matchers]) => [TokenReader, ...MapMatchersToTokens] | undefined; findLast: (...matchers: [...Matchers]) => [TokenReader, ...MapMatchersToTokens] | undefined; findLastMatch: (...matchers: [...Matchers]) => [TokenReader, ...MapMatchersToTokens] | undefined; readUntil: (...matchers: [...Matchers]) => TokenReader; isEof: () => boolean; matches: (...matchers: [...Matchers]) => UnwrapSingleton> | undefined; endMatch: (throwFail?: boolean | string) => TokenReader; unreadToken: () => void; /** * Creates a new TokenReader with semicolons inserted right before newlines if: * - not first/last in the token list * - not surrounded by multiline operators */ insertSemicolons: (multilineOperators: string[]) => TokenReader; }; import type { UnwrapSingleton } from "@helios-lang/type-utils"; export { isCompilerError, makeErrorCollector, makeReferenceError, makeSyntaxError, makeTypeError } from "./errors/index.js"; export { anySymbol, anyWord, boollit, byteslit, group, intlit, isDummySite, makeBoolLiteral, makeByteArrayLiteral, makeComment, makeDummySite, makeGroup, makeHeliosSource, makeIntLiteral, makeNL, makeRealLiteral, makeSource, makeStringLiteral, makeSymbolToken, makeTokenizer, makeTokenReader, makeTokenSite, makeWord, mergeSites, oneOf, reallit, strlit, symbol, wildcard, word, REAL_PRECISION } from "./tokens/index.js"; //# sourceMappingURL=index.d.ts.map