sesaparcours
    Preparing search index...

    Fake class which should be extended to avoid inheriting static properties

    Hierarchy (View Summary)

    Index

    Constructors

    • Class for a code generator that translates the blocks into a language.

      Parameters

      • name: string

        Language name of this generator.

      Returns Generator

    Properties

    COMMENT_WRAP: number

    Maximum length for a comment before wrapping. Does not account for indenting level.

    INDENT: string

    The method of indenting. Defaults to two spaces, but language generators may override this to increase indent or change to tabs.

    INFINITE_LOOP_TRAP: string

    Arbitrary code to inject into locations that risk causing infinite loops. Any instances of '%1' will be replaced by the block ID that failed. E.g. ' checkTimeout(%1);\n'

    isInitialized: boolean

    Whether the init method has been called. Generators that set this flag to false after creation and true in init will cause blockToCode to emit a warning if the generator has not been initialized. If this flag is untouched, it will have no effect.

    ORDER_OVERRIDES: number[][]

    List of outer-inner pairings that do NOT require parentheses.

    STATEMENT_PREFIX: string

    Arbitrary code to inject before every statement. Any instances of '%1' will be replaced by the block ID of the statement. E.g. 'highlight(%1);\n'

    STATEMENT_SUFFIX: string

    Arbitrary code to inject after every statement. Any instances of '%1' will be replaced by the block ID of the statement. E.g. 'highlight(%1);\n'

    Methods

    • Add an infinite loop trap to the contents of a loop. Add statement suffix at the start of the loop block (right after the loop statement executes), and a statement prefix to the end of the loop block (right before the loop statement executes).

      Parameters

      • branch: string

        Code for loop contents.

      • block: Blockly.Block

        Enclosing block.

      Returns string

      Loop contents, with infinite loop trap added.

    • Add one or more words to the list of reserved words for this language.

      Parameters

      • words: string

        Comma-separated list of words to add to the list. No spaces. Duplicates are ok.

      Returns void

    • Recursively spider a tree of blocks, returning all their comments.

      Parameters

      • block: Blockly.Block

        The block from which to start spidering.

      Returns string

      Concatenated list of comments.

    • Generate code for the specified block (and attached blocks). The generator must be initialized before calling this function.

      Parameters

      • block: Blockly.Block

        The block to generate code for.

      • Optionalopt_thisOnly: boolean

        True to generate code for only this statement.

      Returns string | any[]

      For statement blocks, the generated code. For value blocks, an array containing the generated code and an operator order value. Returns '' if block is null.

    • Hook for code to run at end of code generation. Subclasses may override this, e.g. to prepend the generated code with import statements or variable definitions.

      Parameters

      • code: string

        Generated code.

      Returns string

      Completed code.

    • Hook for code to run before code generation starts. Subclasses may override this, e.g. to initialise the database of variable names.

      Parameters

      Returns void

    • Inject a block ID into a message to replace '%1'. Used for STATEMENT_PREFIX, STATEMENT_SUFFIX, and INFINITE_LOOP_TRAP.

      Parameters

      • msg: string

        Code snippet with '%1'.

      • block: Blockly.Block

        Block which has an ID.

      Returns string

      Code snippet with ID.

    • Prepend a common prefix onto each line of code. Intended for indenting code or adding comment markers.

      Parameters

      • text: string

        The lines of code.

      • prefix: string

        The common prefix.

      Returns string

      The prefixed lines of code.

    • Naked values are top-level blocks with outputs that aren't plugged into anything. Subclasses may override this, e.g. if their language does not allow naked values.

      Parameters

      • line: string

        Line of generated code.

      Returns string

      Legal line of code.

    • Generate a code string representing the blocks attached to the named statement input. Indent the code. This is mainly used in generators. When trying to generate code to evaluate look at using workspaceToCode or blockToCode.

      Parameters

      • block: Blockly.Block

        The block containing the input.

      • name: string

        The name of the input.

      Returns string

      Generated code or '' if no blocks are connected.

    • Generate code representing the specified value input.

      Parameters

      • block: Blockly.Block

        The block containing the input.

      • name: string

        The name of the input.

      • outerOrder: number

        The maximum binding strength (minimum order value) of any operators adjacent to "block".

      Returns string

      Generated code or '' if no blocks are connected or the specified input does not exist.

    • Generate code for all blocks in the workspace to the specified language.

      Parameters

      Returns string

      Generated code.