parser

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExpandedLexer added in v0.3.0

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

ExpandedLexer tokenizes .glyphx source code (human-readable expanded syntax) It recognizes keywords like "route", "let", "return" and converts them to the same token types as their symbol equivalents (@, $, >).

func NewExpandedLexer added in v0.3.0

func NewExpandedLexer(input string) *ExpandedLexer

NewExpandedLexer creates a new ExpandedLexer for .glyphx files

func (*ExpandedLexer) Tokenize added in v0.3.0

func (l *ExpandedLexer) Tokenize() ([]Token, error)

Tokenize returns all tokens from the expanded syntax input

type LexError

type LexError struct {
	Message string
	Line    int
	Column  int
	Source  string
	Char    byte
}

LexError represents a lexical analysis error

func (*LexError) Error

func (e *LexError) Error() string

type Lexer

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

Lexer tokenizes GLYPH source code

func NewLexer

func NewLexer(input string) *Lexer

New creates a new Lexer

func (*Lexer) Tokenize

func (l *Lexer) Tokenize() ([]Token, error)

Tokenize returns all tokens from the input

type ParseError

type ParseError struct {
	Message string
	Line    int
	Column  int
	Source  string
	Hint    string
}

ParseError represents a parsing error with context

func (*ParseError) Error

func (e *ParseError) Error() string

type Parser

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

Parser converts tokens to AST

func NewParser

func NewParser(tokens []Token) *Parser

NewParser creates a new Parser

func NewParserWithSource

func NewParserWithSource(tokens []Token, source string) *Parser

NewParserWithSource creates a new Parser with source code for better error messages

func (*Parser) Parse

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

Parse parses tokens into a Module

func (*Parser) ParseExpression added in v0.4.0

func (p *Parser) ParseExpression() (ast.Expr, error)

ParseExpression parses a single expression from the token stream. This is used by the REPL and other tools that need to parse expressions directly.

func (*Parser) ParseStatement added in v0.4.0

func (p *Parser) ParseStatement() (ast.Statement, error)

ParseStatement parses a single statement from the token stream. This is used by the REPL and other tools that need to parse statements directly.

type Token

type Token struct {
	Type    TokenType
	Literal string
	Line    int
	Column  int
}

Token represents a lexical token

type TokenType

type TokenType int

TokenType represents the type of token

const (
	// Special tokens
	ILLEGAL TokenType = iota
	EOF
	NEWLINE

	// Symbols
	AT         // @
	COLON      // :
	DOLLAR     // $
	PLUS       // +
	MINUS      // -
	STAR       // *
	SLASH      // /
	PERCENT    // %
	GREATER    // >
	GREATER_EQ // >=
	LESS       // <
	LESS_EQ    // <=
	BANG       // !
	NOT_EQ     // !=
	EQ_EQ      // ==
	QUESTION   // ?
	TILDE      // ~
	AMPERSAND  // &
	AND        // &&
	OR         // ||

	// Delimiters
	LPAREN   // (
	RPAREN   // )
	LBRACE   // {
	RBRACE   // }
	LBRACKET // [
	RBRACKET // ]
	COMMA    // ,
	DOT      // .
	ARROW    // ->
	PIPE     // |
	PIPE_OP  // |>
	EQUALS   // =

	// Literals
	IDENT   // identifier or path
	STRING  // "string"
	INTEGER // 123
	FLOAT   // 123.45
	TRUE    // true
	FALSE   // false
	NULL    // null
	WHILE   // while

	// Keywords
	SWITCH    // switch
	CASE      // case
	DEFAULT   // default
	FOR       // for
	IN        // in
	MACRO     // macro
	QUOTE     // quote
	MATCH     // match
	WHEN      // when (for guards in match)
	FATARROW  // =>
	DOTDOTDOT // ...
	ASYNC     // async
	AWAIT     // await
	IMPORT    // import
	FROM      // from
	AS        // as
	MODULE    // module
	CONST     // const
	TEST      // test
	ASSERT    // assert
	BREAK     // break
	CONTINUE  // continue
)

func (TokenType) String

func (t TokenType) String() string

String returns a string representation of the token type

Jump to

Keyboard shortcuts

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