Block XML Generator

Allows for you to use some of the features that are not available to use from the UI. Most of these features work just fine.

Here is an example block to get the type for an input.
All of the values come from my blockSpec block

There will be blocks for compiling the new XML data so you can copy and paste it into a file which you can import. This is just a tool to make it easier to make blocks that take in special inputs like existing menus, variables, and the like. This is not a substitution for manual block creation, it is mainly so you can specify any kinds of compatible parameter types.

1 Like

Current progress

Heres some full blocks that it has spat out:

<blocks app="Snap! 5.1, http://snap.berkeley.edu" version="1"><block-definition s="color %&apos;color&apos;" type="reporter" category="pen"><header></header><code></code><translations></translations><inputs><input type="%clr"></input></inputs></block-definition></blocks>


<blocks app="Snap! 5.1, http://snap.berkeley.edu" version="1"><block-definition s="play notes %&apos;notes&apos; for %&apos;beats&apos; beats" type="reporter" category="pen"><header></header><code></code><translations></translations><inputs><input type="%mult%note"></input><input type="%n">1</input></inputs></block-definition></blocks>


*the type was supposed to be changed to command and category to sound

<blocks app="Snap! 5.1, http://snap.berkeley.edu" version="1"><block-definition s="get %&apos;which&apos; from pair %&apos;pair&apos;" type="reporter" category="lists"><header></header><code></code><translations></translations><inputs><input type="%mlt" readonly="true">first<options>first&#xD;second&#xD;&#126;&#xD;random</options></input><input type="%l"></input></inputs></block-definition></blocks>


The process:

The result:

<blocks app="Snap! 5.1, http://snap.berkeley.edu" version="1"><block-definition s="%&apos;A&apos; = %&apos;B&apos;" type="predicate" category="pen"><header></header><code></code><translations></translations><inputs><input type="%clr"></input><input type="%clr"></input></inputs></block-definition></blocks>


Oh, this is very nice! Thank you! Can you do it backwards? I mean, take an existing custom block and report a list structure with the prototype expanded that way?

On my ever-expanding list of projects is the ability to convert between block innards and list structure, so that we can do programmable analysis and synthesis of blocks. What you have is a good beginning; now you need a way to turn the block's script, its body, into list structure and vice versa.

One minor suggestion is that you should imagine that the user is not an expert, so for example in your menu of types, "number" would be better than "%n."

Yea, I just did it that way because I would need a HUGE list of if statements (or a JS dictionary) in order to map each value. Currently, it just selects the appropriate type by the menu option (which is properly labelled). Also, I was getting an error when attempting to do something cool.
I was trying to make it so that you can put code inside of the block and it would get the xml for that too.
I looked into the source code and they use something like

const ide = this.parentThatIsA(IDE_Morph);

ide.serializer.serialize(block)


and

ide.saveXMLAs(serialized, name, false)


but the serializer was giving me errors when I tried to pass in block input.
You wouldn't be able to make recursive definitions but you will be able to reference blocks and parameters (as i gave the block a script variables parameter).
Hopefully someone who knows more about Snap! source code will be able to help.

Don't use the serializer. You don't want a text string, you want a list structure. Something like

as the translated version of

Don't put too much faith in the details; this is just off the top of my head and I'm probably forgetting some important information. All I really want you to take from this is the idea of a nested list structure, rather than a linear text. This is called the Abstract Syntax Tree of a program.

P.S. This nested structure is already in the script itself; all you have to do is make its pieces manipulable by the user. See https://people.eecs.berkeley.edu/~bh/v2ch5/prgdat.html for examples of what I want to be able to do.

Yes but I was trying to make it so someone could define blocks like this just to see if it was possible.

Use turbo mode for the best performance
No JS is used at the moment

Is this deliberate?

I have no idea what your EMPTY RING block does.

But I'll guess that what you're asking is whether the value of an empty ring should be an empty ring. We have arguments about this. Mostly I think it should be the identity function, so MAP with an empty first input would report a copy of its second input.

It's not mine

Oh I see, it's not a question about Snap! in general. Sorry...

Its a simple comparison. It doesnt use any Javascript blocks (which i think can use the empty ring property) so it just compares to the string version of rings. It's not used anywhere, was using it for the DO NOT USE version of the block xml generator to test if the user had placed any sort of block as input

Tried it out with some combinations like multiple colors and notes, works perfectly. Should totally be implemented.

is there a way to make custom hat blocks using something like this? also, how do I make a block that has a non multiple non readonly %kayHat menu?

I just figured it out

lol, what's this

and this?

and this
and this?
and dis?

I LOVE THIS!!!!!!!!!!!!!!!!!!!!! (this is the last time I'm editing this post)

I dont know how a custom Hat would be created or exported so I didnt implement anything

We have it! That's what the generic hat block is.