Convert Code to block Or xml

783 views
Skip to first unread message

hasti mousavi

unread,
Jan 19, 2021, 4:42:00 PM1/19/21
to Blockly
Hi every one
  how can i  convert a sample  java script code to  xml or Block that show in workspace?
it is possible?
 thank u .

Beka Westberg

unread,
Jan 19, 2021, 5:52:21 PM1/19/21
to blo...@googlegroups.com
Hello,

There is no built-in way to convert javascript code to blocks. The reasons for this are:
1) Blockly doesn't support all javascript features. Eg anonymous functions, destructuring, etc.
2) Custom blocks may have arbitrary shapes and generate arbitrary code, which makes it hard to go from code -> blocks automatically :/

However! If you have a custom constrained version of javascript that you want to support (eg no anonymous functions, etc) it /should/ be possible to build something that converts from a string of javascript code to blocks =) But it would still be pretty tricky! You'll have to tokenize the string somehow, and create a way to map from those tokens to your blocks, and create a way to make sure they connect correctly. If you can get that working you should be golden.

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/7a6075fe-b9c9-48bc-aefc-c376cfdd4536n%40googlegroups.com.

Mark Friedman

unread,
Jan 20, 2021, 7:10:13 PM1/20/21
to blo...@googlegroups.com
Hasti,

  This is probably not what you really want but I'll just point out there there have been applications using technologies other than Blockly that do the sort of thing that you're talking about.  One of them is the Droplet Editor (website, source) developed largely by Anthony and David Bau a few years ago.  It supports an older version of JavaScript, however.

-Mark


On Tue, Jan 19, 2021 at 1:42 PM hasti mousavi <hash...@gmail.com> wrote:
--
Reply all
Reply to author
Forward
0 new messages