fix(pp,parser,gengo): pre-release blocker round (Wave 1)
Six audit-driven blockers landed together because they're tangled:
* MENU TO removed from std.ch — the rule expanded to a call to a
nonexistent __MenuTo() RTL symbol, so any user code with `MENU
TO choice` compiled clean and panicked at runtime. Behavior
pre-this-round was a parser silent no-op, which is at least
consistent. Restore that until @ PROMPT (the companion command)
actually lands.
* COUNT now requires `TO <var>`. The earlier `[TO <v>]` optional
bracket was a Harbour-pattern transcription error: the result
template references `<v>` unconditionally, so a bare `COUNT`
expanded to ungrammatical ` := 0 ; dbEval(...)` and the
PRG parser rejected it. Match Harbour's std.ch which makes TO
mandatory.
* UPDATE FROM ... REPLACE now requires `FROM`/`ON`/`REPLACE` all
three. Same root cause as COUNT: the result template uses
`<key>`, `<f1>`, `<x1>` unconditionally; missing any of them
produced broken syntax. Tightened to fail loudly rather than
silently mis-expand.
* CLOSE <unknown_alias> no longer closes the *current* workarea.
SelectByAlias was a silent no-op when the alias was missing,
leaving WASaveAndSelectAlias to evaluate the inner DbCloseArea()
against the originally-selected WA — a real data-loss footgun.
SelectByAlias now returns bool; WASaveAndSelectAlias switches to
the no-area sentinel (0) on miss so the inner expression's
Current() returns nil and short-circuits.
* SUM <x1>, <xN> TO <v1>, <vN> — multi-pair form supported.
Required two pieces:
1. matchSegment's regular-marker stop-boundary now combines
outerTail literals AND the segment's repeat boundary so
`[, <xN>]` doesn't let `<xN>` swallow past the next ','.
2. **Five parser miscompiled comma-separated expressions in
code blocks.** `{|| e1, e2, e3 }` kept only the last expr
and threw away earlier ones at *AST level*, so all their
side effects vanished. New SeqExpr AST node + emitter
(emit each, pop intermediate results) + folding/walk
updates fix the underlying bug, which also unbreaks any
other block that relied on comma sequencing.
* pp.go's `;` continuation joiner now strips exactly one trailing
`;` per iteration, preserving Harbour's `;;` convention (literal
`;` followed by a continuation marker). Without this the SUM
rule's chained `<v1> :=[ <vN> :=] 0 ; ; dbEval(...)` collapsed
to a missing statement separator.
* parseExprStmt's xBase fallback switch is back in sync with
parseIdentStmt — COPY/SORT/COUNT/SUM/AVERAGE/TOTAL/UPDATE/JOIN/
DISPLAY/LIST removed (std.ch handles all of them now). Leaving
them in the fallback masked typos as silent no-ops.
Gates green:
go test ./... : PASS
FiveSql2 SQL:1999 : 43/43
Harbour compat : 56/56
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -540,21 +540,29 @@ func matchSegment(segment, lineWords []string, startLi int, caseSens bool, outer
|
||||
default:
|
||||
return nil, startLi, false
|
||||
}
|
||||
// Build a pseudo-pattern tail so captureExpression picks the
|
||||
// right delimiters. Priority:
|
||||
// Build a pseudo-pattern tail so captureExpression picks
|
||||
// the right delimiters. Priority order (each level is
|
||||
// merged, then captureExpression stops at *whichever*
|
||||
// delimiter shows up first in the input):
|
||||
// 1. Next literals inside the same segment.
|
||||
// 2. Every literal in the outer-pattern tail — this is
|
||||
// what stops `[TO <(f)>] [FIELDS ...] [FOR ...]` from
|
||||
// letting `<(f)>` swallow a trailing FOR/WHILE/NEXT
|
||||
// clause that happened to be present.
|
||||
// 3. Repeat boundary (the segment's leading literal) so a
|
||||
// multi-iteration capture stops before the next iter.
|
||||
// 2. Every literal in the outer-pattern tail — what
|
||||
// stops `[TO <(f)>] [FIELDS ...] [FOR ...]` from
|
||||
// letting `<(f)>` swallow a trailing FOR/WHILE/...
|
||||
// 3. Repeat boundary (the segment's leading literal)
|
||||
// — needed for multi-iter `[, <xN>]` so each
|
||||
// iteration's `<xN>` stops at the next ',' before
|
||||
// the outer-tail's TO/FOR/etc. catches it.
|
||||
tail := segment[pi+1:]
|
||||
if !hasLiteralAfter(tail) {
|
||||
combined := []string{}
|
||||
if hasLiteralAfter(outerTail) {
|
||||
tail = outerTail
|
||||
} else if repeatBoundary != "" {
|
||||
tail = []string{repeatBoundary}
|
||||
combined = append(combined, outerTail...)
|
||||
}
|
||||
if repeatBoundary != "" {
|
||||
combined = append(combined, repeatBoundary)
|
||||
}
|
||||
if len(combined) > 0 {
|
||||
tail = combined
|
||||
}
|
||||
}
|
||||
captured := captureExpression(lineWords, &li, tail, 0, caseSens)
|
||||
|
||||
Reference in New Issue
Block a user