firrtl-spec icon indicating copy to clipboard operation
firrtl-spec copied to clipboard

Linguist Support, TextMate Grammar Support

Open seldridge opened this issue 2 years ago • 5 comments

FIRRTL has enough usage (O(100) repositories) that we can get it in as a supported language by Linguist (GitHub's source code identification/highlighting repository). This requires two things as far as I can sort out:

  1. We need to provide a TextMate-compatible grammar definition. A very basic version of this is here: https://github.com/seldridge/firrtl-grammar/blob/main/grammars/firrtl.json Somewhat annoyingly, I think this needs to be in a separate repository (not firrtl-spec) whose directory structure matches that of a TextMate grammar definition/bundle.
  2. We then go through the steps to add this grammar definition to Linguist via a PR.

Structurally, we should probably create a tool directory inside firrtl-spec to start bundling some of these editor-specific things.

Search query for number of files: https://github.com/search?q=path%3A*.fir+NOT+is%3Afork+circuit&type=code&ref=advsearch&query=path%3A*.fir+NOT+is%3Afork+circuit

seldridge avatar Dec 28 '22 20:12 seldridge

By my count there are ~8k code samples on GitHub as gleaned from the following search:

https://github.com/search?p=10&q=extension%3Afir+NOT+flang+NOT+func+NOT+%22RUN%22+-user%3AKosinskiLab+-user%3Alukezya+-user%3ALourencoPonces+-user%3ALesible+-user%3Ajoaomiguelcaldeira&type=Code

This is slightly complicated as .fir shares a file extension with FLANG IR.

seldridge avatar Dec 28 '22 20:12 seldridge

This is slightly complicated as .fir shares a file extension with FLANG IR.

In theory, all FIRRTL must have a version identifier after that was introduced, and so maybe that can be checked to differentiate the two? (if not just 'are the first (non-whitespace?) characters "FIRRTL"?'). Just a thought.

dtzSiFive avatar Jan 20 '23 16:01 dtzSiFive

Checking for the version string / FIRRTL in it would enable a trivial heuristic to differentiate the two. Great thinking.

seldridge avatar Jan 20 '23 16:01 seldridge

Checking for the version string / FIRRTL in it would enable a trivial heuristic to differentiate the two. Great thinking.

Wouldn't all older FIRRTL files start with circuit? Then if you check for FIRRTL or circuit your heuristic should work for virtually all firrtl files.

ekiwi avatar Jan 20 '23 18:01 ekiwi

Checking for FIRRTL or circuit sounds great. 👍

seldridge avatar Jan 20 '23 18:01 seldridge

Fixed with https://github.com/github-linguist/linguist/pull/6848.

seldridge avatar Jun 10 '24 14:06 seldridge