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

feat: export to javascript using scala-js #4

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rhazn
Copy link
Contributor

@rhazn rhazn commented Apr 29, 2021

What

This PR adds an experimental export to javascript to the parser using Scala-JS. I was playing around with using the parser in a JS context (for parsing in a browser) and saw it is actually reasonably easy to do. This adds overhead and untested code so I am 100% okay with this PR not being merged, I just figured since I already did the work myself I can offer you the result.

Maybe this can serve as a discussion if you are interested in going down this route at all ;).

Demo

If you serve the generated file locally this is a minimal working example html:

<script type="module">
	import {TPTPParser} from "http://localhost:8000/main.js";

	console.log(TPTPParser.annotatedTHF("thf(f, axiom, ![X:$i]: (p @ X))."));
	console.log(TPTPParser.thf("![X:$i]: (p @ X)"));
</script>

That produces these console.logs in which you can see the generated objects for the parsed formulas.

Screenshot 2021-04-28 at 21 51 50

Issues

  • The generated JS code is 1.5mb big
  • The code is untested
  • The compilation might brake at any point in the future, e.g. if you introduce scala only libraries as dependencies

@rhazn
Copy link
Contributor Author

rhazn commented Apr 29, 2021

Ah this sadly seems to auto enable some testing that is not correctly initialized and therefore fails :(. Sorry I did not assume it magically registers tests, I'll have to look into that some time.

@rhazn rhazn marked this pull request as draft April 29, 2021 14:53
@lex-lex
Copy link
Member

lex-lex commented May 16, 2021

Thanks! Looks like a cool feature to have it as off-the-shelf as a JS library. Looking forward to see this progress :-)

@rhazn
Copy link
Contributor Author

rhazn commented May 19, 2021

I had a small additional look into this and it seems like it would take setting up a Cross-Building (https://www.scala-js.org/doc/project/cross-build.html) project for it to work. The setup I did only builds the JS part (as well as a JAR that only other scala-js projects can consume).

Sadly my sbt knowledge is limited, if I try to follow that guide to the best of my abilities the compiler can not find the scala-js annotations, even with the scalajs-stubs dependency mentioned at the end of the page.

I'll see if I can find the time to look into this a bit more down the line but for now I am out of ideas.

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

Successfully merging this pull request may close these issues.

2 participants