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

Detect *.peggy files as PEG in GitHub #544

Closed
wants to merge 1 commit into from

Conversation

spenserblack
Copy link

Thank goodness I stumbled on this! I was about to give up on using the (unmaintained) PEG.js.

Linguist is the tool that GitHub uses to detect languages. This adds an override to .gitattributes to make Linguist detect files with the .peggy extension as PEG.js. This adds syntax highlighting to those files, and makes sure that they're included in the language stats.

Unfortunately, .peggy doesn't seem to be popular enough yet to "officially" be made a PEG.js extension. I'll make a PR there just in case. So for now, using the language override seems to be the best way to get .peggy files detected as code. Vim or Emacs modelines can also be used.

@hildjj
Copy link
Contributor

hildjj commented Aug 28, 2024

This is great, and thank you for offering to file a bug over there to get the ball rolling.

Can you please add something to docs/documentation.html about this, and ensure you are in the AUTHORS file?

@spenserblack
Copy link
Author

Sure! I wasn't sure where to mention this in the docs. I just kind of skimmed, but I didn't see anything like a "recommended project structure" section where I could recommend a .gitattributes file.

I'll get a PR out to Linguist soon. If it gets approve and isn't marked pending popularity, you might not need this PR at all 🙂 Is it cool if I use one of the files in examples/ as a code sample for the Linguist PR?

@hildjj
Copy link
Contributor

hildjj commented Aug 28, 2024

Yes, those examples are fine. The most interesting one is probably fizzbuzz.peggy which tries to have one of every syntax construct, including ones that have been added since the fork from PEG.js. I've got several other projects to point to if you need them.

Please link to the linguist bug here for tracking.

If you add a section almost at the end, before "Compatibility", I can also say something about the new TypeScript support (which hasn't shipped yet) in that section; it would say "put your .peggy file in src/, generate parser.js and parser.d.ts into lib/, and reference the .js file in your .ts file with '../lib/parser.js'". I think this would be a good place to suggest using a .peggy.confg.js file as well. I'll add all of that if you stub it out.

@spenserblack
Copy link
Author

github-linguist/linguist#7017

@spenserblack
Copy link
Author

Looks like we commented at the same time 😆

I opted for the semver example because it's a bit more "real world" in terms of its usage. Linguist doesn't like "Hello world" style examples, and I think a fizzbuzz example could fall under that category.

@hildjj
Copy link
Contributor

hildjj commented Aug 28, 2024

Note the new grammar syntax constructs since the fork are:

  • expression |count| (etc) Finite repetition
  • @ ( label : )? expression plucking
  • {{}} top-level initializer

@spenserblack
Copy link
Author

spenserblack commented Aug 28, 2024

Note the new grammar syntax constructs since the fork are:

  • expression |count| (etc) Finite repetition
  • @ ( label : )? expression plucking
  • {{}} top-level initializer

🤔 That syntax is supported by the VS Code extension, right? Is that backwards-compatible with "old" PEG.js? If so, it might be worth updating Linguist to also use the new syntax grammar. The current grammar comes from here, I think. Or it may be worth making a PR into https://github.com/Alhadis/language-grammars to update the grammar there.

@hildjj
Copy link
Contributor

hildjj commented Aug 28, 2024

🤔 That syntax is supported by the VS Code extension, right? Is that backwards-compatible with "old" PEG.js?

Yes, because I maintain that now, too, and IIRC someone sent me a patch. Current code is here: https://github.com/peggyjs/code-peggy-language

If so, it might be worth updating Linguist to also use the new syntax grammar. The currently grammar comes from here, I think.

Yes, it's worth doing that at the same time. The new syntax is a proper superset of the PEG.js syntax; backward-compatibility has been a high priority for Peggy.

@hildjj
Copy link
Contributor

hildjj commented Aug 28, 2024

If you want a lower-latency way to talk this all through, we've got a Discord you can get to from https://peggyjs.org/

@hildjj
Copy link
Contributor

hildjj commented Aug 28, 2024

Another good example that is real-world here: https://github.com/hildjj/node-abnf/blob/main/lib/abnfp.peggy

@spenserblack
Copy link
Author

The Linguist PR was approved, so this PR probably isn't needed after all. .peggy files should automatically be detected as PEG.js in the next release.

@hildjj
Copy link
Contributor

hildjj commented Aug 28, 2024

OK, I'm going to close this as overcome by events, but feel free to either re-open or add more comments here as needed. I've subscribed to the linguist bug to watch for other updates. Let us know if we can help with updating the syntax.

Thanks for the work!

@hildjj
Copy link
Contributor

hildjj commented Aug 28, 2024

Superseded by github-linguist/linguist#7017

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