XML lexical definition documentation for Blockly

118 views
Skip to first unread message

Frank Lonigro

unread,
Dec 7, 2021, 7:40:31 PM12/7/21
to Blockly

I'm looking for a document that explains the lexical structure of the XML that generates the blocks in Blockly.  Is there a document that explains the lexical rules or tokens that the XML file may contain?  The XML I'm referring to is the XML that is generated when converting the blocks to XML and then back to blocks.

Thanks in advance,
-Frank

Beka Westberg

unread,
Dec 7, 2021, 8:20:32 PM12/7/21
to blo...@googlegroups.com
Hiya Frank! Neil has got you covered man! You can check out the schema here.

I hope that helps! If you have any further questions please reply =)
--Beka

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/f6c8f9e6-6bc1-4cdb-94fd-709c52c218f1n%40googlegroups.com.

Frank Lonigro

unread,
Dec 8, 2021, 8:51:51 AM12/8/21
to Blockly
Hi Beka,

Thanks for the reply.  So the schema for the XML is somewhat helpful, it's not quite what I was looking for.

Below is an example of a simple "if" statement in XML.

Where is it documented on what can appear as strings for block type, value name, field name, statement name, shadow type, etc, etc?

Thanks,
-Frank

<xml xmlns="https://developers.google.com/blockly/xml">
  <block type="controls_if" id="`32.Tk0*t19a2pX47S,X" x="13" y="12">
    <value name="IF0">
      <block type="logic_compare" id="d{^vq|:Y0wZ/TW/!;hV-">
        <field name="OP">GT</field>
        <value name="A">
          <block type="math_number" id="0+?fq_UKYVW;#zk`t_Y`">
            <field name="NUM">99</field>
          </block>
        </value>
        <value name="B">
          <block type="math_number" id="dCD*o4M`z_}*JdRv2I99">
            <field name="NUM">56</field>
          </block>
        </value>
      </block>
    </value>
    <statement name="DO0">
      <block type="text_print" id="QwKuPo6OhR],S!tn,Sc=">
        <value name="TEXT">
          <shadow type="text" id="%Z},:re~2K_7m30rV7D2">
            <field name="TEXT">xyz</field>
          </shadow>
        </value>
      </block>
    </statement>
  </block>
</xml>

Beka Westberg

unread,
Dec 8, 2021, 9:38:58 AM12/8/21
to blo...@googlegroups.com
Hi again Frank!

So the values that can appear in those places depend on the block definitions provided by the developer.

Block and Shadow type: These are the identifiers associated with block definitions and block-code generators that you define. For example if you define a block like:
`Blockly.Blocks['my_block'] = { ... }` then 'my_block' can now appear in the block type position.

Value and Statement name: These are the identifiers associated with individual inputs in your block definition. For example, you append an input to a block like:
```
Blockly.Blocks['my_block'] = {
  init: function() {
    this.appendValueInput('MY_INPUT_NAME');
  }
}
```
Then 'MY_INPUT_NAME' can now appear in the value name position.

Field names: These are the identifiers associated with individual fields on a block. For example if you add a field to an input like:
```
Blockly.Blocks['my_block'] = {
  init: function() {
    this.appendValueInput('MY_INPUT_NAME')
          .appendField(new SomeField(), 'MY_FIELD_NAME');
  }
}
```
Then 'MY_FIELD_NAME' can now appear in the field name position.

If you're using JSON block definitions, then the same concept applies.

I hope that helps! If you have any further questions please reply =)
--Beka

Frank Lonigro

unread,
Dec 8, 2021, 10:40:33 AM12/8/21
to Blockly
Hi Beka,

That was super helpful, thanks.

-Frank

Marius Rusu

unread,
Dec 12, 2021, 10:17:21 AM12/12/21
to blo...@googlegroups.com
Sorry,But I'm not Beka.

Virus-free. www.avast.com

Reply all
Reply to author
Forward
0 new messages