The code is a bit long. So, I put it at the bottom of the page. It took five or six hours to come up with. That may seem like a long time for that much code, but it's not. Most of the time was spent learning enough about C to be able to get things working.
Said another way, writing the code was the easy part. Figuring out _what__ to write is what took all the time.
I used three references/resources to get me going:
- The Tree-sitter "External Scanners" Documentation^docs^^
- The source code of another parser that uses C^code^^
- The LearnXinYminutes C examples^learn^^
I could have done it without the source code sample, but it probably saved me half an hour of experimenting and troulbeshooting by acting as an reference example.
I don't know how much time I spent going through the C page of Learn X In Y Minutues. I'd guess half an hour, but I was skimming for parts of it. And, I didn't really learn what I was doing. Really, I was just looking for code I could copy/paste to get me going.