Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Research pragmatic bach.json to bach conversions in CLJS #26

Open
slurmulon opened this issue Feb 17, 2021 · 0 comments
Open

Research pragmatic bach.json to bach conversions in CLJS #26

slurmulon opened this issue Feb 17, 2021 · 0 comments

Comments

@slurmulon
Copy link
Owner

Problem

Right now the conversion to bach to bach.json is straight-forward, however the reverse conversion is not.

It's most noticeable in JS land, since only bach.track/compose is exported right now.

If you wanted changes to bach.json to be reflected in bach source code, you would need to use hacky regex patterns to perform the search and replacements in the bach source code.

If you're using a reactive web framework like Vue or React then you can be more declarative using string templates, but it still involves reflecting/re-implementing what bach.ast does already. The resulting code code is still dense and brittle, and the developer should not be expected to write it.

Solution

bach.ast, and the instaparse hiccup tree it provides, is already the lowest-level data structure in bach, and it can naturally be used to support bach.json -> bach conversions.

It would involve creating a new method in the bach core library that takes composed bach.json and then converts it bach into an AST.

This AST can then be used to re-compose the bach data.

This involves updating shadow-cljs and the bach-cljs package in general to export not only bach.ast but also any new modules or methods that are introduced with this work.

Alternative

We could achieve the same resulting by baking all of the string template and regex pattern weirdness into bach, but that solution is not particularly pleasant or speedy to write. It does, however, have better performance than converting bach.json into both bach.ast and bach, and that's why I mention it here to keep in mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant