/** * Written type syntax: `List`, `(a: A) -> B`, `Name.Member`, and the * optional suffix, plus the two refusals the type position owns — the retired * `Function` shorthand and a `=>` written where `->` belongs. * * The `>` problem lives here as well: a generic close that runs into the next * operator lexes as one token, so `checkTypeGreater`/`expectTypeGreater` on the * host split it, and every nested reference goes back through the parser's own * `parseTypeReference` so the depth budget is charged once per level. */ import type { TypeReference, TypeSyntax } from "../ast.ts"; import { type Diagnostic } from "../diagnostic.ts"; import { type Span } from "../source.ts"; import { type Token, type TokenKind } from "../token.ts"; export interface TypeSyntaxParserHost { advance(): Token; check(kind: TokenKind): boolean; checkTypeGreater(): boolean; checkWord(value: string): boolean; current(): Token; readonly diagnostics: Diagnostic[]; expect(kind: TokenKind, message: string): Token; expectTypeGreater(message: string): Token; index: number; match(kind: TokenKind): boolean; parseTypeReference(allowTrailingOptional?: boolean, initialized?: boolean): TypeReference; peekKind(distance: number): TokenKind; previous(): Token; /** CO-U5: the spellings this module already refused as type-parameter names. */ readonly refusedTypeParameterNames: ReadonlySet; readonly tokens: Token[]; validateExtensionTypeArguments(_name: string, _arguments: readonly TypeSyntax[], _nameSpan: Span): boolean; } export declare class TypeSyntaxParser { private readonly host; /** * CO-I4: the bare `Function` occurrences of the annotation being parsed, and * how deep in it we are. A whole annotation is one outermost * `parseTypeReferenceBody`; nested references — a type argument, a function * type's parameter, a union member — recurse back through it, so depth zero * on the way out is where an annotation is complete and its occurrences can * be settled. */ private readonly pendingRetiredFunctionShorthands; private referenceDepth; constructor(host: TypeSyntaxParserHost); /** * `initialized` says the annotation is a declaration's whole type and a value * follows it: `const g: Function = (a: number) => a + 1`. That is the one * position whose real signature is written beside the annotation, so the * occurrence is marked and left for the analyzer, which has the value's type. */ parseTypeReferenceBody(allowTrailingOptional: boolean, initialized?: boolean): TypeReference; /** * Every bare `Function` of the annotation just parsed, except the one a * declaration's initializer will answer. There is no value to read at the * others, so the sentence gives the shape of an arrow rather than a constant * example — `() -> null` was the shape the recovery happened to build, right * at no site, and pasting it back earned a second report at the initializer. */ private settleRetiredFunctionShorthands; private parseSingleTypeReference; /** * The two type syntaxes that wrap another one: the `readonly` view modifier, * and a parenthesized group. `null` means neither opened here — including a * `(` that opens a function type's parameter list, which the next form owns. */ private parseWrappedTypeSyntax; /** * A function type — `(name: T, ...rest: R) -> U`. Its parameter list is the * one place a type position takes names, optionality and a rest element, so * the three rules that order them are answered here. `null` means the next * token did not open one. */ private parseFunctionTypeSyntax; /** * What a dotted type-reference head names. A namespace-imported enum needs * three segments — `library.Status.pending` — so the path is read to its end * and refused whole rather than stopping the statement at the second dot: * the last segment is the member, and the segments before it qualify the * name that owns it. */ private typeNamePath; /** * D114 ③: `Function`, `Function` and `Function` were a second * spelling of the arrow function type, admitted before D28 and never given a * decision record of their own. The family is retired: a function type has * one spelling. Every type position recovers as the arrow the shorthand * meant, so analysis continues and a nested occurrence — `List>`, * a parameter inside another function type, an alias body, a record or class * field, an extern contract — is rewritten where it stands rather than * collapsing the annotation around it. * * `arguments_` is the written type argument list, or `null` for the bare * name. Answers `null` when `syntax` is not the retired shorthand, so a * caller can pass any type syntax through it. */ private retiredFunctionShorthand; private finishTypeReferenceSuffix; private makeOptionalTypeSyntax; /** * D63 rule 161: `=>` counts as evidence here even though it is the wrong * spelling. VelarScript writes the value-level arrow `=>` and the type-level * arrow `->`, and a TypeScript reader writes `(string, string) => T` in a * type position on the first try. Reading that as a *grouped* type produced * `Expected ')' after grouped type` plus five cascades, none of which said * `->` — a pile of cascades with no right answer in it is no diagnostic * (D42's standing criterion). Claiming the parenthesis as a function type * lets `reportTypePositionFatArrow` say the one thing worth saying, and the * rest of the annotation parses normally, so the cascade never starts. */ private isFunctionTypeParenthesis; /** The one diagnostic a `=>` in a type position gets, with its rewrite. */ private reportTypePositionFatArrow; } //# sourceMappingURL=type-syntax.d.ts.map