alda-lang / alda

A music programming language for musicians. :notes:
https://alda.io
Eclipse Public License 2.0
5.59k stars 286 forks source link

Decompiler - Setup #373

Closed Scowluga closed 1 year ago

Scowluga commented 3 years ago

The need for an Alda decompiler is twofold:

  1. With the start of interoperability, we are now able to import MusicXML into Alda IR (ScoreUpdate). Although we can do lots of stuff from this representation like output to JSON or play, we can't actually obtain Alda code itself from it. The decompiler will serve to decompile ScoreUpdate structs to Alda code so users can start writing Alda from imported music.
  2. Many great languages come with great formatters (ex gofmt). Alda may eventually aim to support built-in formatting. This is most easily done by scanning to parser.Token then formatting back to code. This PR will set up this formatter in the most basic form.

This PR sets up the decompiler by:

  1. Setting up packages and public methods code_generator.Generate and code_formatter.Format.
  2. Updating the MusicXML importer to use these method (and remove the bootstrapped play implementation).
  3. Refactor parser.Token parameters to be public so they can be used outside of the parser.

Alda compiler AST refactor

This PR will wait for a refactor of the Alda parser to include a step to transform into an AST instead of a flat []parser.Token. Then the generator will generate directly to this, and the formatter will get this as input.

Scowluga commented 1 year ago

Previous work on this task is a bit stale. Closing and restarting.