Documentation
¶
Index ¶
- type Assignment
- type CallFunc
- type Catch
- type DoWhile
- type Expression
- type Finally
- type For
- type ForRange
- type FuncDec
- type Ident
- type If
- type IncDec
- type Include
- type KeyValue
- type Level1
- type Level2
- type Level3
- type Level4
- type Level5
- type ParameterList
- type Primary
- type Repeat
- type ResourceList
- type Return
- type Script
- type Statement
- type Statements
- type Switch
- type SwitchCase
- type SwitchCaseExpression
- type Ternary
- type Try
- type Unary
- type While
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 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) IsPostIncDec ¶
IsPostIncDec returns true if ident-- or ident++ but no array indices
func (*Ident) IsPreIncDec ¶
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 KeyValue ¶
type KeyValue struct { Pos lexer.Position Key string `parser:"@String"` Value *Expression `parser:"':' @@"` }
KeyValue is "string": expression
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 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 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 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.