Class: Names

Constructor

Names

new Names(reservedWords, opt_variablePrefix)

Parameter

reservedWords

A comma-separated string of words that are illegal for use as names in a language (e.g. 'new,if,this,...').

opt_variablePrefix

Optional

Some languages need a '$' or a namespace before all variable names (but not procedure names).

Enumeration

NameType

constant   static

string

Enum for the type of a name. Different name types may have different rules about collisions. When JavaScript (or most other languages) is generated, variable 'foo' and procedure 'foo' would collide. However, Blockly has no such problems since variable get 'foo' and procedure call 'foo' are unambiguous. Therefore, Blockly keeps a separate name type to disambiguate. getName('foo', 'VARIABLE') -> 'foo' getName('foo', 'PROCEDURE') -> 'foo2'

Value

DEVELOPER_VARIABLE

VARIABLE

PROCEDURE

Properties

DEVELOPER_VARIABLE_TYPE

static

Constant to separate developer variable names from user-defined variable names when running generators. A developer variable will be declared as a global in the generated code, but will never be shown to the user in the workspace or stored in the variable map.

NameType

constant   static

string

Enum for the type of a name. Different name types may have different rules about collisions. When JavaScript (or most other languages) is generated, variable 'foo' and procedure 'foo' would collide. However, Blockly has no such problems since variable get 'foo' and procedure call 'foo' are unambiguous. Therefore, Blockly keeps a separate name type to disambiguate. getName('foo', 'VARIABLE') -> 'foo' getName('foo', 'PROCEDURE') -> 'foo2'

Value

DEVELOPER_VARIABLE

VARIABLE

PROCEDURE

Methods

equals

static

equals(name1, name2) returns boolean

Do the given two entity names refer to the same entity? Blockly names are case-insensitive.

Parameter

name1

string

First name.

name2

string

Second name.

Returns

boolean True if names are the same.

getDistinctName

getDistinctName(name, type) returns string

Convert a Blockly entity name to a legal exportable entity name. Ensure that this is a new name not overlapping any previously defined name. Also check against list of reserved words for the current language and ensure name doesn't collide.

Parameter

name

string

The Blockly entity name (no constraints).

type

(NameType or string)

The type of entity in Blockly ('VARIABLE', 'PROCEDURE', 'DEVELOPER_VARIABLE', etc...).

Returns

string An entity name that is legal in the exported language.

getName

getName(nameOrId, type) returns string

Convert a Blockly entity name to a legal exportable entity name.

Parameter

nameOrId

string

The Blockly entity name (no constraints) or variable ID.

type

(NameType or string)

The type of the name in Blockly ('VARIABLE', 'PROCEDURE', 'DEVELOPER_VARIABLE', etc...).

Returns

string An entity name that is legal in the exported language.

getUserNames

getUserNames(type) returns Array of string

Return a list of all known user-created names of a specified name type.

Parameter

type

(NameType or string)

The type of entity in Blockly ('VARIABLE', 'PROCEDURE', 'DEVELOPER_VARIABLE', etc...).

Returns

non-null Array of string A list of Blockly entity names (no constraints).

populateProcedures

populateProcedures(workspace)

Generate names for procedures.

Parameter

workspace

Blockly.Workspace

Workspace to generate procedures from.

Value must not be null.

populateVariables

populateVariables(workspace)

Generate names for user variables, but only ones that are being used.

Parameter

workspace

Blockly.Workspace

Workspace to generate variables from.

Value must not be null.

reset

reset()

Empty the database and start from scratch. The reserved words are kept.

setVariableMap

setVariableMap(map)

Set the variable map that maps from variable name to variable object.

Parameter

map

Blockly.VariableMap

The map to track.

Value must not be null.