blockpy-edu / blockpy

Blockly that's more Python than JavaScript, powered with Skulpt
Apache License 2.0
391 stars 130 forks source link

Code Analysis #32

Closed isnullxbh closed 3 years ago

isnullxbh commented 6 years ago

Is it possible to parse a source code, like:

var.function(...);
var.property = ...;
var.function(...);

into one block? As I understand it, the existing mechanism allows to parse source code for blocks that are consist of one row, like:

plt.xlabel("title")
acbart commented 6 years ago

Good question! You're right that the existing mechanism assumes that a line of code will turn into zero or one lines of blocks. I haven't touched this code in a while, but I don't think it'd be impossible to allow the convertBody function to handle chunks of code in special cases, though specifying it would be a bit tricky to figure out the first time.

That said, I'm nervous about the idea. From a pedagogical perspective, we still don't have much understanding of how novices understand the block/text conversion. There are times I regret implementing the idea of 1=>0 block conversion. In particular, import blocks "disappear" when they go from text to blocks. What will happen when we start swallowing more lines of code?

I'd be interested in specific ideas that you had for situations where you'd need to convert multiple linse of code into a single block!

acbart commented 3 years ago

BlockMirror could probably handle stuff like this now: https://github.com/blockpy-edu/BlockMirror/

I don't know for certain, though. It's not really designed around collapsing multiple statements, though it does handle multiple lines?