Harbour's `#xcommand DEFAULT <v1> TO <x1> [, <vn> TO <xn>] => ...` uses an optional, repeatable trailing `[...]` block to accept any number of `var TO default` pairs on a single line. Five's PP skipped bracket bodies during pattern matching and treated them as no-ops in result templates, so DEFAULT a TO 10, b TO 20, c TO 30 expanded (at best) the first pair and dropped the rest — and common.ch itself was documented as "not yet supported". Three concrete changes: 1. matchPattern now matches the `[...]` body repeatedly against remaining line tokens via a new matchSegment helper. Each successful iteration appends captures for the interior markers under the same name, joined with a \x01 sentinel. 2. matchSegment, when capturing the last marker in a body with no following literal, uses the body's opening literal (e.g. the `,` in `[, <vn> TO <xn>]`) as the iteration boundary. Otherwise captureExpression would greedily eat the rest of the line and collapse every remaining pair into one capture. 3. applyResult's new expandOptionalRepeat walks the result template for top-level `[...]` blocks. When a referenced marker is multi- captured it emits the body N times (substituting per-iter value); when it's single-captured it emits the body once; otherwise drops the block. A separate referencedMarkers scanner and an inMarker guard keep literal `[` / `]` inside PP markers (like `<.x.>`) from being mistaken for bracket delimiters. Side fix: ParseRule previously stripped every ` ;` as a Harbour line-continuation marker, but that also destroyed in-line PRG statement separators in result templates. Line joining is the preprocessor's job upstream — keep semicolons intact here. common.ch now ships real DEFAULT and UPDATE #xcommands. Verified 1-, 2-, and 3-pair DEFAULT expansion plus `common.ch` inclusion from user code. FiveSql2 43/43, Harbour compat 56/56, Go test ALL PASS. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
28 lines
922 B
Plaintext
28 lines
922 B
Plaintext
/*
|
|
* common.ch — Five compatibility shim for Harbour's common.ch
|
|
*
|
|
* Harbour ships #translate-based aliases for ISNIL / ISARRAY /
|
|
* ISNUMBER / ISCHARACTER / ISLOGICAL / ISDATE / ISBLOCK / ISMEMO /
|
|
* ISOBJECT. Five registers those as direct RTL symbols in
|
|
* hbrtl/register.go (each points at the same Go function as its
|
|
* HB_IS* twin), so they work without any preprocessor translation.
|
|
*
|
|
* The DEFAULT / UPDATE #xcommand forms use Five's optional-repeat
|
|
* PP support — `DEFAULT a TO 1, b TO 2, c TO 3` expands into three
|
|
* `IF x == NIL ; x := v ; ENDIF` statements.
|
|
*/
|
|
|
|
#ifndef HB_COMMON_CH_
|
|
#define HB_COMMON_CH_
|
|
|
|
#define TRUE .T.
|
|
#define FALSE .F.
|
|
#define YES .T.
|
|
#define NO .F.
|
|
|
|
#xcommand DEFAULT <v1> TO <x1> [, <vn> TO <xn>] => IF <v1> == NIL ; <v1> := <x1> ; ENDIF [; IF <vn> == NIL ; <vn> := <xn> ; ENDIF ]
|
|
|
|
#command UPDATE <v1> IF <exp> TO <v2> => IF <exp> ; <v1> := <v2> ; ENDIF
|
|
|
|
#endif
|