Document line-significance limitations in the Pico-8 Lua grammar
PICO-8's shorthand `if (cond) stmt [else stmt]` is line-bounded, but tree-sitter has no built-in newline awareness. Without an external scanner ( the same mechanism tree-sitter-python uses for INDENT / DEDENT / NEWLINE ), the grammar greedily binds `else` to the nearest `if` and takes only one consequence statement for the shorthand body. Token classification is unaffected, so syntax highlighting renders identically to a correct parse; only auto-indent and semantic selection are subtly off, in a code pattern that is uncommon in real PICO-8 code. New `grammars/pico-8-lua/KNOWN_LIMITATIONS.md` walks through both incorrect cases ( the dangling-else mis-bind and the multi-statement shorthand body ), tabulates which Zed features are and aren't affected, and sketches the fix. README cross-links it from the "Known limitations" block and adds it as a prerequisite to the v0.3 LSP work. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -53,6 +53,20 @@ their PICO-8 work continue to get standard Lua treatment.
|
||||
|
||||
### Known limitations
|
||||
|
||||
- **Line-significant dialect features are not modeled.** PICO-8's
|
||||
shorthand `if (cond) stmt [else stmt]` is line-bounded — a
|
||||
later-line `else` belongs to an enclosing standard `if`, not the
|
||||
shorthand. Without an external scanner, the grammar can't see
|
||||
newlines, so it greedily binds `else` to the nearest `if` ( the
|
||||
C / Java convention ) and treats a multi-statement single-line
|
||||
shorthand body as one statement plus a sequence of unconditional
|
||||
follow-ups. The parse is structurally wrong but **tokens still
|
||||
classify correctly**, so syntax highlighting renders identically
|
||||
to a correct parse; only auto-indent and semantic selection are
|
||||
subtly affected. Full write-up:
|
||||
[`grammars/pico-8-lua/KNOWN_LIMITATIONS.md`](grammars/pico-8-lua/KNOWN_LIMITATIONS.md).
|
||||
Slated for v0.3 work alongside LSP integration ( which needs a
|
||||
correct AST ).
|
||||
- **No language server.** No completion, hover docs, or diagnostics for
|
||||
PICO-8 builtins yet — only a static `function.builtin` highlight on
|
||||
recognized names. See Roadmap.
|
||||
@@ -163,7 +177,13 @@ fallback `unknown_section` rule.
|
||||
|
||||
### v0.3 — Language server integration
|
||||
|
||||
Wire up [`japhib/pico8-ls`](https://github.com/japhib/pico8-ls) ( or whichever
|
||||
Prerequisite: an external scanner for `tree-sitter-pico8-lua` so the
|
||||
shorthand-if and shorthand-while bodies are line-bounded the way PICO-8
|
||||
defines them. See [`grammars/pico-8-lua/KNOWN_LIMITATIONS.md`](grammars/pico-8-lua/KNOWN_LIMITATIONS.md).
|
||||
LSP features that walk the AST ( unreachable-code lint, goto-definition
|
||||
through a conditional branch ) need correct structure.
|
||||
|
||||
Then wire up [`japhib/pico8-ls`](https://github.com/japhib/pico8-ls) ( or whichever
|
||||
PICO-8 LSP is most maintained at the time ) for:
|
||||
|
||||
- Completion of PICO-8 builtins ( `spr`, `circfill`, `btn`, `flr`, … ).
|
||||
|
||||
Reference in New Issue
Block a user