lang

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintError

func PrintError(err error, dest io.Writer)

Types

type Array

type Array struct {
	Items []*Value
}

func (*Array) Add

func (a *Array) Add(value Value)

func (*Array) Clone

func (a *Array) Clone() Value

type AssignTarget

type AssignTarget struct {
	Obj  Expr
	Path []PathSeg
}

type BufferedInputFile

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

func (*BufferedInputFile) Name

func (f *BufferedInputFile) Name() string

func (*BufferedInputFile) NewReader

func (f *BufferedInputFile) NewReader() io.Reader

type ErrorGroup

type ErrorGroup struct {
	Errors []error
}

func (ErrorGroup) Error

func (err ErrorGroup) Error() string

type Evaluator

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

func EvalProgram

func EvalProgram(progSrc string, files []InputFile, rootSelectors []string, stdout io.Writer, fuzzing bool) (*Evaluator, error)

func EvalProgramContext

func EvalProgramContext(progSrc string, files []InputFile, rootSelectors []string, stdout io.Writer, fuzzing bool, ctx context.Context) (*Evaluator, error)

func NewEmptyEvaluator

func NewEmptyEvaluator(stdout io.Writer) Evaluator

func NewEvaluator

func NewEvaluator(prog Program, stdout io.Writer) Evaluator

func (*Evaluator) EvalExpr

func (e *Evaluator) EvalExpr(expr Expr) (Value, error)

func (*Evaluator) EvalStatement

func (e *Evaluator) EvalStatement(stmt Statement) error

func (*Evaluator) GetPrettyRootJson

func (e *Evaluator) GetPrettyRootJson() (string, error)

func (*Evaluator) GetUglyRootJson

func (e *Evaluator) GetUglyRootJson() (string, error)

func (*Evaluator) RunInBeginFileContext

func (e *Evaluator) RunInBeginFileContext(files []InputFile, rootSelectors []string, fn func() error) error

func (*Evaluator) RunProgram

func (e *Evaluator) RunProgram(prog Program, files []InputFile, rootSelectors []string) error

type Expr

type Expr interface {
	Node
	// contains filtered or unexported methods
}

type ExprArray

type ExprArray struct {
	Items []Expr
	// contains filtered or unexported fields
}

func (*ExprArray) String

func (expr *ExprArray) String() string

func (*ExprArray) Token

func (expr *ExprArray) Token() Token

type ExprAssign

type ExprAssign struct {
	Target  AssignTarget
	Value   Expr
	OpToken Token
}

func (*ExprAssign) String

func (expr *ExprAssign) String() string

func (*ExprAssign) Token

func (expr *ExprAssign) Token() Token

type ExprBinary

type ExprBinary struct {
	Left    Expr
	Right   Expr
	OpToken Token
}

func (*ExprBinary) String

func (expr *ExprBinary) String() string

func (*ExprBinary) Token

func (expr *ExprBinary) Token() Token

type ExprCall

type ExprCall struct {
	Func Expr
	Args []Expr
}

func (*ExprCall) String

func (expr *ExprCall) String() string

func (*ExprCall) Token

func (expr *ExprCall) Token() Token

type ExprFunction

type ExprFunction struct {
	Ident string
	Args  []string
	Body  Statement
	// contains filtered or unexported fields
}

func (*ExprFunction) String

func (expr *ExprFunction) String() string

func (*ExprFunction) Token

func (expr *ExprFunction) Token() Token

type ExprIdentifier

type ExprIdentifier struct {
	Ident string
	// contains filtered or unexported fields
}

func (*ExprIdentifier) String

func (expr *ExprIdentifier) String() string

func (*ExprIdentifier) Token

func (expr *ExprIdentifier) Token() Token

type ExprLiteral

type ExprLiteral struct {
	Literal string
	// contains filtered or unexported fields
}

func (*ExprLiteral) String

func (expr *ExprLiteral) String() string

func (*ExprLiteral) Token

func (expr *ExprLiteral) Token() Token

type ExprMatch

type ExprMatch struct {
	Value Expr
	Cases []MatchCase
	// contains filtered or unexported fields
}

func (*ExprMatch) String

func (expr *ExprMatch) String() string

func (*ExprMatch) Token

func (expr *ExprMatch) Token() Token

type ExprObject

type ExprObject struct {
	Items []ObjectKeyValue
	// contains filtered or unexported fields
}

func (*ExprObject) String

func (expr *ExprObject) String() string

func (*ExprObject) Token

func (expr *ExprObject) Token() Token

type ExprRange

type ExprRange struct {
	Start Expr
	End   Expr
	// contains filtered or unexported fields
}

func (*ExprRange) String

func (expr *ExprRange) String() string

func (*ExprRange) Token

func (expr *ExprRange) Token() Token

type ExprTernary

type ExprTernary struct {
	Cond      Expr
	TrueExpr  Expr
	FalseExpr Expr
}

func (*ExprTernary) String

func (expr *ExprTernary) String() string

func (*ExprTernary) Token

func (expr *ExprTernary) Token() Token

type ExprUnary

type ExprUnary struct {
	Expr    Expr
	OpToken Token
	Target  AssignTarget // ++ and -- only
	Postfix bool
}

func (*ExprUnary) String

func (expr *ExprUnary) String() string

func (*ExprUnary) Token

func (expr *ExprUnary) Token() Token

type FnWithContext

type FnWithContext struct {
	Expr  *ExprFunction
	Scope *scope
}

type InputFile

type InputFile interface {
	Name() string
	NewReader() io.Reader
}

func NewBufferedInputFile

func NewBufferedInputFile(name string, content []byte) InputFile

func NewStreamingInputFile

func NewStreamingInputFile(name string, reader io.Reader) InputFile

type JsonError

type JsonError struct {
	Message  string
	FileName string
}

func (JsonError) Error

func (err JsonError) Error() string

type LValue

type LValue interface {
	Get() Value
	Set(Value)
}

type Lexer

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

func NewLexer

func NewLexer(src string) Lexer

func (*Lexer) GetLineAndCol

func (l *Lexer) GetLineAndCol(pos int) (string, int, int)

func (*Lexer) GetString

func (l *Lexer) GetString(token *Token) string

func (*Lexer) Next

func (l *Lexer) Next() (Token, error)

func (*Lexer) Regex

func (l *Lexer) Regex() (Token, error)

the parser calls this when it finds a '/' in prefix position

type MatchCase

type MatchCase struct {
	Exprs []Expr
	Body  Statement
}

type Node

type Node interface {
	Token() Token
}

type Object

type Object struct {
	Items map[string]*Value
	Keys  []string
}

func (*Object) Get

func (o *Object) Get(key string) (*Value, bool)

func (*Object) Set

func (o *Object) Set(key string, val Value)

type ObjectKeyValue

type ObjectKeyValue struct {
	Key   string
	Value Expr
}

type Parser

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

func NewParser

func NewParser(l *Lexer) Parser

func (*Parser) Parse

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

func (*Parser) ParseExpression

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

func (*Parser) ParseStatement

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

type PathSeg

type PathSeg struct {
	Field string
	Expr  Expr
	// contains filtered or unexported fields
}

type Precedence

type Precedence uint8
const (
	PrecNone Precedence = iota
	PrecAssign
	PrecTernary
	PrecLogical
	PrecComparison
	PrecAddition
	PrecMultiplication
	PrecPower
	PrecPostfix
	PrecUnary
	PrecCall
	PrecGroup
)

type Program

type Program struct {
	Rules     []Rule
	Functions []ExprFunction
}

type Rule

type Rule struct {
	Kind    RuleKind
	Pattern Expr
	Body    Statement
}

type RuleKind

type RuleKind uint8
const (
	BeginRule RuleKind = iota
	EndRule
	BeginFileRule
	EndFileRule
	PatternRule
)

func (RuleKind) String

func (k RuleKind) String() string

type RuntimeError

type RuntimeError struct {
	Message string
	Line    int
	Col     int
	SrcLine string
}

func (RuntimeError) Error

func (err RuntimeError) Error() string

type Statement

type Statement interface {
	Node
	// contains filtered or unexported methods
}

type StatementBlock

type StatementBlock struct {
	Body []Statement
	// contains filtered or unexported fields
}

func (*StatementBlock) Token

func (stmt *StatementBlock) Token() Token

type StatementBreak

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

func (*StatementBreak) Token

func (stmt *StatementBreak) Token() Token

type StatementContinue

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

func (*StatementContinue) Token

func (stmt *StatementContinue) Token() Token

type StatementExit

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

func (*StatementExit) Token

func (stmt *StatementExit) Token() Token

type StatementExpr

type StatementExpr struct {
	Expr Expr
}

func (*StatementExpr) Token

func (stmt *StatementExpr) Token() Token

type StatementFor

type StatementFor struct {
	PreExpr  Expr
	Expr     Expr
	PostExpr Expr
	Body     Statement
	// contains filtered or unexported fields
}

func (*StatementFor) Token

func (stmt *StatementFor) Token() Token

type StatementForIn

type StatementForIn struct {
	Ident      *ExprIdentifier
	IndexIdent *ExprIdentifier
	Iterable   Expr
	Body       Statement
}

func (*StatementForIn) Token

func (stmt *StatementForIn) Token() Token

type StatementIf

type StatementIf struct {
	Expr     Expr
	Body     Statement
	ElseBody Statement
}

func (*StatementIf) Token

func (stmt *StatementIf) Token() Token

type StatementLet

type StatementLet struct {
	Ident *ExprIdentifier
	Value Expr
}

func (*StatementLet) Token

func (stmt *StatementLet) Token() Token

type StatementNext

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

func (*StatementNext) Token

func (stmt *StatementNext) Token() Token

type StatementPrint

type StatementPrint struct {
	Args []Expr
	// contains filtered or unexported fields
}

func (*StatementPrint) Token

func (stmt *StatementPrint) Token() Token

type StatementReturn

type StatementReturn struct {
	Expr Expr
}

func (*StatementReturn) Token

func (stmt *StatementReturn) Token() Token

type StatementWhile

type StatementWhile struct {
	Expr Expr
	Body Statement
}

func (*StatementWhile) Token

func (stmt *StatementWhile) Token() Token

type StreamingInputFile

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

func (*StreamingInputFile) Name

func (f *StreamingInputFile) Name() string

func (*StreamingInputFile) NewReader

func (f *StreamingInputFile) NewReader() io.Reader

type SyntaxError

type SyntaxError struct {
	Message string
	Line    int
	Col     int
	SrcLine string
}

func (SyntaxError) Error

func (err SyntaxError) Error() string

type Token

type Token struct {
	Tag TokenTag
	Pos int
	Len int
	// contains filtered or unexported fields
}

func (*Token) GetLineAndCol

func (t *Token) GetLineAndCol() (string, int, int)

type TokenTag

type TokenTag uint8
const (
	EOF TokenTag = iota
	Error
	Ident
	Str
	Regex
	Num
	Begin
	End
	BeginFile
	EndFile
	Print
	Function
	Return
	If
	Else
	For
	While
	In
	Match
	Break
	Continue
	Next
	Newline
	Exit
	Null
	Is
	Let
	True          // true
	False         // false
	LCurly        // {
	RCurly        // }
	LSquare       // [
	RSquare       // ]
	LParen        // (
	RParen        // )
	LessThan      // <
	GreaterThan   // >
	Dollar        // $
	Comma         // ,
	Dot           // .
	Equal         // =
	EqualEqual    // ==
	BangEqual     // !=
	LessEqual     // <=
	GreaterEqual  // >=
	Colon         // :
	SemiColon     // ;
	Plus          // +
	Minus         // -
	Multiply      // *
	Power         // **
	Divide        // /
	PlusEqual     // +=
	MinusEqual    // -=
	MultiplyEqual // *=
	DivideEqual   // /=
	Tilde         // ~
	BangTilde     // !~
	AmpAmp        // &&
	PipePipe      // ||
	Arrow         // =>
	Bang          // !
	PlusPlus      // ++
	MinusMinus    // --
	Percent       // %
	Question      // ?
)

func (TokenTag) String

func (i TokenTag) String() string

type Value

type Value struct {
	Tag      ValueTag
	Str      *string
	Num      *float64
	Bool     *bool
	Array    *Array
	Obj      *Object
	NativeFn func(*Evaluator, []*Value, *Value) (*Value, error)
	Fn       FnWithContext
	Regexp   *regexp.Regexp
	Proto    *Value
	Binding  *Value
}

func NewArray

func NewArray() Value

func NewObject

func NewObject() Value

func NewString

func NewString(str string) Value

func NewValue

func NewValue(srcVal any) Value

func (*Value) Compare

func (v *Value) Compare(b *Value) (int, error)

func (*Value) GetMember

func (v *Value) GetMember(member Value) (Value, bool, error)

func (*Value) MarshalJSON

func (v *Value) MarshalJSON() ([]byte, error)

func (*Value) Not

func (v *Value) Not() *Value

func (*Value) PrettyString

func (v *Value) PrettyString(quote bool) string

convert a value to prettified string

func (*Value) String

func (v *Value) String() string

convert a value to a string suitable for string concatentation, object indexing, etc

type ValueTag

type ValueTag uint8
const (
	ValueStr      ValueTag = iota // string
	ValueBool                     // bool
	ValueNum                      // number
	ValueArray                    // array
	ValueObj                      // object
	ValueNil                      // null
	ValueNativeFn                 // nativefunction
	ValueFn                       // function
	ValueRegex                    // regex
	ValueUnknown                  // unknown
)

func (ValueTag) String

func (i ValueTag) String() string

Jump to

Keyboard shortcuts

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