parser

package
v1.3.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package parser turns a craftgo source buffer into an ast.File.

The implementation is a hand-rolled recursive-descent parser. It runs the lexer on construction (in New) so callers do not interact with tokens directly. Errors are accumulated as lexer.Diagnostic entries; the parser always returns a (possibly partial) AST so that LSP / formatters / linting can keep working in the presence of mistakes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser holds the token stream and accumulates diagnostics. Use New to construct one and call Parser.Parse to drive parsing. Parsers are not safe for concurrent use; create one per file.

func New

func New(filename, src string) *Parser

New tokenises src (with filename used for diagnostics) and returns a Parser ready to call Parser.Parse. Lexer-level errors are propagated into the parser's diagnostics so callers only need to inspect one slice.

func (*Parser) Diagnostics

func (p *Parser) Diagnostics() []lexer.Diagnostic

Diagnostics returns all errors collected during lexing and parsing.

func (*Parser) Parse

func (p *Parser) Parse() *ast.File

Parse consumes the entire token stream and returns an *ast.File. The returned file is non-nil even when diagnostics were recorded, so callers can offer best-effort downstream behaviour.

File-level decorators (those that appear BEFORE `package`) are attached to `f.Decorators`; decorators with no following `package` keyword are passed to the first declaration instead.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL