compile

package
v0.0.0-...-2047864 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package compile compiles Suneido source code to byte code to be interpreted by the runtime package.

It uses a recursive descent parser that produces an AST that is then converted to byte code by codegen

Compiling constants (other than functions) produces values directly without going through an AST.

Expression parsing is shared with database queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Checked

func Checked(th *Thread, src string) (Value, []string)

func Constant

func Constant(src string) Value

Constant compiles an anonymous Suneido constant

func EvalString

func EvalString(th *Thread, s string) Value

EvalString executes string containing Suneido code i.e. string.Eval()

func NamedConstant

func NamedConstant(lib, name, src string, prevDef Value) Value

NamedConstant compiles a Suneido constant with a name e.g. a library record

func SetPos

func SetPos(result iSetPos, org, end int32)

Types

type Aspects

type Aspects interface {
	ast.Builder
	// contains filtered or unexported methods
}

Aspects allows tailoring the parser for different purposes. e.g. codegen, ast generation, queries, go gen

type Expr

type Expr = ast.Expr

type Labels

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

type Parser

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

func AstParser

func AstParser(src string) *Parser

func CheckParser

func CheckParser(src string, t *core.Thread) *Parser

func NewParser

func NewParser(src string) *Parser

func QueryParser

func QueryParser(src string) *Parser

func (*Parser) Const

func (p *Parser) Const() (result Value)

func (*Parser) Constant

func (*Parser) Constant(val core.Value) Expr

func (*Parser) Expression

func (p *Parser) Expression() ast.Expr

Expression parses a Suneido expression and builds an AST

func (*Parser) Function

func (p *Parser) Function() *ast.Function

Function parses a function (starting with the "function" keyword)

func (*Parser) InitFuncInfo

func (p *Parser) InitFuncInfo()

type ParserBase

type ParserBase struct {
	Aspects
	Lxr *Lexer

	// Item is the current lexical token etc.
	Item

	// EndPos is the end of the previous token
	EndPos int32

	// EqToIs treats Eq as Is for queries
	EqToIs bool
	// contains filtered or unexported fields
}

func (*ParserBase) Error

func (p *ParserBase) Error(args ...any) string

Error panics with "syntax Error at " + position It claims to return string so it can be called inside panic (so compiler knows we don't return)

func (*ParserBase) ErrorAt

func (p *ParserBase) ErrorAt(pos int32, args ...any) string

func (*ParserBase) Match

func (p *ParserBase) Match(token tok.Token)

func (*ParserBase) MatchIdent

func (p *ParserBase) MatchIdent() string

func (*ParserBase) MatchIf

func (p *ParserBase) MatchIf(token tok.Token) bool

func (*ParserBase) MustMatch

func (p *ParserBase) MustMatch(token tok.Token)

func (*ParserBase) Next

func (p *ParserBase) Next()

Next skips whitespace and comments to advance to the next token. It sets p.Item (Text, Pos, Token), p.EndPos, and p.newline.

Directories

Path Synopsis
Package ast defines the node types used by the compiler to build syntax trees
Package ast defines the node types used by the compiler to build syntax trees
Package check processes an ast.Function and finds used but (possibly) not initialized, and initialized but (possibly) not used.
Package check processes an ast.Function and finds used but (possibly) not initialized, and initialized but (possibly) not used.
Package lexer implements the lexical scanner for the Suneido language
Package lexer implements the lexical scanner for the Suneido language
Package tokens defines the lexical tokens
Package tokens defines the lexical tokens

Jump to

Keyboard shortcuts

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