| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
After Alt-o, Alt-i, Alt-n or Alt-p (helix's node walks, run in the
editor on the module's parse) the primary range is read back and the
text compiled again with it as a probe: Lang.compile takes the bytes of
a selection and compiles the smallest expression holding them into a
third tape, `Program.probe`. The compiler learns each expression's bytes
as it parses (`spanned`: a number, a name used, a call, parentheses, a
unary minus, each binary operation, a whole line), keeping the smallest
that holds the probe: no table of spans. A name used is the line that
defines it, so a walk onto `kick` hears kick.
State keeps the probe's tape (`probe`, empty when there is none). While
it is set, `draw` hears it as `out` (through the crossfade, as any
change) and sees it as the picture, grey unless it is a colour. Any
other key empties it, so Escape or an edit goes back to the program. It
is in State, so a replay probes where the session did.
Test: Lang.zig, a probe on an argument, a number, a cursor on one of its
digits, a name used, a line's name, a selection Alt-o grew to, and
between two lines (none); test/live.script, Alt-o twice from the 2 of
220 (`220`, then `tau * 220`), then Escape. Lang.compile takes the probe
as a second argument; the other calls pass null. zig build test: 85 of
85 steps, 8 of 8 tests.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
|
|
|
grammar/grammar.js is the language as src/Lang.zig parses it, for
tree-sitter (24 lines): lines of `name = expression` parted by newlines,
`+ -` below `* /` below unary `-`, calls, parentheses, numbers (Lang's
digits, point and `e`), names, `#` comments as extras. `tree-sitter
generate` (tree-sitter 0.26.9; ABI 14, the CLI's without a
tree-sitter.json) wrote grammar/src/parser.c (918 lines) and its
tree_sitter/ headers, committed: the build compiles them into the sketch
as a static library and never runs the generator.
The `Language` is handed to the editor at run time (`tree_sitter_live`,
queries/highlights.scm and queries/indents.scm embedded). The parse is a
module's `Syntax`, kept between calls so Alt-i goes back the way Alt-o
came, handed to every key, forgotten at a jump (in `draw`, `in.jumped`)
and started again by a reload (the tree a reload leaves is leaked:
marked ponytail). `code` colours each run of bytes by `Syntax.colors` in
pardes's own theme (orchard, the first): a defined name as a keyword, a
called builtin as a string, numbers and comments as theirs, the rest in
the theme's ink.
indents.scm gives a new line no indent outside an open call or
parenthesis: pardes's plain indent is a level more after `)`, so every
line of this language that ends in a call pushed the next one in. The
library now reads a handed-in language's indent query (pardes, its own
change).
Test: test/grammar.zig parses with the grammar and compiles with Lang.zig
22 texts: the survey's program and two others both take; eleven broken
lines both refuse (an unclosed or extra parenthesis, a missing operand or
`=`, two numbers, `1.2.3`, a stray `$`); eight both parse but only
Lang.zig refuses, as only it knows names, builtins, arities and where a
colour may stand (a name used before it is defined or defined twice, a
builtin redefined or called with too few arguments, an unknown call, a
colour outside the color line, a name called). Lang.zig's survey is
public for it. zig build test: 85 of 85 steps.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
|