script

package
v0.0.0-...-377a6f8 Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: Apache-2.0 Imports: 1 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assignment

type Assignment struct {
	Pos lexer.Position

	Left        *Ternary    `parser:"@@"`                        // Expression or ident/reference to value to set
	AugmentedOp *string     `parser:"( @('+'|'-'|'*'|'/'|'%')?"` // Operation to perform on the result
	Declare     bool        `parser:"  @(':')?"`                 // := to declare in local scope, unset to use outer if already defined
	Op          string      `parser:"  @'='"`                    // assign value
	Right       *Assignment `parser:"  @@ )?"`                   // Expression to define value
}

type CallFunc

type CallFunc struct {
	Pos lexer.Position

	Name       string         `parser:"@Ident"`
	Parameters *ParameterList `parser:"'(' @@? ')'"`
}

type Catch

type Catch struct {
	CatchIdent string     `parser:"'catch' '(' @Ident ')'"` // catch var
	Statement  *Statement `parser:" @@"`                    // catch block
}

type DoWhile

type DoWhile struct {
	Pos lexer.Position

	Body      *Statement  `parser:"'do' @@"`
	Condition *Expression `parser:"'while' @@"`
}

type Expression

type Expression struct {
	Pos lexer.Position

	Right *Assignment `parser:"@@"`
}

type Finally

type Finally struct {
	Statement *Statement `parser:"'finally' @@"` // finally block
}

type For

type For struct {
	Pos lexer.Position

	Init      *Expression `parser:"'for' (@@)? ';'"`
	Condition *Expression `parser:"(@@)? ';'"`
	Increment *Expression `parser:"(@@)?"`
	Body      *Statement  `parser:"@@"`
}

type ForRange

type ForRange struct {
	Pos lexer.Position

	Key        string      `parser:"'for' @Ident ','"` // index in range, _ to ignore
	Value      string      `parser:"@Ident"`           // value in range, _ to ignore
	Declare    bool        `parser:"@(':')?"`          // := to declare in local scope
	Expression *Expression `parser:" '=' 'range' @@"`
	Body       *Statement  `parser:"@@"`
}

ForRange emulates go's "for i,v:=range expr {...}"

type FuncDec

type FuncDec struct {
	Pos lexer.Position

	Name       string      `parser:"@Ident"`
	Parameters []string    `parser:"'(' (@Ident (',' @Ident)*)? ')'"`
	FunBody    *Statements `parser:"@@"`
}

type Ident

type Ident struct {
	Pos lexer.Position

	PreIncDec  *IncDec       `parser:"(@@?)"`
	Ident      string        `parser:"@Ident"`
	PostIncDec *IncDec       `parser:"(@@?)"`
	Index      []*Expression `parser:"[ ('[' @@ ']')+ ]"`
}

func (*Ident) IsIndexed

func (i *Ident) IsIndexed() bool

IsIndexed returns true if ident[...] but no pre or post incDec

func (*Ident) IsPostIncDec

func (i *Ident) IsPostIncDec() bool

IsPostIncDec returns true if ident-- or ident++ but no array indices

func (*Ident) IsPreIncDec

func (i *Ident) IsPreIncDec() bool

IsPreIncDec returns true if --ident or ++ident but no array indices

type If

type If struct {
	Pos lexer.Position

	Condition *Expression `parser:"'if' @@"`
	Body      *Statement  `parser:"@@"`
	Else      *Statement  `parser:"('else' @@)?"`
}

type IncDec

type IncDec struct {
	Pos lexer.Position

	Decrement bool `parser:"( @('-' '-')"`
	Increment bool `parser:"  | @('+' '+') )"`
}

type Include

type Include struct {
	Pos lexer.Position

	Path []string `parser:"'include' ( @String (',' @String)* )"`
}

type KeyValue

type KeyValue struct {
	Pos lexer.Position

	Key   string      `parser:"@String"`
	Value *Expression `parser:"':' @@"`
}

KeyValue is "string": expression

type Level1

type Level1 struct {
	Pos lexer.Position

	Left  *Level2 `parser:"@@"`
	Op    string  `parser:"[ @( '|' '|' )"`
	Right *Level1 `parser:"  @@ ]"`
}

type Level2

type Level2 struct {
	Pos lexer.Position

	Left  *Level3 `parser:"@@"`
	Op    string  `parser:"[ @( '&' '&' )"`
	Right *Level2 `parser:"  @@ ]"`
}

type Level3

type Level3 struct {
	Pos lexer.Position

	Left  *Level4 `parser:"@@"`
	Op    string  `parser:"[ @( '=' '=' | '!' '=' | '<' '=' | '<' | '>' '=' | '>' )"`
	Right *Level3 `parser:"  @@ ]"`
}

type Level4

type Level4 struct {
	Pos lexer.Position

	Left  *Level5 `parser:"@@"`
	Op    string  `parser:"[ @( '+' | '-' )"`
	Right *Level4 `parser:"  @@ ]"`
}

type Level5

type Level5 struct {
	Pos lexer.Position

	Left  *Unary  `parser:"@@"`
	Op    string  `parser:"[ @( '*' '*' | '*' | '/' | '%' | '<' '<' | '>' '>' | '&' '^' | '&' | '|' | '^')"`
	Right *Level5 `parser:"  @@ ]"`
}

type ParameterList

type ParameterList struct {
	Args     []*Expression `parser:"(@@ (',' @@)*) "`
	Variadic bool          `parser:"    @('...')?"`
}

type Primary

type Primary struct {
	Pos lexer.Position

	Float         *float64    `parser:"( @Number"`
	Integer       *int        `parser:"  | @Int"`
	KeyValue      *KeyValue   `parser:"  | @@"`
	String        *string     `parser:"  | @String"`
	Null          bool        `parser:"  | @'null'"`
	Nil           bool        `parser:"  | @'nil'"`
	True          bool        `parser:"  | @'true'"`
	False         bool        `parser:"  | @'false'"`
	SubExpression *Expression `parser:"  | '(' @@ ')' "`
	CallFunc      *CallFunc   `parser:"  | ( @@"`
	Ident         *Ident      `parser:"    | @@ "`
	PointOp       string      `parser:"    ) [ @Period"`
	Pointer       *Primary    `parser:"      @@] )"`
}

type Repeat

type Repeat struct {
	Pos lexer.Position

	Body      *Statement  `parser:"'repeat' @@"`
	Condition *Expression `parser:"'until' @@"`
}

type ResourceList

type ResourceList struct {
	Resources []*Expression `parser:"'(' @@ (';' @@)* ')'"` // init block
}

type Return

type Return struct {
	Pos lexer.Position

	Result *Expression `parser:"'return' @@?"`
}

type Script

type Script struct {
	Pos lexer.Position

	Include  []*Include `parser:"( @@"`
	FunDec   []*FuncDec `parser:"| @@)+"`
	Includes map[string]interface{}
}

type Statement

type Statement struct {
	Pos  lexer.Position
	Next *Statement // Next statement within Statements block

	Break    bool      `parser:"  @'break'"`
	Continue bool      `parser:"| @'continue'"`
	DoWhile  *DoWhile  `parser:"| @@"`
	IfStmt   *If       `parser:"| @@"`
	For      *For      `parser:"| @@"`
	ForRange *ForRange `parser:"| @@"`
	Repeat   *Repeat   `parser:"| @@"`
	Return   *Return   `parser:"| @@"`
	Switch   *Switch   `parser:"| @@"`
	While    *While    `parser:"| @@"`

	// Try is after the main block as it's a bit more complex,
	// so it's better to place it here after the statements
	// when in the railroad diagrams.
	//
	// Otherwise, this could be in the above block
	Try *Try `parser:"| @@"`

	// These must be at the end
	Block      *Statements `parser:"| @@"`
	Expression *Expression `parser:"| @@"`
	Empty      bool        `parser:"| @';'"`
}

type Statements

type Statements struct {
	Pos lexer.Position

	Statements []*Statement `parser:"'{' @@* '}'"`
}

type Switch

type Switch struct {
	Pos lexer.Position

	Expression *Expression   `parser:"'switch' (@@)? '{'"`
	Case       []*SwitchCase `parser:"(@@)+ "`
	Default    *Statement    `parser:"('default' ':' @@ )? '}'"`
}

type SwitchCase

type SwitchCase struct {
	Pos lexer.Position

	Expression []*SwitchCaseExpression `parser:"'case' (@@ (',' @@)*) ':'"`
	Statement  *Statement              `parser:"@@"`
}

type SwitchCaseExpression

type SwitchCaseExpression struct {
	Pos lexer.Position

	String     *string     `parser:"(@String"`
	Expression *Expression `parser:"| @@)"`
}

type Ternary

type Ternary struct {
	Pos lexer.Position

	Left  *Level1 `parser:"@@"`
	True  *Level1 `parser:"( '?' @@"`
	False *Level1 `parser:"  ':' @@ )?"`
}

type Try

type Try struct {
	Pos lexer.Position

	Init    *ResourceList `parser:"'try' @@?"` // init block
	Body    *Statement    `parser:"@@"`        // body
	Catch   *Catch        `parser:"@@?"`       // catch block
	Finally *Finally      `parser:"@@?"`       // finally block
}

Try is based on Java's try {} catch {} finally{} construct.

The Try.Init section contains variables pointing to resources. If they implement TryClosable then they will be closed when the body is exited.

Try.Catch is called if an error occurs in the body. This is optional.

Try.Finally is called once the body & catch blocks have executed.

Note: If a value in Try.Init implements TryClosable that interface is invoked before any catch or finally block. This follows the order in Java.

type Unary

type Unary struct {
	Pos lexer.Position

	Op    string   `parser:"  ( @( '!' | '-' )"`
	Left  *Primary `parser:"    @@ )"`
	Right *Primary `parser:"| @@"`
}

type While

type While struct {
	Pos lexer.Position

	Condition *Expression `parser:"'while' @@"`
	Body      *Statement  `parser:"@@"`
}

Jump to

Keyboard shortcuts

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