tldr: This is an overly complicated tool with the following parts:
- DSL (domain specific language) for Lua typing information (LUARS)
- PEG Grammar for LUARS using the pest.rs crate (see: luars.pest)
- Manually documented Types for the PlaydateSDK expressed in LUARS (see: playdate.luars)
- A web scraper which scrapes the PlaydateSDK documentation using the scraper crate.
- A rust which combines the scraped documentation and types and generates LuaLS compatible Type Annotations with documentation and types for the entire SDK.
- I've been coding Lua for Playdate.
- The PlaydateSDK has no types and leverages Lua dynamic nature for variadic params and returns.
- There's a pretty good Language server for Lua which created a standard for Lua typing via comments (LuaCATS)
- I've been learning rust.
- I wrote a scraper for the PlaydateSDK docs (in rust)
- For each function I generated a TOML skeleton and manually determined parameter and return types.
- TOML turned out to overly verbose, fragile and unsearchable for ~1000 functions and ~3500 type definitions (~15K lines).
- So I came up with a format for function signatures which only requires one line per function.
- I learned PEG and wrote a parser for function signature format I came up with.
- Iterate. Iterate. Iterate.
Now we can do static code analysis, type checking and autocomplete in VSCode and other IDEs that support the LuaLS Language Server's LUACATS style type annotation comments. Just use notpeter/playdate-luacats.
Semicolon terminated statements which begin with global|local|fun
.
Global is for tables in the global playdate.*
table.
Local is for table types used by the SDK.
Fun is functions (and parameters, parameter types, returns, return types and optionality of each).
See the LUARS pest.rs PEG Grammar and Playdate.luars for more.