parser

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package parser implements a Pratt (precedence-climbing) recursive descent parser for the Meow language. It consumes tokens via iter.Pull and produces an ast.Program AST.

Parsing Strategy

Expressions are parsed using a Pratt parser with the following precedence levels (lowest to highest):

||           logical OR
&&           logical AND
== !=        equality
< > <= >=    comparison
|=|          pipe
+ -          additive
* / %        multiplicative
! - (unary)  prefix operators
() []        call / index

Statements are dispatched by leading keyword:

nyan      variable declaration
meow      function definition
bring     return
sniff     if / else if / else
purr      while loop

Error Handling

Parse errors are collected as *ParseError values. When errors occur the parser attempts to continue, so multiple errors may be reported from a single parse.

Usage

p := parser.New(lexer.New(src, file).Tokens())
prog, errs := p.Parse()
if errs != nil {
    for _, e := range errs {
        fmt.Println(e)
    }
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ParseError

type ParseError struct {
	// Pos is the source location where the error occurred.
	Pos token.Position
	// Message is the error description.
	Message string
}

ParseError represents a parser error with a cat-themed message.

func (*ParseError) Error

func (e *ParseError) Error() string

type Parser

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

Parser produces an AST from a token stream.

func New

func New(tokens iter.Seq[token.Token]) *Parser

New creates a parser from an iter.Seq of tokens.

func (*Parser) Errors

func (p *Parser) Errors() []*ParseError

Errors returns parser errors.

func (*Parser) Parse

func (p *Parser) Parse() (*ast.Program, []*ParseError)

Parse parses the token stream into a Program AST.

Jump to

Keyboard shortcuts

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