parser

package
v0.84.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BpLowest  = iota // 0 — expression terminator
	BpAssign         // 1 — =
	BpOr             // 2 — ||
	BpAnd            // 3 — &&
	BpEqual          // 4 — == !=
	BpCompare        // 5 — < <= > >=
	BpAdd            // 6 — + -
	BpMul            // 7 — * / %
	BpUnary          // 8 — prefix ! and - (not in BindingPower, used directly)
	BpCall           // 9 — fn()  expr[]
)

Binding power is the "gravitational pull" of an infix operator. The higher the value, the more tightly the operator binds its operands.

Variables

This section is empty.

Functions

This section is empty.

Types

type Position

type Position struct {
	Line   int
	Column int
}

func (Position) String

func (p Position) String() string

type Token

type Token struct {
	Type        TokenType
	Lexeme      string
	StartLine   int
	StartColumn int
	EndLine     int
	EndColumn   int
}

func NewToken

func NewToken(typ TokenType, m *machines.Match) Token

func Parse

func Parse(input string) ([]Token, error)

func (Token) StartPos

func (t Token) StartPos() Position

type TokenType

type TokenType int
const (
	EOF TokenType = -1 + iota
	WHITESPACE
	COMMENT

	KW_IF
	KW_ELSE
	KW_TRUE
	KW_FALSE
	KW_NULL
	KW_ABORT
	KW_DEL
	KW_FOR
	KW_IN

	IDENT

	LIT_FLOAT
	LIT_INTEGER
	LIT_STRING     // "double quoted"
	LIT_STRING_RAW // s'\n\n'
	LIT_REGEX      // r'\d+'
	LIT_TIMESTAMP  // t'2024-01-01T00:00:00Z'

	OP_AND    // &&
	OP_OR     // ||
	OP_EQ     // ==
	OP_NEQ    // !=
	OP_LTE    // <=
	OP_GTE    // >=
	OP_ASSIGN // =
	OP_LT     // <
	OP_GT     // >

	LPAREN   // (
	RPAREN   // )
	LBRACE   // {
	RBRACE   // }
	LBRACKET // [
	RBRACKET // ]

	PLUS      // +
	MINUS     // -
	STAR      // *
	SLASH     // /
	PERCENT   // %
	BANG      // !
	COMMA     // ,
	COLON     // :
	SEMICOLON // ;
	DOT       // .
)

func (TokenType) BindingPower

func (t TokenType) BindingPower() int

func (TokenType) String

func (t TokenType) String() string

Jump to

Keyboard shortcuts

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