Repository navigation
Commit 15b04d4
Markus
chore: prototype an idiomatic Lark (LALR) engine for workflow expressions
Evaluation spike for Discussion github#4917; the candidate proposed there.
Adds engine_lark_a2.py and wires it into engine.py:
- LALR parser with keyword terminal priority; same language as today.
- The ambiguous-precedence guards are a grammar property: a filter chain
only applies to an operator-free head, so a pipe after a comparison or
after `not` is a parse error ("ambiguous filter precedence").
- The PATH terminal is built from namespace._PLAIN_SEGMENT /
_INDEXED_SEGMENT, so path syntax has one definition; the existing drift
test now covers the grammar too.
- _collect_leaves / _evaluator_rejects are a single static tree walk; the
probe run and _leaf_sink are gone from the contract.
- _syntax_error returns the parser's message with column, which the
condition diagnostics use.
- Filters dispatch through FILTER_TABLE.
Deliberate test changes, each with its reason in the test:
- [1,2,3][1] and an unclosed quote in a condition raise ValueError
instead of silently yielding None / False.
- Trailing tokens after a filter name, and a comparison after a filter
chain, are parse errors ("invalid expression") instead of dispatcher
messages; still ValueError.
- Three diagnostics fixture rows expect the parser's message.
- The probe-only tests are replaced (leaf-walk transparency of groups) or
removed (_leaf_sink); imports of engine internals are dropped.
Measured: corpus 96/96; full test suite 11427 passed, 0 failed; owned
code 334 SLOC, cognitive complexity 110 vs 166 (hardest function 31 vs
70); runtime about 1.3x the hand-written engine.
Assisted-by: OpenCode (model: claude-opus-5.5, autonomous)1 parent ce25492 commit 15b04d4
6 files changed
Lines changed: 638 additions & 74 deletions
File tree
- src/specify_cli/workflows/expressions
- tests
- unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
| |||
57 | 56 | | |
58 | 57 | | |
59 | 58 | | |
60 | | - | |
61 | 59 | | |
62 | 60 | | |
63 | 61 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
| |||
31 | 30 | | |
32 | 31 | | |
33 | 32 | | |
34 | | - | |
35 | 33 | | |
36 | 34 | | |
0 commit comments