jdthorpe / kicad-module-parser

A PegJS parser for Kicad Modules
3 stars 3 forks source link

Add .kicad_sym grammar #6

Closed roberth-flux closed 5 months ago

roberth-flux commented 5 months ago

Impact

Adds a grammar for .kicad_sym files which unblocks supporting KiCad 6 symbol files in our import workflows.

Description

I've added a grammar to parse Kicad 6 symbol files. I've replicated the testing setup of the other grammars, ie. script fetching a bunch of symbol files and running them through the grammar parser, and then the post processing step to yield clean JSON.

Testing

Follow the instructions in tests/README.md

But essentially, populate the data files:

pushd data/symbols
./init.sh
popd

And then run the unit tests using yarn test, which compiles the typescript test files and then exercises the grammar parser against all the downloaded symbols from the data/symbols/repos.txt file.

We can add more repos here, but the default KiCad symbol repo is a great start and there are tens of thousands of symbols in the files.

Notes

I've also added a pegjs prettier plugin to format the files and run the symbol.pegjs file through it. We should probably do the same for the module grammar file.

I started running the tests against modules, symbols and boards, and so you'll see some fixes to the board grammar, but given we don't currently parse boards and I was running out of time to get this working, I stopped. To that end, I expect there to be failing boards in the test data set, but I bypassed them to get symbol parsing working. The modules parse correctly.