Open pdawyndt opened 6 years ago
make block delimiters optional between stack blocks that are surrounded by square brackets to support both horizontal and vertical blocks layouts (#90)
[block][block]...[block] // first stack
[block][block]...[block] // second stack
investigate if we could even drop the extra newline between two horizontal stacks
substacking uses nesting in the horizontal layout
[block]...[block][block [block][block]...[block]][block]...[block] // block with substack
[block] // first stack
[block]
...
[block]
[block] // second stack
[block]
...
[block]
or a shorthand notation that drops the square brackets around stack blocks in vertical layout
block // first stack
block
...
block
block // second stack
block
...
block
substacking uses indentation in the vertical layout
block // top-level stack
....
block
block // substack
...
block
block // continuation of top-level stack
....
block
investigate if and when, square brackets and block delimiters can be mixed in the same environment (where they can be dropped) or if it is needed to let the user specify beforehand whether she want to use horizontal (mandatory square brackets around stack blocks) or vertical (optional square brackets around stack blocks) layout
allow grammar to make distinction between built-in/extension blocks and user-defined blocks by dynamically generating the grammar from the block specification in Scratch Extensions format; this would allow syntax highlighting (#1) and code completion (#38) of Scratch-LN; the grammar could also enforce shapes and types on built-in/extension blocks and their arguments that prohibits certain connections and nestings
the definition of a user-defined stack block could be treated the same way as an extension, which could be supported by extending the list of built-in/extension blocks used by the visitor or by injecting new grammar rules while parsing a user-defined stack block; as a result, the parser could make distinction between user-defined blocks that have and haven't been defined in the Scratch-LN script and issue a warning if a closed world model is followed
the notation
move (10) steps
is actually closer to the visual representation than
move {10} steps
so we might consider to make the following changes:
[]
) represent stack blocks or menu parameters; the former are always optional; ; there are different types of stack blocks: connector blocks (two connectors), hat blocks (no top connector), cap blocks (no bottom connector) and menu blocks (no connectors but menu selection), but these cannot be discriminated when the block definitions are available (in the visitor or when dynamically injected in the grammar)()
) represent reporter blocks (including variables) or reporter parameters (the latter are optional when an actual argument is passed)<>
) represent boolean blocks (including variables) or boolean parameters (the latter are optional when an actual argument is passed)""
) represent shadow blocks (that can be considered as string literals and can not stand on their own); shadow blocks are a special kind of reporter blocks (they also yield a value)the full version of the move %1 steps
and when %1 key pressed
blocks would then become
[move () steps] # (1) reporter parameter without an argument (no shadow)
[move ("") steps] # (2) reporter parameter filled with an empty shadow block (2)
[move ("10") steps] # (3) reporter parameter filled with a shadow block filled with a string
[move ((count)) steps] # (4) reporter parameter filled with a variable
[when [] key pressed] # (5) menu parameter without an argument
[when [[space]] key pressed] # (6) menu parameter filled with a stack block (representing a menu)
as syntactic sugar we could then have the following rules
[]
) or double quotes (""
); they actually yield a value this would allow the following shorthands for the above examples
move () steps # (1) applying rules (i) (rule 2 can not be applied because of the empty shadow)
move "" steps # (2) applying rules (i) and (ii)
move "10" steps # (3) applying rules (i) and (ii)
move (count) steps # (4) applying rules (i) and (ii)
when [] key pressed # (5) applying rule (i) only once (second pair of brackets can not be dropped because no argument is passed)
when [space] key pressed # (6) applying rule (i) twice
when "space" key pressed # (6) apply rule (iv) to write [space] as "space" and then apply rules (i) and (v)
this would remove the curly braces ({}
) from the syntax, as they are replaced by stack ({}
), reporter (()
) and boolean (<>
) parameters; grammar could check if argument matches the parameter if the characters are used to denote the parameters; the characters used to denote the parameters could be dropped if an actual argument is passed and the visitor could then infer the parameter type from the argument type; the visitor could also check if both the parameter type and the argument value match the block specification, otherwise a warning is issued and an "error" extension block is injected in Scratch as a visual placeholder that indicates where the error has happened
this would also have a natural extension to using substacks using nesting
[if <<mouse down ?>> then [[move ("10") steps][turn cw ("15") degrees]] else [[move ("20") steps][turn cw ("25") degrees]]]
is then the longer version of (horizontal layout)
if <mouse down> [move "10" steps][turn cw "15" degrees] else [move "20" steps][turn cw "25" degrees]
or (vertical layout)
if <mouse down>
move "10" steps
turn cw "15" degrees
else
move "20" steps
turn cw "25" degrees
instead of trying to using a custom block in combination with a warning that an invalid argument was used, we could better inject a new block as an "error" extension to Scratch 3.0, using the extension mechanism to report errors, and then add the warning issued as a comment to this block
support of the Scratchblocks modifiers for ::color
or a specific category could also be supported by dynamically adding block specifications / grammar rules; same for the Scratchblocks support for custom C-blocks
we might try to represent block shapes such as in (here with horizontal layout in mind)
block shape | notation |
---|---|
connector | >block> |
hat | \|block> |
cap | >block\| |
connector | \|block\| |
a stack could then be written as
|hat> >connector> >connector> >connector> >cap |
or in short
| hat > connector > connector > connector > cap |
where both the hat and cap blocks are optional
> connector > connector > connector >
RESEARCH QUESTION: if the grammar only focuses on the visual aspects of the language (connecting blocks, nesting blocks and substacking), we might even move into the direction of having a grammar that supports all feature that are in Google Blockly, instead of having something Scratch-specific
terminology:
block
| block
| block
block
block
| block
| block
block
--------------------
hat
---___--------------
connector
---___--------------
connector
---___--------------
connector
---___--------------
cap
--------------------
as a shorthand for
--------------------
hat
---___--------------
---___--------------
connector
---___--------------
---___--------------
connector
---___--------------
---___--------------
connector
---___--------------
---___--------------
cap
--------------------
this could also be used to represent C-blocks
|---___-----------------
| if <mouse down> then
| |---___---------------
| |---___---------------
| | move "10" steps
| |---___---------------
| |---___---------------
| else
| |---___---------------
| |---___---------------
| | move "20" steps
| |---___---------------
| |---___---------------
|---___-----------------
Design principles
A new version of the Scratch-LN grammar should follow these design principles:
end
keyword that is not visible on the Scratch blocks anyway and would allow the grammar to recognize substacks