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

Add support for plugins to change parsing, printing, and visiting behaviors #213

Closed
wants to merge 22 commits into from

Conversation

Kampfkarren
Copy link
Owner

@Kampfkarren Kampfkarren commented Dec 8, 2021

Won't close #152 until we actually do make those plugins (especially the Luau one, which I don't really want to maintain, at least not alone).

Will write extensive documentation later.

Point is every node now has a P: Plugin generic (defaulting to DefaultPlugin) which links to structs that implement PluginMod for every node (AssignmentMod: PluginMod<Assignment<Self>>), which contains the information for what values to put in each node, as well as display, and when I finish it, visiting. Plugins will also likely be where custom parsing is handled. You will only be able to have one plugin at a time.

This is all designed to, ideally (though not tested), be completely zero-cost if no plugin is used. DefaultPlugin has () as its NodeInfo for structs, and Never (an empty enum, ideally ! in the future?) for enums. () is a ZST, meaning it will not take up any additional space in the struct, and Never means that the branch should functionally not exist in the eyes of the compiler, since it is uncreatable in safe Rust.

Creating plugins is a bit obtuse, but shouldn't be a big deal since the number of consumers will be very small, and probably kept in close contact with me.

  • Custom struct/enum information
  • Custom parsers
  • Custom visitors
  • Port Luau
  • Port Lua 5.2
  • Documentation
  • Proc macro to supplement default associated types

@rzvxa
Copy link
Contributor

rzvxa commented Jan 24, 2024

Hello @Kampfkarren, Sorry for pinging you on this old PR, But I couldn't help but wonder why this got closed. Were there any challenges with the current structure of the parser that makes it impossible to decouple stuff?

I'm working on a gradually typed language that compiles to Lua and can target all runtimes. In some sense, it is similar to TypeScript, But it is not really a superset; While most things in the syntax are close to Lua, and Luau, The language comes with its own quirks such as nil safety, pattern matching, if expression among other things.

Since full-moon has support for all of the target runtimes, It would be nice if it was possible to have an extendable system that would allow having multiple AST types simultaneously.

I would happily work on it with you, Was there ever a plan to also make AST extendable? Either way, I'm probably going to base my compiler's parser on this project and I prefer to contribute it back to this project. There are going to be some generalizations to support a higher-level syntax(such as the macro system and other new features). I know at least part of it could be welcomed here with this PR.

If we want to decouple different language features from the parser we should consider also modularizing the AST itself, Which in return needs to have extendable Stmt, Expression, etc. It would introduce some sort of dynamic dispatching into the mix which I'm not sure is the most desirable thing. On the other hand, if we can't make the AST extendable without introducing too much overhead I need to hard fork it for extension and with each Luau update or new Lua release or on the off chance that this language gets some actual users in the wild, we all get to update our versions respectively.

I haven't read the source thoroughly so I need more time before I can have a solid understanding of the project structure, Have you considered extending plugins to AST itself? If it was part of the plan, what was your idea for tackling it? I would appreciate it if you let me know.

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.

Allow custom parsers to be created, separate roblox and 5.2 features into their own crates
2 participants