Return the type of block the script begins with.
779515
def script_start_type(script):
        """"""
        if script[0].type.text == 'when @greenFlag clicked':
            return HairballPlugin.HAT_GREEN_FLAG
        elif script[0].type.text == 'when I receive %s':
            return HairballPlugin.HAT_WHEN_I_RECEIVE
        elif script[0].type.text == 'when this sprite clicked':
            return HairballPlugin.HAT_MOUSE
        elif script[0].type.text == 'when %s key pressed':
            return HairballPlugin.HAT_KEY
        else:
            return HairballPlugin.NO_HAT
323628
def script(self):
        """"""
        # The script object is cached, since constructing it may involve
        # a number of string-manipulation operations.
        if getattr(self, '_script', None) is None:
            self._script = self._script__getter()
        return self._script
1306429
def get_aside_of_type(self, block, aside_type):
        
        # TODO: This function will need to be extended if we want to allow:
        #   a) XBlockAsides to statically indicated which types of blocks they can comment on
        #   b) XBlockRuntimes to limit the selection of asides to a subset of the installed asides
        #   c) Optimize by only loading asides that actually decorate a particular view

        if self.id_generator is None:
            raise Exception("Runtimes must be supplied with an IdGenerator to load XBlockAsides.")

        usage_id = block.scope_ids.usage_id

        aside_cls = self.load_aside_type(aside_type)
        definition_id = self.id_reader.get_definition_id(usage_id)
        aside_def_id, aside_usage_id = self.id_generator.create_aside(definition_id, usage_id, aside_type)
        scope_ids = ScopeIds(self.user_id, aside_type, aside_def_id, aside_usage_id)
        return aside_cls(runtime=self, scope_ids=scope_ids)
830777
function checkKeyframesBlocks(i) {
  if (i >= tokensLength) return 0;

  const blockEnd = tokens[i].block_end;
  const start = i;
  let l;

  if (!blockEnd) return 0;

  if (l = checkSC(i)) i += l;

  if (l = checkKeyframesBlock(i)) i += l;

  while (i < blockEnd) {
    if (l = checkSC(i)) i += l;
    else if (l = checkKeyframesBlock(i)) i += l;
    else if (l = checkAtrule(i)) i += l;
    else break;
  }

  if (i !== blockEnd + 1) return 0;

  return blockEnd + 1 - start;
}
1266929
def findPrevStmt(self, block):
        
        stmtEnd = self._prevNonCommentBlock(block)
        stmtStart = self.findStmtStart(stmtEnd)
        return Statement(self._qpart, stmtStart, stmtEnd)
45805
def new_code_block(self, **kwargs):
        """"""
        proto = {'content': '',
                 'type': self.code,
                 'IO': '',
                 'attributes': ''}
        proto.update(**kwargs)
        return proto
1190892
function() {
    var ALL_SCRIPTS = 'all';
    var THIS_SCRIPT = 'this script';
    var OTHER_SCRIPTS = 'other scripts in sprite';
    var stopDropdown = new Blockly.FieldDropdown(function() {
      if (this.sourceBlock_ &&
          this.sourceBlock_.nextConnection &&
          this.sourceBlock_.nextConnection.isConnected()) {
        return [
          [Blockly.Msg.CONTROL_STOP_OTHER, OTHER_SCRIPTS]
        ];
      }
      return [[Blockly.Msg.CONTROL_STOP_ALL, ALL_SCRIPTS],
        [Blockly.Msg.CONTROL_STOP_THIS, THIS_SCRIPT],
        [Blockly.Msg.CONTROL_STOP_OTHER, OTHER_SCRIPTS]
      ];
    }, function(option) {
      // Create an event group to keep field value and mutator in sync
      // Return null at the end because setValue is called here already.
      Blockly.Events.setGroup(true);
      var oldMutation = Blockly.Xml.domToText(this.sourceBlock_.mutationToDom());
      this.sourceBlock_.setNextStatement(option == OTHER_SCRIPTS);
      var newMutation = Blockly.Xml.domToText(this.sourceBlock_.mutationToDom());
      Blockly.Events.fire(new Blockly.Events.BlockChange(this.sourceBlock_,
          'mutation', null, oldMutation, newMutation));
      this.setValue(option);
      Blockly.Events.setGroup(false);
      return null;
    });
    this.appendDummyInput()
        .appendField(Blockly.Msg.CONTROL_STOP)
        .appendField(stopDropdown, 'STOP_OPTION');
    this.setCategory(Blockly.Categories.control);
    this.setColour(Blockly.Colours.control.primary,
        Blockly.Colours.control.secondary,
        Blockly.Colours.control.tertiary
    );
    this.setPreviousStatement(true);
  }
637251
def p_block(self, p):
        """"""
        p[0] = self.asttypes.Block(p[2])
        p[0].setpos(p)
696619
def construct_xblock(self, block_type, scope_ids, field_data=None, *args, **kwargs):
        
        """
        return self.construct_xblock_from_class(
            cls=self.load_block_type(block_type),
            scope_ids=scope_ids,
            field_data=field_data,
            *args, **kwargs
        )
1166761
def get_block_type(values, dtype=None):
    
    dtype = dtype or values.dtype
    vtype = dtype.type

    if is_sparse(dtype):
        # Need this first(ish) so that Sparse[datetime] is sparse
        cls = ExtensionBlock
    elif is_categorical(values):
        cls = CategoricalBlock
    elif issubclass(vtype, np.datetime64):
        assert not is_datetime64tz_dtype(values)
        cls = DatetimeBlock
    elif is_datetime64tz_dtype(values):
        cls = DatetimeTZBlock
    elif is_interval_dtype(dtype) or is_period_dtype(dtype):
        cls = ObjectValuesExtensionBlock
    elif is_extension_array_dtype(values):
        cls = ExtensionBlock
    elif issubclass(vtype, np.floating):
        cls = FloatBlock
    elif issubclass(vtype, np.timedelta64):
        assert issubclass(vtype, np.integer)
        cls = TimeDeltaBlock
    elif issubclass(vtype, np.complexfloating):
        cls = ComplexBlock
    elif issubclass(vtype, np.integer):
        cls = IntBlock
    elif dtype == np.bool_:
        cls = BoolBlock
    else:
        cls = ObjectBlock
    return cls
719942
function() {
    var tok = this.expect('block');

    var node = 'indent' == this.peek().type
      ? this.block()
      : this.emptyBlock(tok.line);
    node.type = 'NamedBlock';
    node.name = tok.val.trim();
    node.mode = tok.mode;
    node.line = tok.line;

    return node;
  }
1000548
def start_block(self,stylestack=None):
        
        if self.dirty:
            self.escpos._raw('\n')
            self.dirty = False
        self.stack.append('block')
        if stylestack:
            self.style(stylestack)
588251
def load_block_type(self, block_type):
        
        return XBlock.load_class(block_type, self.default_class, self.select)
694617
function getCurrentItem(opts: Options, value: Value, block?: Block): ?Block {
    const { document } = value;

    if (!block) {
        if (!value.selection.startKey) return null;
        block = value.startBlock;
    }

    const parent = document.getParent(block.key);
    return parent && parent.type === opts.typeItem ? parent : null;
}
1144864
def name(self):
        

        if self._name is not None:
            return self._name

        if not self.blocks:
            return None

        if not self.blocks[0].instructions:
            return None

        if not self.blocks[0].instructions[0].labels:
            return None

        lbl = self.blocks[0].instructions[0].labels[0]

        if isinstance(lbl, FunctionLabel):
            return lbl.function_name

        return None
784781
def process_code_block(self, block):
        """"""
        if block['type'] != self.code:
            return block

        attr = PandocAttributes(block['attributes'], 'markdown')

        if self.match == 'all':
            pass

        elif self.match == 'fenced' and block.get('indent'):
            return self.new_text_block(content=('\n' +
                                                block['icontent'] +
                                                '\n'))

        elif self.match == 'strict' and 'input' not in attr.classes:
            return self.new_text_block(content=block['raw'])

        elif self.match not in list(attr.classes) + ['fenced', 'strict']:
            return self.new_text_block(content=block['raw'])

        # set input / output status of cell
        if 'output' in attr.classes and 'json' in attr.classes:
            block['IO'] = 'output'
        elif 'input' in attr.classes:
            block['IO'] = 'input'
            attr.classes.remove('input')
        else:
            block['IO'] = 'input'

        if self.caption_comments:
            # override attributes id and caption with those set in
            # comments, if they exist
            id, caption = get_caption_comments(block['content'])
            if id:
                attr.id = id
            if caption:
                attr['caption'] = caption

        try:
            # determine the language as the first class that
            # is in the block attributes and also in the list
            # of languages
            language = set(attr.classes).intersection(languages).pop()
            attr.classes.remove(language)
        except KeyError:
            language = None

        block['language'] = language
        block['attributes'] = attr

        # ensure one identifier for python code
        if language in ('python', 'py', '', None):
            block['language'] = self.python
        # add alternate language execution magic
        elif language != self.python and self.magic:
            block['content'] = CodeMagician.magic(language) + block['content']
            block['language'] = language

        return self.new_code_block(**block)
369492
def goto_block(self, block):
        
        old_block = self.basic_block
        term = block.terminator
        if term is not None:
            self.position_before(term)
        else:
            self.position_at_end(block)
        try:
            yield
        finally:
            self.position_at_end(old_block)