Formal Grammar for Kicad_mod files

Is there a formal grammar for the kicad_mod files? I get that they are s-expression based and found a hand-written parser and a list of key-words, but I have not been able to find a formal grammar.

I was considering writing an extension for VS code that validates the grammar (not just the syntax – i.e. that a fp_line should contain a start, end, layer and width, but containing a pad or a lyer [typo] would be an error), and having a formal grammar would make writing a parser / validation tool in JavaScript (the native language for VS Code extensions) quite a bit faster.

I hereby certify that I am not simply asking someone else to design a footprint for me.

This is an auto-generated message that is in place on the “footprints” section of the KiCad.info forum. If I remove it and ask for a footprint to be designed anyway, I understand that I will be subject to forum members telling me to go design my own footprint or referring me to a 3rd party footprint site.

3 Likes

Because the parser is hand-written, we don’t have a formal grammar file. There are some spec files around but they don’t get updated (largely because there are no dependencies on them) frequently. The current plan is to update an outline for the v6 documentation.

I know quite a few folks who would love to see your VSCode validator

3 Likes

I wrote a PegJS Parser for Kicad Module files which can be found here. If I can find the time I’ll develop it into a VScode extension, and if someone beats me to it, all the better :slight_smile:

-Jason

1 Like