parser

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package parser provides the lexer and parser for the English programming language.

Package parser – human-readable error messages and hint strings.

Every message that can be shown to a programmer when their code contains a syntax error lives here. Edit this file to improve wording, add extra examples, or translate the text – no other file needs to change.

Convention

  • msg* constants are the primary error description ("what went wrong").
  • hint* constants give corrective guidance ("how to fix it").
  • msgFmt* / hintFmt* constants are fmt.Sprintf format strings whose %s / %q placeholders are filled in by the call site using runtime token values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lexer

type Lexer = tokeniser.Lexer

Lexer is a type alias for the shared tokeniser.Lexer so that all existing callers (cmd, vm, lsp, transpiler …) continue to work without change while both the parser and the highlight package share a single tokenisation implementation.

func NewLexer

func NewLexer(input string) *Lexer

NewLexer creates a new Lexer for the given input.

type Parser

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

Parser transforms tokens into an AST

func NewParser

func NewParser(tokens []token.Token) *Parser

NewParser creates a new parser for the given tokens

func (*Parser) Parse

func (p *Parser) Parse() (*ast.Program, error)

Parse parses the tokens and returns the AST

type SyntaxError

type SyntaxError struct {
	Msg  string // human-readable description of what went wrong
	Line int    // 1-based source line (0 = unknown)
	Col  int    // 1-based source column (0 = unknown)
	Hint string // optional guidance for the programmer
}

SyntaxError is a structured parse-time error. It satisfies the stacktraces.SyntaxError interface so the renderer can display it with a dedicated "Syntax Error" header, line/column information, and an optional user-friendly hint.

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

Error implements the standard error interface.

func (*SyntaxError) SyntaxCol

func (e *SyntaxError) SyntaxCol() int

SyntaxCol implements stacktraces.SyntaxError.

func (*SyntaxError) SyntaxHint

func (e *SyntaxError) SyntaxHint() string

SyntaxHint implements stacktraces.SyntaxError.

func (*SyntaxError) SyntaxLine

func (e *SyntaxError) SyntaxLine() int

SyntaxLine implements stacktraces.SyntaxError.

func (*SyntaxError) SyntaxMessage

func (e *SyntaxError) SyntaxMessage() string

SyntaxMessage implements stacktraces.SyntaxError.

Jump to

Keyboard shortcuts

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