peggyjs / peggy

Peggy: Parser generator for JavaScript
https://peggyjs.org/
MIT License
914 stars 65 forks source link

Multi file #417

Closed hildjj closed 8 months ago

hildjj commented 1 year ago

This is a PR draft exploring another part of #292.

What if you could just pass multiple files in on the command line, and have Peggy stitch them together into a single output?

This points out a few issues:

hildjj commented 1 year ago

There's a timing bug in the watchfile tests as well. Will deal with it if we end up using this.

hildjj commented 9 months ago

I think the sourcemap thing isn't an issue. This works surprisingly well already. Still needs a compiler pass that checks if output type is "es" and looks for import lines to move to the top.

hildjj commented 9 months ago

Still needs docs, a changelog entry, and some thought about how this affects the version number.

hildjj commented 9 months ago

Being able to specify a URL in the CLI would be pretty cool. In order to do this, I'd look for filenames starting with https?://, use fetch to pull down the contents, and cache it, like deno. This would up the minimum version of node required to be v18 -- That's fine with me because:

a) we're taking a breaking change in this release for node version anyway. b) Node 16 is no longer supported.

This would make importing rules from a central repository easier, I think.

frostburn commented 8 months ago

Tested combining grammars from two repositories successfully: https://github.com/frostburn/peggy-string-concat

hildjj commented 8 months ago

Another patch coming with other issues fixed.

hildjj commented 8 months ago

OK, I think I fixed all of the outstanding issues. I've left this as two patches since review to make it easier to see the changes, but I'll reorder and clean up the patch before merging.

hildjj commented 8 months ago

This is ready to squash and merge.

hildjj commented 8 months ago

ready to go if anyone wants to take a last look. Next step is to merge the imports grammar back into the main grammar, and give it two entry points. Then, I'll use the imports grammar to add imports syntax before toplevel initializers.