Constructor

ASTNode

new ASTNode(type, location, opt_params)

Class for an AST node. It is recommended that you use one of the createNode methods instead of creating a node directly.

Parameter

type

string

The type of the location. Must be in Bockly.ASTNode.types.

location

(Blockly.Block, Blockly.Connection, Blockly.Field, or Blockly.Workspace)

The position in the AST.

opt_params

Optional

Object

Optional dictionary of options.

Value must not be null.

Enumeration

types

static

string

Object holding different types for an AST node.

Value

FIELD

BLOCK

INPUT

OUTPUT

NEXT

PREVIOUS

STACK

WORKSPACE

Properties

types

static

string

Object holding different types for an AST node.

Value

FIELD

BLOCK

INPUT

OUTPUT

NEXT

PREVIOUS

STACK

WORKSPACE

location_

non-null Blockly.Block

location_

non-null Blockly.Block

location_

non-null Blockly.Block

Methods

createBlockNode

static

createBlockNode(block) returns Blockly.ASTNode

Creates an AST node pointing to a block.

Parameter

block

Blockly.Block

The block used to create an AST node.

Value must not be null.

Returns

non-null Blockly.ASTNode An AST node pointing to a block.

createConnectionNode

static

createConnectionNode(connection) returns Blockly.ASTNode

Creates an AST node pointing to a connection. If the connection has a parent input then create an AST node of type input that will hold the connection.

Parameter

connection

Blockly.Connection

This is the connection the node will point to.

Returns

Blockly.ASTNode An AST node pointing to a connection.

createFieldNode

static

createFieldNode(field) returns Blockly.ASTNode

Create an AST node pointing to a field.

Parameter

field

Blockly.Field

The location of the AST node.

Value must not be null.

Returns

non-null Blockly.ASTNode An AST node pointing to a field.

createInputNode

static

createInputNode(input) returns Blockly.ASTNode

Creates an AST node pointing to an input. Stores the input connection as the location.

Parameter

input

Blockly.Input

The input used to create an AST node.

Returns

non-null Blockly.ASTNode An AST node pointing to a input.

createStackNode

static

createStackNode(topBlock) returns Blockly.ASTNode

Create an AST node of type stack. A stack, represented by its top block, is the set of all blocks connected to a top block, including the top block.

Parameter

topBlock

Blockly.Block

A top block has no parent and can be found in the list returned by workspace.getTopBlocks().

Value must not be null.

Returns

non-null Blockly.ASTNode An AST node of type stack that points to the top block on the stack.

createWorkspaceNode

static

createWorkspaceNode(workspace, wsCoordinate) returns Blockly.ASTNode

Creates an AST node pointing to a workspace.

Parameter

workspace

Blockly.Workspace

The workspace that we are on.

Value must not be null.

wsCoordinate

Blockly.utils.Coordinate

The position on the workspace for this node.

Returns

non-null Blockly.ASTNode An AST node pointing to a workspace and a position on the workspace.

getLocation

getLocation() returns (Blockly.Field, Blockly.Connection, Blockly.Block, or Blockly.Workspace)

Gets the value pointed to by this node. It is the callers responsibility to check the node type to figure out what type of object they get back from this.

Returns

non-null (Blockly.Field, Blockly.Connection, Blockly.Block, or Blockly.Workspace) The current field, connection, workspace, or block the cursor is on.

getType

getType() returns string

The type of the current location. One of Blockly.ASTNode.types

Returns

string The type of the location.

getWsCoordinate

getWsCoordinate() returns Blockly.utils.Coordinate

The coordinate on the workspace.

Returns

Blockly.utils.Coordinate The workspace coordinate or null if the location is not a workspace.

in

in() returns Blockly.ASTNode

Find the element one level below and all the way to the left of the current location.

Returns

Blockly.ASTNode An AST node that wraps the next field, connection, workspace, or block. Or null if there is nothing below this node.

isConnection

package

isConnection() returns boolean

Whether the node points to a connection.

Returns

boolean [description]

next

next() returns Blockly.ASTNode

Find the element to the right of the current element in the AST.

Returns

Blockly.ASTNode An AST node that wraps the next field, connection, block, or workspace. Or null if there is no node to the right.

out

out() returns Blockly.ASTNode

Find the next element that is one position above and all the way to the left of the current location.

Returns

Blockly.ASTNode An AST node that wraps the next field, connection, workspace or block. Or null if we are at the workspace level.

prev

prev() returns Blockly.ASTNode

Find the element to the left of the current element in the AST.

Returns

Blockly.ASTNode An AST node that wraps the previous field, connection, workspace or block. Or null if no node exists to the left. null.