Class: Names

Constructor

Names

new Names(reservedWords, opt_variablePrefix)

Class for a database of entity names (variables, procedures, etc).

Parameter

reservedWords

string

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

opt_variablePrefix

Optional

string

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

Property

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.

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, realm) 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).

realm

string

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

Returns

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

getName

getName(nameOrId, realm) 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.

realm

string

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

Returns

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

getUserNames

getUserNames(realm) returns Array of string

Return a list of all known user-created names in a specified realm.

Parameter

realm

string

The realm 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.