Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
- aspizu
-
Scratcher
60 posts
goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
goboscript v3.1.0
This release features a refactored pre-processor that fixes several issues, paves the way for new features, and gracefully handles errors.
CONCAT Macro
Joins two tokens into a single token.
CONCAT can be nested, for example:
Limitation: Currently, only name tokens can be joined.
Recursive Macros
Recursive macros (macros that reference their own name in their definition) are now handled gracefully. Once a macro is expanded, it is marked as suppressed to avoid re-evaluation in the same substitution pass, preventing hangs and infinite loops.
Parsing Ambiguity: Variable-like vs Function-like Macros
When defining a variable-like macro whose definition starts with a ( token, if the token following is a name, it may be misinterpreted as a function-like macro.
Solution: To ensure proper parsing, additional parentheses are required. For instance, defining %define unit_range (zero,one) now requires extra parentheses:
Recommended Conventions for Macros
Function-like Macros: Use these to clearly indicate that the macro expands into an expression (e.g. IS_HOVERED() instead of IS_HOVERED), which avoids confusion with global variables.
Naming: Uppercase naming is recommended for macros.
Constants: For constants, consider using variable declarations (e.g. var EXAMPLE = 2*(3+4); ) if constant-folding optimizations are not required.
This release features a refactored pre-processor that fixes several issues, paves the way for new features, and gracefully handles errors.
CONCAT Macro
Joins two tokens into a single token.
CONCAT(LHS, RHS)
# becomes
LHSRHS
CONCAT can be nested, for example:
CONCAT(PREFIX, CONCAT(NAME, SUFFIX))
# becomes
PREFIXNAMESUFFIX
Limitation: Currently, only name tokens can be joined.
Recursive Macros
Recursive macros (macros that reference their own name in their definition) are now handled gracefully. Once a macro is expanded, it is marked as suppressed to avoid re-evaluation in the same substitution pass, preventing hangs and infinite loops.
Parsing Ambiguity: Variable-like vs Function-like Macros
When defining a variable-like macro whose definition starts with a ( token, if the token following is a name, it may be misinterpreted as a function-like macro.
Solution: To ensure proper parsing, additional parentheses are required. For instance, defining %define unit_range (zero,one) now requires extra parentheses:
%define unit_range ((zero,one))
Recommended Conventions for Macros
Function-like Macros: Use these to clearly indicate that the macro expands into an expression (e.g. IS_HOVERED() instead of IS_HOVERED), which avoids confusion with global variables.
Naming: Uppercase naming is recommended for macros.
Constants: For constants, consider using variable declarations (e.g. var EXAMPLE = 2*(3+4); ) if constant-folding optimizations are not required.
- codingfire23
-
Scratcher
41 posts
goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
I find it quite funny how it still looks like scratch even in a text format. Because of that however, i don't really see a point. I guess its more flexible and less restrictive but i don't know since i don't do scratch anymore.
- awesome-llama
-
Scratcher
1000+ posts
goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
I find it quite funny how it still looks like scratch even in a text format. Because of that however, i don't really see a point. I guess its more flexible and less restrictive but i don't know since i don't do scratch anymore.You missed all the mentions of macros, functions with returns, structs, enums, and more.
There's no need to manually create variables in the project editor, you type them and they are created. There are local variables to stay within the scope of the procedure they are a part of.
You can copy-paste code. Find and replace. No more pain of backpacking scripts and finding out they made a mess of variables that require renaming or replacement. You can also include code from other files or libraries.
You can use version control such as Git.
It's very useful. I'm making my next project with it.
Last edited by awesome-llama (March 18, 2025 06:00:48)
- codingfire23
-
Scratcher
41 posts
goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
Makes sense why you would use it now. I literally can't read these days XDI find it quite funny how it still looks like scratch even in a text format. Because of that however, i don't really see a point. I guess its more flexible and less restrictive but i don't know since i don't do scratch anymore.You missed all the mentions of macros, functions with returns, structs, enums, and more.
There's no need to manually create variables in the project editor, you type them and they are created. There are local variables to stay within the scope of the procedure they are a part of.
You can copy-paste code. Find and replace. No more pain of backpacking scripts and finding out they made a mess of variables that require renaming or replacement. You can also include code from other files or libraries.
You can use version control such as Git.
It's very useful. I'm making my next project with it.
- gilbert_given_189
-
Scratcher
1000+ posts
goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
This is a great project! If only there's more blocks implemented…
([variable v] of [Sprite1 v])Here is one such block. (its opcode is sensing_of with a child sensing_of_object_menu)
Last edited by gilbert_given_189 (March 19, 2025 02:38:59)
- aspizu
-
Scratcher
60 posts
goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
goboscript was one of the first-place winners of FOSS HACK 25, and was awarded a 50,000 Rs. prize. FOSS HACK 25 was a open-source hackathon conducted on 22nd - 23rd February 2025 by the FOSS United Foundation. During the 48-hour hackathon, I had worked on several goboscript issues and feature implementation.
- hacktronics
-
Scratcher
100+ posts
goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
Is there a way to generate blocks xml from a text file, instead of creating a project, direct exe or better wasm. I was hoping to integrate with CodeSkool, a free to use, commercial Scratch mode for Robotics and AI. Instead of generating a whole project, wanted user to just fast type something that will be added to the current project. Creating a whole project has limited use cases.
- Minecraft_dog1284
-
Scratcher
27 posts
goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
YESSSSSSSS PLEASE ADD ST!!!!!!!!! 

- _E-J_
-
Scratcher
100+ posts
goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
GOBO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- aspizu
-
Scratcher
60 posts
goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
star the repo
- gilbert_given_189
-
Scratcher
1000+ posts
goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
star the repodone
- redspacecat
-
Scratcher
500+ posts
goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
This is a great project! If only there's more blocks implemented…I tried making that my own text based scratch recreation, and it is very difficult because it uses both kinds of dropdowns([variable v] of [Sprite1 v])Here is one such block. (its opcode is sensing_of with a child sensing_of_object_menu)
- aspizu
-
Scratcher
60 posts
goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
I'm adding an interpreter to goboscript, so you can directly run scripts written in goboscript.
it will have most of the features from Scratch. but it will still be very limited, additionally I will add file and network I/O through special procedures and functions which will do nothing when compiled normally.
goboscript run -i script.gs
it will have most of the features from Scratch. but it will still be very limited, additionally I will add file and network I/O through special procedures and functions which will do nothing when compiled normally.
- aspizu
-
Scratcher
60 posts
goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
functions now have default arguments, after i merge the kwargs branch, working on struct field defaults right now.
we got to hacker news front page guys!
we got to hacker news front page guys!
- aspizu
-
Scratcher
60 posts
goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
Last edited by aspizu (May 26, 2025 17:28:00)
- MonkeyBean2
-
Scratcher
500+ posts
goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
This is a great project! If only there's more blocks implemented…perhaps this could be implemented with a general purpose scratch embedding interface, that lets you create blocks with different inputs and fields and whatever for custom stuff or “hacked” blocks, something like embed_scratch(“sensing_of”, inputs = {“OBJECT”: embed_scratch(“sensing_of_object_menu”, inputs={…}, fields={…})}, fields = {“PROPERTY”: }) that takes care of some of the kind of complicated input/field formatting, that uses a shorthand for special blocks you normally don't think of as blocks because in the JSON format they are pretty much always in this shorthand format.([variable v] of [Sprite1 v])Here is one such block. (its opcode is sensing_of with a child sensing_of_object_menu)
Also, @aspizu if you don't already have a good way of viewing or testing out scratch, I recommend you write a little bookmarklet that lets you view and edit the JSON using projectjson = vm.toJSON() and vm.loadProject(projectjson)
- aspizu
-
Scratcher
60 posts
goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
Also, @aspizu if you don't already have a good way of viewing or testing out scratch, I recommend you write a little bookmarklet that lets you view and edit the JSON using projectjson = vm.toJSON() and vm.loadProject(projectjson)
I already have a bash script that extracts the project.json file from a .sb3 file and validates it using the built in validation schema used by Scratch editor.
see the file tools/run in the repository.
- MonkeyBean2
-
Scratcher
500+ posts
goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
Ahh very nice, I'm writing my own scratch targeting compiler as well, and I've often resorted to staring at the scratch-generated JSON and my JSON trying to figure out what exactly it doesn't like, lol.Also, @aspizu if you don't already have a good way of viewing or testing out scratch, I recommend you write a little bookmarklet that lets you view and edit the JSON using projectjson = vm.toJSON() and vm.loadProject(projectjson)
I already have a bash script that extracts the project.json file from a .sb3 file and validates it using the built in validation schema used by Scratch editor.
see the file tools/run in the repository.
- redspacecat
-
Scratcher
500+ posts
goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
Relatable… Scratch has a lot of very specific requirements for a project to be valid to load.Ahh very nice, I'm writing my own scratch targeting compiler as well, and I've often resorted to staring at the scratch-generated JSON and my JSON trying to figure out what exactly it doesn't like, lol.Also, @aspizu if you don't already have a good way of viewing or testing out scratch, I recommend you write a little bookmarklet that lets you view and edit the JSON using projectjson = vm.toJSON() and vm.loadProject(projectjson)
I already have a bash script that extracts the project.json file from a .sb3 file and validates it using the built in validation schema used by Scratch editor.
see the file tools/run in the repository.
- aspizu
-
Scratcher
60 posts
goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.
Relatable… Scratch has a lot of very specific requirements for a project to be valid to load.
and all of those requirements are formally defined in the JSON schema of the scratch-parser npm module.
https://github.com/scratchfoundation/scratch-parser
- Discussion Forums
- » Advanced Topics
-
» goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.









