Upload code to Blockly

1,931 views
Skip to first unread message

ahmed aroui

unread,
Apr 24, 2015, 10:09:09 AM4/24/15
to blo...@googlegroups.com
Hello,
I'm working on a project that uses the Google Blockly API.
I have understood something that to import code we have to pass by uploading xml to the content_xml.
So any idea how to generate the Blockly/xml corresponding to each line of the arbutrary code (python for example)?

The arbitrary code corresponds to the blockly blocks and my own (custom) blocks. but not wel formed like the generated code.

thanks.

Kevin Hahn

unread,
Apr 24, 2015, 2:06:23 PM4/24/15
to blo...@googlegroups.com
Blockly does not support taking code and translating it into Blockly xml. Take a look at this FAQ answer

Carlos Galarza

unread,
Apr 25, 2015, 12:13:50 PM4/25/15
to blo...@googlegroups.com
Hi ahmed, to achieve this you should:
 - make a parser or find one: for python you can use filbert, or for javascript the acorn parser, both are AST parsers with mozilla parser API compatibility.
 - make a renderer wich displays AST directly in blocks or a converter to XML. An example of a renderer are this, but could be easily rewritten like a converter from AST to XML.

I'm very interested in this feature and i'm working in it like an extension for Blockly. If you are interested i'll be happy to share my advances in this topic.

ahmed aroui

unread,
Apr 26, 2015, 3:25:53 PM4/26/15
to blo...@googlegroups.com
Thank's for Help Carlos & Kevin.
I will try to do my best

Best Regards

--
You received this message because you are subscribed to a topic in the Google Groups "Blockly" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/blockly/A6MU3pzkjuw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
ELAROUI Ahmed
Computer Sciences Engineering Student
GSM : (+216) 50 16 63 78

Austin Bart

unread,
Apr 27, 2015, 10:07:06 AM4/27/15
to blo...@googlegroups.com
This project isn't being publicly released yet, but this is related to my dissertation work:


We're using a custom fork of blockly that makes it more pythonic. The advantage is that we can do roughly 1-1 mutual language translation with Python. It's not 100% (while loops aren't available, for instance), but it should definitely let you get a feel for it.

We don't have a name for it yet, so we're codenaming it Blockpy. 

~Cory

Dhanashree Revagade

unread,
May 14, 2020, 12:59:27 AM5/14/20
to Blockly
Hey Carlos, thanks for the steps for mentioning the code to Blocks conversion.
Could you please elaborate a bit more on the second point of Converting AST to XML. 
Using a python parser I got the JSON AST representation of python code, but I'm not clear how to proceed further to convert my AST to Blockly XML.

Thank You. 

Austin Bart

unread,
May 14, 2020, 1:08:23 AM5/14/20
to Blockly
You may find this project to be of interest: https://github.com/blockpy-edu/BlockMirror

We split off our Block<->Python editor from the rest of BlockPy last summer. In theory, you should be able to just use BlockMirror as a stand alone entity now.
Reply all
Reply to author
Forward
0 new messages