Skip to content

fix(include,omit): a terminator in a comment closes a COMPILE/OMIT block - #860

Merged
msarson merged 2 commits into
msarson:version-1.0.11from
geircodes:fix/terminator-quoted-in-comment
Nov 17, 2026
Merged

msarson merged 2 commits into
msarson:version-1.0.11from
geircodes:fix/terminator-quoted-in-comment

Conversation

@geircodes

Copy link
Copy Markdown
Contributor

What happened

A marker idiom used for debug-only code writes the COMPILE terminator quoted, in a comment:

  MEMBER
  COMPILE('*Debug*', _Debug_)   ! on for a debug build
  INCLUDE('Debug.inc'), ONCE
  !'*Debug*'

  INCLUDE('SomeClass.inc'), ONCE
  INCLUDE('OtherClass.inc'), ONCE

or on one line, with the terminator in the directive line's own comment:

  COMPILE('*Debug*', _Debug_); DebugBreak()  !'*Debug*'

With _Debug_ off this compiles: the compiler ends the block on the comment line. (If it didn't, the rest of the module would be dropped and the build would fail.) The extension never ended it. Everything after the directive counted as not compiled, so SomeClass.inc and OtherClass.inc were treated as not included, and the missing-include check reported the first variable of each class in the module:

'SomeClass' is defined in 'SomeClass.inc' which is not included.

Root cause

scanConditionalCompile (#807) strips every quoted string from a line before it looks for the terminator, and that includes the comment:

// A terminator counts outside strings, as the directive detector reads it (a comment counts).
const closes = (text: string, terminator: string) => text.replace(/'(?:[^']|'')*'/g, '').includes(terminator);

!'*Debug*' becomes !, so the terminator is gone. The rule was taken from OmitCompileDetector, which has the same stripping. The rule exists so that MESSAGE('***') doesn't close an OMIT('***'), and that still holds for strings in code. But a comment isn't code: the text after ! is plain text.

Separately, neither scan looked at the rest of the directive's own line, so the one-line form never closed either.

The fix

One shared test of a line, in ConditionalCompile.ts. The code part has its strings removed and the comment part is searched as it is:

export function terminatorOnLine(text: string, terminator: string): boolean {
    const live = code(text);
    // A string becomes '' rather than nothing, so the text either side of it does not join up.
    return live.replace(/'(?:[^']|'')*'/g, "''").includes(terminator) || text.slice(live.length).includes(terminator);
}

code() is the existing helper that cuts a line at the first ! outside a string, so MESSAGE('Hi! ***') stays code and does not close.

  • scanConditionalCompile uses it for every line, and checks the rest of the directive line after the matched directive. A block that closes there opens and closes on that line:
    if (omits) inactive[line] = 1;
    if (closes(text.slice(directive[0].length), terminator)) continue;
    stack.push({ terminator, omits, undecided: holds === undefined });
  • OmitCompileDetector.findDirectiveBlocksInLines uses it in its terminator pass. It also checks the rest of the directive line, but only reads that line when its tokens go on after the closing ), so OMIT body detection adds ~5 ms to every keystroke in a large module #733's "reads no line it does not need" still holds.
  • One more detector change. Its condition check treated any token after the terminator string as a condition argument, a trailing comment included. So OMIT('**Old**') ! the old way was skipped like a conditional block and its body was not treated as omitted. The argument list now ends at ), and a comment is not an argument. A conditional directive with a comment is still skipped (there is a test for this).
  • The strip now replaces a string with '' rather than nothing, as the detector already did, so that *'x'* does not join up into **. This changes nothing for the existing tests.

Tests

ConditionalCompileTerminatorInComment.test.ts (new, 11 tests):

  • Conditional scan:
    • a quoted terminator in a comment closes a block that does not compile; control: the same block compiling
    • the same for an OMIT that omits
    • a terminator in the directive line's comment, COMPILE and OMIT
    • the directive's own terminator argument does not close its block
    • MESSAGE('Hi! ***') still does not close
  • OmitCompileDetector:
    • a quoted terminator in a comment closes the block
    • a terminator in the directive line's comment closes it there
    • a terminator in a string in code still does not close
    • a trailing comment is not a condition argument; control: a conditional directive with a comment is still not a block

With the two source files reverted, 6 of the 11 fail and the 5 controls pass. The full server suite passes: 4562 passing, 0 failing, 3 pending. The existing #807 (ConditionalCompile807), #733 (OmitKeystrokeCost733) and OmitCompileDetector tests are unchanged and pass.

Scope

  • Does the compiler also ignore a terminator inside a string in code (MESSAGE('***') in an OMIT('***') block)? Both scans assume so, and this PR keeps that assumption. It isn't compiler-checked here, and it would be worth confirming.
  • The detector still skips every conditional block (it does not evaluate switches). That is unchanged.

🤖 Generated with Claude Code

Both scans stripped every quoted string from a line before looking for
the terminator, the comment included, so the marker idiom !'*Debug*'
never closed its block, and neither looked at the rest of the
directive's own line (COMPILE('*X*',_X_); F() !'*X*'). With the switch
off the block ran to the end of the file: every later INCLUDE counted
as not compiled and the missing-include check flagged their classes.
A comment is now plain text; a terminator in a string in code still
does not close. The detector also stops reading a trailing comment as
a condition argument. New ConditionalCompileTerminatorInComment tests:
6 fail without the fix; suite 4562 passing, 0 failing, 3 pending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@msarson

msarson commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks. The code does what it says: the build is clean, 6 of the 11 tests fail on the base, the suite passes, and it merges cleanly with head. The comment scanning ('', a ! inside a string, the same-line slice) checks out.

The one problem is the rule for a terminator inside a string in code. The help only says the block ends with "the line that contains" the terminator, so I compiled each case on Clarion 10. Each case was its own project, and the code inside the block refers to an unknown identifier, so the errors show which lines were compiled:

Block Result
OMIT('*X*') … !'*X*' (quoted, in a comment) closes there, as the PR says
OMIT('*X*') … !*X* closes there
OMIT('*X*'); s = 'a' !*X* (on the directive's own line) closes on that line, as the PR says
OMIT('*X*') … s = '*X*' (in a string in code) closes there, and the next line is compiled
OMIT('ENDX') … s = NoSuchENDXInside closes there, but that terminating line itself is still omitted (it gives no error)
OMIT('*X*') with no terminator OMIT not terminated: *X*

So the compiler does a plain text match on the line, whether the terminator is in a comment, in a string or inside a word. The two "a terminator in a string in code does not close" guard tests assert the opposite. As the PR stands, the extension would treat the rest of the block as omitted after s = '*X*', while the compiler compiles it.

Could you change terminatorOnLine to a plain substring search on the whole line? On the directive's own line it should search only after the directive's argument, as your slice already does. Please flip those two tests too. I haven't tested whether the match is case-sensitive; one more probe would settle that.

— Alice

…ipped or compiled

Review follow-up. Probing Clarion 11.1 and 12 shows two rules,
depending on whether the compiler skips the block or compiles it:

- skipped (OMIT, COMPILE with a false condition): a plain text search,
  so the terminator closes the block anywhere on the line, inside a
  string or inside a word too;
- compiled (COMPILE, OMIT with a false condition): the compiler reads
  through string literals, so a terminator inside a string does not
  close the block; one in code or in a comment does.

The match is case-sensitive either way. terminatorOnLine takes the
block's state: scanConditionalCompile passes whether the block omits
(an undecided block is read as compiled), OmitCompileDetector whether
it is an OMIT (it tracks only unconditional blocks).

Tests: 8 new in ConditionalCompileTerminatorInComment.test.ts; 4 fail
on the previous rule and 3 on a plain search everywhere. Four existing
tests asserted that a string never closes an OMIT: the 807 one is
flipped, the OmitCompileDetector and msarson#733 ones now use a COMPILE, and
an OMIT counterpart is added. Server suite: 4569 passing, 3 pending;
the SDI disk cache test timed out under full load as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@geircodes

Copy link
Copy Markdown
Contributor Author

Thanks, the compiler test was the right call. I ran your cases and some more on Clarion 11.1 and Clarion 12 (both gave identical results), the same way: one project per case, each line assigning an undeclared P_xx, so the "Unknown identifier" errors show which lines were compiled. Your table holds for every block that is skipped. A block that is compiled reads its terminator differently, so a plain substring search everywhere would be wrong there. Pushed f8d79a3 with both rules.

Skipped block (OMIT, or COMPILE with a false condition): plain text search, as you found.

Block Result
OMIT('*X*') … S = '*X*' & P_a2 closes there; the terminating line is omitted, the next is compiled
OMIT('ENDX') … V = P_NoENDXInside closes there
COMPILE('*X*',ProbeOff) … S = '*X*' & P_k2 closes there
OMIT('*X*'); S = '*X*' & P_d1 (directive line) closes on that line; the code after ; is omitted

Compiled block (COMPILE with a true condition or none, OMIT with a false condition): the compiler reads through string literals.

Block Result
COMPILE('*X*',ProbeOn) … S = '*X*' & P_m1 does not close: OMIT not terminated: *X*
OMIT('*X*',ProbeOff) … S = '*X*' & P_m1 does not close: OMIT not terminated: *X*
COMPILE('*X*') … S = '*X*' & P_m1 does not close: OMIT not terminated: *X*
COMPILE('*X*',ProbeOn) … V = P_m1 !'*X*' closes; quoted or not, a comment counts
COMPILE('ENDX',ProbeOn) … V = P_NoENDXInside closes; reported as Unknown identifier: P_NO, so the line is compiled only up to the terminator
COMPILE('*X*',ProbeOn); V = P_e1 (directive line) the code after ; is compiled

Case: the match is case-sensitive in both modes. OMIT('ENDX') is not closed by !endx but is by !ENDX; the same holds for '*x*' against *X*, 'EndX' against ENDX, and a compiled COMPILE('ENDX',ProbeOn) with !endx (OMIT not terminated). The existing includes is already case-sensitive, so nothing changes there.

(A literal condition such as COMPILE('*X*',0) is a compile error, Invalid OMIT/EMBED expression, so the conditional cases use ProbeOn EQUATE(1) / ProbeOff EQUATE(0).)

This fits the Language Reference: the compiler "reads and parses source/include files by blocks" and "either will skip the text up to terminator or will continue to parse the file – depending on whether you are using OMIT or COMPILE and what condition". Skipping, it searches the text; parsing, it sees strings as strings.

The change: terminatorOnLine(text, terminator, skipping). Skipping: text.includes(terminator). Compiled: the previous outside-strings search. scanConditionalCompile passes whether the block omits, and an undecided block is read as compiled, as it already is for what it contains. OmitCompileDetector tracks only unconditional blocks, so an OMIT is skipped and a COMPILE is compiled. On the directive's own line the same rule is applied to the text after the argument.

Tests: the two "a terminator in a string in code does not close" guard tests you pointed out now assert the skipped rule, next to tests for the compiled one. 8 new tests in ConditionalCompileTerminatorInComment.test.ts: 4 fail on the previous rule and 3 on a plain search everywhere. Four existing tests asserted that a string never closes an OMIT, which the compiler contradicts: the #807 one is flipped, and the two string tests in OmitCompileDetector.test.ts and the #733 read-count test now use a COMPILE, which keeps what they test (the '' escape, the lines read). An OMIT counterpart is added. Server suite: 4569 passing, 3 pending. One SDI disk cache test (a corrupt disk cache degrades to a full scan) timed out under the full run; it passes on its own.

@msarson
msarson merged commit 048e970 into msarson:version-1.0.11 Nov 17, 2026
1 check passed
msarson added a commit that referenced this pull request Nov 17, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@msarson

msarson commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Merged, thanks. You were right about compiled blocks.

I ran your compiled-block cases on both installs here:

  • Clarion 12 (14204): matches your table. COMPILE('*X*',ProbeOn) (or with no condition) followed by s = '*X*' gives OMIT not terminated.
  • Clarion 10 (12567): the same source builds clean, so C10 does close a compiled block on a terminator inside a string. With no terminator at all, it also reports OMIT not terminated.

Skipped blocks and the case-sensitive match behave the same on both versions. Following 11.1 and 12 is the right call; I'm only noting the C10 difference for the record.

The reviewers had two small follow-ups, neither blocking:

  • There are no tests yet for nested blocks (an OMIT inside a compiled COMPILE, and a COMPILE inside a skipped OMIT) or for an undecided COMPILE('*X*',UNKNOWN) with a quoted terminator.
  • In the detector's pass 2, an inner COMPILE inside an outer OMIT is still read with the compiled rule. That gives a phantom fold, but not a wrong omitted range.

— Alice

@geircodes
geircodes deleted the fix/terminator-quoted-in-comment branch November 25, 2026 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants