parser

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Preprocess

func Preprocess(tokens []Token, absPath string, open func(name string) (io.ReadCloser, error), stack []string, defines *Defines) ([]Token, map[string][][]rune, *Defines, []string, []error)

Types

type Constant

type Constant struct {
	Token Token
}

type DataType

type DataType string
const (
	DTNumber DataType = "number"
	DTBool   DataType = "boolean"
	DTString DataType = "string"
	DTImage  DataType = "image"

	DTNumberList DataType = "number[]"
	DTStringList DataType = "string[]"
)

type Define

type Define struct {
	Name    Token
	Start   Position
	End     Position
	Content []Token
}

func (*Define) IsInScope

func (d *Define) IsInScope(at Position) bool

func (*Define) String

func (d *Define) String() string

type Defines

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

func NewDefines

func NewDefines() *Defines

func (*Defines) GetDefine

func (d *Defines) GetDefine(name string, at Position) (Define, bool)

func (*Defines) GetDefines

func (d *Defines) GetDefines(at Position) []Define

type Expr

type Expr interface {
	Accept(visitor ExprVisitor) error
	Type() DataType
	Position() (start, end Position)
}

type ExprBinary

type ExprBinary struct {
	Operator   Token
	Left       Expr
	Right      Expr
	ReturnType DataType
}

func (*ExprBinary) Accept

func (e *ExprBinary) Accept(visitor ExprVisitor) error

func (*ExprBinary) Position

func (e *ExprBinary) Position() (start, end Position)

func (*ExprBinary) Type

func (e *ExprBinary) Type() DataType

type ExprFuncCall

type ExprFuncCall struct {
	Name       Token
	Parameters []Expr
	ReturnType DataType
	CloseParen Token
}

func (*ExprFuncCall) Accept

func (e *ExprFuncCall) Accept(visitor ExprVisitor) error

func (*ExprFuncCall) Position

func (e *ExprFuncCall) Position() (start, end Position)

func (*ExprFuncCall) Type

func (e *ExprFuncCall) Type() DataType

type ExprGrouping

type ExprGrouping struct {
	OpenParen  Token
	CloseParen Token
	Expr       Expr
}

func (*ExprGrouping) Accept

func (e *ExprGrouping) Accept(visitor ExprVisitor) error

func (*ExprGrouping) Position

func (e *ExprGrouping) Position() (start, end Position)

func (*ExprGrouping) Type

func (e *ExprGrouping) Type() DataType

type ExprIdentifier

type ExprIdentifier struct {
	Name       Token
	ReturnType DataType
}

func (*ExprIdentifier) Accept

func (e *ExprIdentifier) Accept(visitor ExprVisitor) error

func (*ExprIdentifier) Position

func (e *ExprIdentifier) Position() (start, end Position)

func (*ExprIdentifier) Type

func (e *ExprIdentifier) Type() DataType

type ExprListInitializer

type ExprListInitializer struct {
	OpenBracket  Token
	CloseBracket Token
	Values       []Expr
	ReturnType   DataType
}

func (*ExprListInitializer) Accept

func (e *ExprListInitializer) Accept(visitor ExprVisitor) error

func (*ExprListInitializer) Position

func (e *ExprListInitializer) Position() (start, end Position)

func (*ExprListInitializer) Type

func (e *ExprListInitializer) Type() DataType

type ExprLiteral

type ExprLiteral struct {
	Token      Token
	End        Position
	ReturnType DataType
}

func (*ExprLiteral) Accept

func (e *ExprLiteral) Accept(visitor ExprVisitor) error

func (*ExprLiteral) Position

func (e *ExprLiteral) Position() (start, end Position)

func (*ExprLiteral) Type

func (e *ExprLiteral) Type() DataType

type ExprTypeCast

type ExprTypeCast struct {
	Target     Token
	Value      Expr
	ReturnType DataType
	CloseParen Token
}

func (*ExprTypeCast) Accept

func (e *ExprTypeCast) Accept(visitor ExprVisitor) error

func (*ExprTypeCast) Position

func (e *ExprTypeCast) Position() (start, end Position)

func (*ExprTypeCast) Type

func (e *ExprTypeCast) Type() DataType

type ExprUnary

type ExprUnary struct {
	Operator   Token
	Right      Expr
	ReturnType DataType
}

func (*ExprUnary) Accept

func (e *ExprUnary) Accept(visitor ExprVisitor) error

func (*ExprUnary) Position

func (e *ExprUnary) Position() (start, end Position)

func (*ExprUnary) Type

func (e *ExprUnary) Type() DataType

type ExprVisitor

type ExprVisitor interface {
	VisitIdentifier(expr *ExprIdentifier) error
	VisitExprFuncCall(expr *ExprFuncCall) error
	VisitTypeCast(expr *ExprTypeCast) error
	VisitLiteral(expr *ExprLiteral) error
	VisitListInitializer(expr *ExprListInitializer) error
	VisitUnary(expr *ExprUnary) error
	VisitBinary(expr *ExprBinary) error
	VisitGrouping(expr *ExprGrouping) error
}

type FuncParam

type FuncParam struct {
	Name Token
	Type Token
}

type ParseError

type ParseError struct {
	Token   Token
	Message string
}

func (ParseError) Error

func (p ParseError) Error() string

type Position

type Position struct {
	Line   int
	Column int
	Path   string
}

type ScanError

type ScanError struct {
	Pos     Position
	Message string
}

func (ScanError) Error

func (s ScanError) Error() string

type Stmt

type Stmt interface {
	Accept(visitor StmtVisitor) error
	Position() (start, end Position)
}

func Parse

func Parse(tokens []Token) ([]Stmt, []error)

type StmtAssignment

type StmtAssignment struct {
	Variable Token
	Operator Token
	Value    Expr
}

func (*StmtAssignment) Accept

func (s *StmtAssignment) Accept(visitor StmtVisitor) error

func (*StmtAssignment) Position

func (s *StmtAssignment) Position() (start, end Position)

type StmtCall

type StmtCall struct {
	Name       Token
	CloseParen Token
	Parameters []Expr
}

func (*StmtCall) Accept

func (s *StmtCall) Accept(visitor StmtVisitor) error

func (*StmtCall) Position

func (s *StmtCall) Position() (start, end Position)

type StmtConstDecl

type StmtConstDecl struct {
	Name        Token
	AssignToken Token
	Value       Expr
}

func (*StmtConstDecl) Accept

func (s *StmtConstDecl) Accept(visitor StmtVisitor) error

func (*StmtConstDecl) Position

func (s *StmtConstDecl) Position() (start, end Position)

type StmtEvent

type StmtEvent struct {
	At        Token
	Name      Token
	Parameter Expr
	Body      []Stmt
}

func (*StmtEvent) Accept

func (s *StmtEvent) Accept(visitor StmtVisitor) error

func (*StmtEvent) Position

func (s *StmtEvent) Position() (start, end Position)

type StmtEventDecl

type StmtEventDecl struct {
	Keyword Token
	Name    Token
}

func (*StmtEventDecl) Accept

func (s *StmtEventDecl) Accept(visitor StmtVisitor) error

func (*StmtEventDecl) Position

func (s *StmtEventDecl) Position() (start, end Position)

type StmtFuncDecl

type StmtFuncDecl struct {
	Name       Token
	CloseParen Token
	Params     []FuncParam
	Body       []Stmt
	StartLine  int
	EndLine    int
}

func (*StmtFuncDecl) Accept

func (s *StmtFuncDecl) Accept(visitor StmtVisitor) error

func (*StmtFuncDecl) Position

func (s *StmtFuncDecl) Position() (start, end Position)

type StmtIf

type StmtIf struct {
	Keyword   Token
	Condition Expr
	Body      []Stmt
	ElseBody  []Stmt
}

func (*StmtIf) Accept

func (s *StmtIf) Accept(visitor StmtVisitor) error

func (*StmtIf) Position

func (s *StmtIf) Position() (start, end Position)

type StmtLoop

type StmtLoop struct {
	Keyword   Token
	Condition Expr
	Body      []Stmt
}

func (*StmtLoop) Accept

func (s *StmtLoop) Accept(visitor StmtVisitor) error

func (*StmtLoop) Position

func (s *StmtLoop) Position() (start, end Position)

type StmtVarDecl

type StmtVarDecl struct {
	Name        Token
	DataType    DataType
	AssignToken Token
	Value       Expr
}

func (*StmtVarDecl) Accept

func (s *StmtVarDecl) Accept(visitor StmtVisitor) error

func (*StmtVarDecl) Position

func (s *StmtVarDecl) Position() (start, end Position)

type StmtVisitor

type StmtVisitor interface {
	VisitVarDecl(stmt *StmtVarDecl) error
	VisitConstDecl(stmt *StmtConstDecl) error
	VisitFuncDecl(stmt *StmtFuncDecl) error
	VisitEventDecl(stmt *StmtEventDecl) error
	VisitEvent(stmt *StmtEvent) error
	VisitCall(stmt *StmtCall) error
	VisitAssignment(stmt *StmtAssignment) error
	VisitIf(stmt *StmtIf) error
	VisitLoop(stmt *StmtLoop) error
}

type Token

type Token struct {
	Type             TokenType
	Lexeme           string
	Pos              Position
	EndPos           Position
	LineAfterInclude int
	Indent           int

	DataType DataType
	Literal  any
}

func Scan

func Scan(source io.Reader, path string) ([]Token, [][]rune, []error)

func (Token) String

func (t Token) String() string

type TokenType

type TokenType int
const (
	TkNewLine TokenType = iota
	TkAt
	TkOpenParen
	TkCloseParen
	TkOpenBracket
	TkCloseBracket
	TkColon
	TkDot
	TkComma

	TkBang
	TkOr
	TkAnd

	TkPlus
	TkPlusAssign
	TkMinus
	TkMinusAssign
	TkMultiply
	TkMultiplyAssign
	TkDivide
	TkDivideAssign
	TkModulus
	TkModulusAssign

	TkAssign
	TkEqual
	TkNotEqual
	TkLess
	TkGreater
	TkLessEqual
	TkGreaterEqual

	TkIf
	TkElif
	TkElse
	TkWhile
	TkFor
	TkVar
	TkConst
	TkFunc
	TkEvent

	TkIdentifier
	TkLiteral
	TkType
	TkPreprocessor

	TkEOF
)

Jump to

Keyboard shortcuts

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