SpaceManiac / SpacemanDMM

A BYOND language smartness provider, map renderer, and more.
https://marketplace.visualstudio.com/items?itemName=platymuus.dm-langclient
GNU General Public License v3.0
83 stars 83 forks source link

Expose parser and AST to external programs #261

Open Karolis2011 opened 3 years ago

Karolis2011 commented 3 years ago

So, this is a suggestion to add FFI that would allow understanding DM from other languages.

I have started working on mine, myself, https://github.com/Karolis2011/dremamaker-ffi But it would require more work to expose all internal rust structs also as alternative I tried using json serialization but that requres that all structs be serializable.

Why would this be useful? Let's say I want to write myown dream checker in python, then I could use FFI and use already build rust code base logic to do heavy lifting of lexing and parsing while peaple could care only for analysis code.

SpaceManiac commented 3 years ago

I'm hopeful that SpacemanDMM's parser can be useful to other projects as it was useful to StrongDMM. But in order to keep SpacemanDMM flexible enough to adapt to BYOND changes and to improve over time, I don't want to commit to API stability. Also, maintaining complicated code and making binary releases for a C FFI layer that doesn't see much use isn't something I want to commit to.

You could try to maintain your own C FFI but it's probably not worth it given the 'one and done' nature of parsing an environment. You suggest JSON serialization, and this is also the strategy StrongDMM uses. While I would accept a patch to mark SpacemanDMM's structs as Serializable, I similarly do not want to commit to keeping the output of that serialization stable. I would recommend doing like StrongDMM does: use Rust code to adapt SpacemanDMM's structures into structures of your own, which you then export as desired.

Mothblocks commented 3 years ago

On this note, I've been interested in writing mlua bindings, I wanted to write tg specific lints with very little overhead in terms of distribution, but are too complicated for basic greps (such as requiring SIGNAL_HANDLER on signal handlers). The best way to do this seemed to be just adding a very simple Lua interface, which is solid as an embedded language for this purpose.