Documentation ¶
Overview ¶
Package ast provides structures for representing parsed source code.
The structures in this package will be initialized from the parser package.
Index ¶
- func TypeOf(node Node) (*types.Type, error)
- type Argument
- type Array
- type Assert
- type Assign
- type Binary
- type Break
- type Call
- type Case
- type Comment
- type Continue
- type ErrorScope
- type Finally
- type For
- type Func
- type Group
- type Identifier
- type If
- type Import
- type In
- type Interpolate
- type Key
- type KeyValue
- type Literal
- type Map
- type Node
- type On
- type Raise
- type Return
- type Switch
- type Test
- type Unary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Assign ¶
type Assign struct { // There will always be at least one Lefts element. Lefts []Node // There may be one Right element, or the same number of elements as Lefts. Rights []Node }
Assign is a specific case of Binary, just for "=".
type Binary ¶
type Binary struct { // Op is TokenPlus, TokenMinusAssign, etc. It will never be TokenAssign, // this special case is handled in an Assign operation. Op string Left, Right Node }
Binary is an binary operator operation.
type Call ¶
type Call struct { // Expr is the expression that returns the function to be called. Expr Node // Arguments contains zero or more elements that represent each of the // arguments respectively. Arguments []Node Pos string }
Call represents a function call with zero or more arguments.
type Case ¶
type Case struct { // Conditions will always contain at least one element. Conditions []Node // Statements may be nil. Statements []Node Pos string }
Case represents a switch case statement.
type Comment ¶
type Comment struct { Comment string // Func will be the name of the function this comment is attached to; // otherwise it will be empty. Func string Pos string }
Comment represents a single or multiline comment. All characters immediately following `//` are part of the comment (even the proceeding space) up to but not including the new line.
type ErrorScope ¶ added in v0.15.0
type ErrorScope struct { // Statements is what will be run in this scope. It is allowed to be nil. Statements []Node // On can have zero or more elements. On []*On Pos string // Finally is optional. An empty finally block and no finally block are // treated the same way. Finally *Finally }
ErrorScope represents the try/on error scope.
func (*ErrorScope) Position ¶ added in v0.15.0
func (node *ErrorScope) Position() string
Position returns the position.
type Finally ¶ added in v0.15.3
type Finally struct { // Index is the unique counter for each finally block in this function. It // is used to activate and deactivate finally blocks by the VM at runtime. Index int // Statement may be nil. Statements []Node Pos string }
Finally will always be called on success or failure.
type For ¶
type For struct {
// All of Init, Condition and Next may be nil.
Init, Condition, Next Node
// Statements may be nil.
Statements []Node
Pos string
}
For represents a for loop.
type Func ¶
type Func struct { // Name is the name of the function being declared. Name string // Arguments may contain zero or more elements. They will always be in the // order in which their are declared. Arguments []*Argument // Returns may contain zero or more types. They will always be in the order // in which they are declared. Returns []*types.Type // Statements can have zero or more elements for each of the ordered // discreet statements in the function. Statements []Node Pos string }
Func represents the definition of a function.
func NewFuncFromPrototype ¶ added in v0.17.2
NewFuncFromPrototype is a hack for now. It should be derived directly from the type itself.
func (*Func) IsConstructor ¶ added in v0.17.8
type Identifier ¶
Identifier could refer to a variable, function, etc.
func (*Identifier) Position ¶ added in v0.13.1
func (node *Identifier) Position() string
Position returns the position.
type If ¶
type If struct { Condition Node // Either or both is allowed to be nil. True, False []Node Pos string }
If represents an if/else combination.
type Interpolate ¶ added in v0.13.2
type Interpolate struct { // Parts will have at least one element. Each element will be one of // StringLiteral or Group. However, they can appear in any order. Parts []Node Pos string }
Interpolate is a string literal that contains expressions.
func (*Interpolate) Position ¶ added in v0.13.2
func (node *Interpolate) Position() string
Position returns the position.
type KeyValue ¶
type KeyValue struct {
Key, Value Node
}
KeyValue represents a key-value pair used in maps and object initialization.
type Literal ¶
type Literal struct { Kind *types.Type Value string // Array is also used to hold the keys of the map. This is required for // iteration. Array []*Literal // If the literal is a function Map will be the parent scope. Map map[string]*Literal Pos string }
Literal represents a literal of any type.
type On ¶ added in v0.15.0
type On struct { // Type is the type name, like "MyError". Type *types.Type // Statement may be nil. Statements []Node Pos string }
On a error handler for an ErrorScope.
type Raise ¶ added in v0.15.0
Raise will raise an error to be handled. An error must be in the form of a constructor call, this is for simplicity right now.
type Switch ¶
type Switch struct { // Expr may be nil. Expr Node // Cases may be nil. Cases []*Case // Else may be nil. Else []Node Pos string }
Switch represents a switch statement.