The self-hosted parser (ADR 0043 stage 2). A port of the reference recursive-descent/Pratt parser over the Talk lexer's token stream, validated construct-by-construct against the frozen dump corpus.
Errors carry the reference diagnostic code and rendered message so the validation dump matches byte-for-byte.
The reference parser streams tokens with previous/current/next plus a previous-before-newline cursor for span ends. Here the scanner runs up front and pos indexes the token list: current is tokens[pos] (end-of-stream yields EOF tokens forever, like the reference lexer), and the previous-before-newline cursor is recovered by scanning backward past newline tokens.
API Reference
Structs
struct Fail
A structured parser diagnostic with stable code, message, and blame range.
struct DocumentedDecl
One decl with its attached leading comment group, in source order (Docs.tlk's attachment pass). ParseOutcome.docs carries these only when the parse ran through the documenting entry point.
struct ParseOutcome
The AST prefix, diagnostics, trivia, and metadata produced by one category parse.
Functions
func describe_kind(kind: TokenKind) -> String
A kind described for a user-facing message (the reference describe_kind): literal spellings in backticks, classes in words.
func parse_file_source(source: String) -> ParseOutcome
Scans and parses a complete source file, including file-level imports.
func parse_block_items_source(source: String) -> ParseOutcome
Scans and parses declarations and statements using block grammar.
func parse_members_source(source: String) -> ParseOutcome
Parse a whole input as nominal-body members (ADR 0026): the grammar struct and extension bodies use, so a macro expansion spliced into a declaration body yields member declarations — methods, not plain functions.
func parse_expr_source(source: String) -> ParseOutcome
Scans and parses the complete input as exactly one expression.
func parse_pattern_source(source: String) -> ParseOutcome
Scans and parses the complete input as exactly one pattern.
func parse_type_source(source: String) -> ParseOutcome
Scans and parses the complete input as exactly one type annotation.
func parse_file_tokens(source: String, input: TokenRange) -> ParseOutcome
Parses a pre-tokenized complete file without scanning or reconstructing text.
func parse_block_items_tokens(source: String, input: TokenRange) -> ParseOutcome
Parses pre-tokenized declarations and statements using block grammar.
func parse_expr_tokens(source: String, input: TokenRange) -> ParseOutcome
Parses a pre-tokenized range as exactly one expression.
func parse_pattern_tokens(source: String, input: TokenRange) -> ParseOutcome
Parses a pre-tokenized range as exactly one pattern.
func parse_type_tokens(source: String, input: TokenRange) -> ParseOutcome
Parses a pre-tokenized range as exactly one type annotation.
func parse_decl_tokens(source: String, input: TokenRange) -> ParseOutcome
Parses a pre-tokenized range as exactly one top-level declaration.
func parse_decl_tokens_in(source: String, input: TokenRange, context_tag: Int) -> ParseOutcome
Parses one pre-tokenized declaration in its eventual insertion context.
func parse_decl_source(source: String) -> ParseOutcome
Convenience source entry for the declaration category. Production macro expansion uses parse_decl_tokens after balanced capture.
func lex_tokens(source: String) -> [MetaToken]
MARK: The lexing surface (ADR 0043 Stage 5)