Inspiration

The scratch-fuse project was born out of frustration with existing Scratch text-based solutions like Goboscript and Tosh. I (FurryR) found these tools suffered from several issues: Goboscript's local variable system was flawed and buggy in recursive or complex scenarios; struct implementations were just collections of variables, hard to organize and unable to support nesting; and its syntaxes were too "Pythonic," leading to a poor coding experience. To create a truly practical Scratch programming language and toolchain, I decided to build FUSE language from the ground up.

What it does

scratch-fuse is a complete ecosystem toolchain that compiles the advanced FUSE programming language into Scratch 3.0 projects. The organization maintains 8 core repositories:

  1. Core Functionality: The core repo provides the lexer and parser; compiler implements FUSE to IR compilation and decompiler features; serializer converts IR to Scratch SB3 format and supports deserialization.
  2. Developer Tools: The lsp repo offers Language Server Protocol (LSP) support, including syntax highlighting, code completion, error checking, and other IDE features. The formatter repo provides code formatting tools.
  3. Utility Components: builtins contains Scratch builtin block definitions; utility supplies common functions; fuse is the main CLI compiler.

How we built it

The project uses TypeScript as its principal language and builds a modular architecture. Each module has specific responsibilities:

  • Parsing Layer: Utilizes core’s lexer to parse FUSE into AST.
  • Compilation Layer: compiler turns AST into IR, providing advanced decompiler capabilities including intelligent variable renaming, function format detection, operator reconstruction, and namespace matching.
  • Serialization Layer: serializer handles conversion between IR and Scratch SB3.
  • Tools Layer: Offers LSP server, code formatter, and CLI interface.

All modules use unified build tooling (tsup) and follow the MPL-2.0 license.

Challenges we ran into

Currently, the parser fails on parsing large (>30MB) scripts and we'd like to find a solution to resolve the issue. We have refactored parser and lexer with streaming API, but it has poor effect.

Accomplishments that we're proud of

  • Complete Toolchain: Built a fully-featured toolchain from parsing to Scratch project generation, supporting bidirectional conversion.
  • Modern IDE Features: Implemented (partial) LSP support for a contemporary programming experience, and even compatibility with tooling like GitHub Copilot.
  • Advanced Decompiler: Developed a decompiler to decompile Scratch projects into FUSE projects, which helps developer to migrate their projects into FUSE seamlessly.
  • Modular Architecture: Each component is highly modular, developers may use any of these repositories to create their own FUSE-based project (e.g. Scratch vibe coding)

What we learned

Through this project, we gained deep insights into:

  • Compiler Theory: Building a full language toolchain from lexing to code generation.
  • Language Server Protocol: Integrating custom language support for modern IDEs.
  • Scratch Internal Mechanics: Thorough understanding of Scratch’s block and project formats.
  • Open Source Management: Managing and expanding a multi-module open-source ecosystem.

What's next for scratch-fuse

Future directions include:

  1. Ecosystem Expansion: Improving and extending the toolchain with more practical features and integrations, e.g. Scratch editor integration.
  2. Community Development: Promoting the project through hackathons and growing developer contributions.
  3. Performance Improvements: Continuously optimizing the compiler and LSP for larger projects.
  4. Educational Applications: Introducing tools into EDU environments to help students learn programming concepts.
  5. Standardization: Driving FUSE language standardization and establishing robust syntax guidelines.

The scratch-fuse project showcases open source innovation in educational tech, bringing powerful new capabilities to Scratch-related development and enabling more efficient and professional creation of complex Scratch projects, while empowering Scratch editors (IDEs) with the ability of text-based programming language.

Share this project:

Updates