Repository navigation
fix(tokenizer): A statement starting with a variable called Data no longer ends the CODE section - #861
Merged
msarson merged 1 commit intoNov 17, 2026
Conversation
…s in CODE codeSectionSetBy took any line beginning with the word DATA for the routine DATA header, so `data = ''` in a procedure body left the CODE section for the rest of the procedure. Every LOOP and IF after it lost its structure token (LOOP read as `OOP`, IF as `F`), and each BREAK or CYCLE in such a LOOP was warned as used outside a LOOP or ACCEPT. The DATA header now counts only alone on its line, like CODE: the rule msarson#855 applied in DocumentStructure, applied to the tokenizer's section state. ROUTINE is unchanged; it is reserved and cannot name a variable. Test: ControlFlowDiagnostics.DataVariableStatement, 12 of 14 failing before the fix, 14/14 after. Server suite 4565 passing, 3 pending. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A statement starting with a variable called Data no longer ends the CODE section
What happened
A procedure that assigns a variable called
Dataat the start of a statement got false'BREAK' used outside of a LOOP or ACCEPT structure.warnings (and the same for CYCLE) on every BREAK/CYCLE in any LOOP after that line:The same happens after
Data = 'x',Data.Field = 'x',Data[1] = 'x'anddata &= NULL, and with a local declaredData STRING(520). In the real class this came from, two methods gave 7 warnings, and across a 153-file solution 10 warnings in 3 files, none of them real.The warnings are the visible part. The token stream after that line is wrong:
LOOPis tokenized as the variableOOPandIFasF, so folding, END matching and anything else that reads the structure tokens is off for the rest of the procedure.Root cause
ClarionTokenizer.codeSectionSetBydecides when the tokenizer is inside a CODE section, and took any line starting with the word DATA for the routine's DATA header:data = ''matches, soinCodeSectiongoes false until the next CODE or PROCEDURE line. Outside CODE the Structure pattern skips execution structures (if (!inCodeSection && isExecutionStructure) continue;), the Variable pattern excludes structure keywords, and the next match starts one character in:OOP,F. The LOOP never gets afinishesAt, sovalidateCycleBreakOutsideLoopfinds no loop range around the BREAK.This is the tokenizer side of #855: that fix made
DocumentStructureaccept CODE/DATA as the statement only when nothing but a comment follows it (isBareExecutionMarker), and #618 guarded the outline's own DATA check, whose commit notes the same stray leadingF. Neither reachescodeSectionSetBy, which the tokenizer andTokenCache(codeSectionAt,isStructureAffectingEdit) read.Fix
The DATA header counts only alone on its line, optionally followed by a comment, the same form as the CODE check just above it and as the routine-local scan (
/^\s*data\s*(!.*)?$/i):Datais a legal label for a procedure-local variable and a parameter: #855 compiler-verified it on Clarion 10 and 12, and the class this was found in compiles on Clarion 11.1 with both a parameter nameddataand a localData STRING(520).Testing
New
server/src/test/ControlFlowDiagnostics.DataVariableStatement.test.ts(14 tests), run through the production path (tokenizer +DocumentStructure.process()):data = '',Data = 'x',DATA = 'x' ! comment,data=1,Data.Field = 'x',Data[1] = 'x',data &= NULL.finishesAtare identical to the same procedure withx = ''in place ofdata = '', and no keyword loses its first character.Data STRING(520)and assigned in CODE.data = ''is still flagged, and only that one. Before the fix, the CYCLE inside the LOOP was flagged as well.DATAsection (bare, upper and lower case, with a trailing comment) still opens, its local is still a variable, and its LOOP still owns its BREAK.codeSectionSetByunit cases: the header forms returnfalse(including a trailing\r), the statement forms returnundefined.Red before the fix: 12 of 14 failing (the two ROUTINE/header guards pass on both sides). 14/14 after. Server suite: 4565 passing, 3 pending.
Corpus check over a 153-file real-world solution, old build against new: the token stream changed in 5 files, every one of them containing a statement that starts with
data, and in no other file. The BREAK/CYCLE warnings went from 10 to 0. All 15 real routineDATAheaders in that corpus are in the strict form.Scope
ROUTINEkeeps its current check. It is a reserved word, so no variable can start a statement with it.ExecutionMarkertoken pattern (/\b(?:CODE|DATA)\b/iinTokenPatterns.ts) still emitsdataindata = ''as an ExecutionMarker token.DocumentStructure(Field labelled Code or Data is read as the CODE/DATA marker (false 'is not a field' on PROJECT) #855) and the outline (Outline lists CODE-section expressions as data ("Loc:Flag AND01") after a statement that starts withDATAor with a prefixed name ending in:Data(v1.0.5) #618) already ignore it there, so it no longer changes any section state. Narrowing the token itself would change what consumers and highlighting receive, so I left it out of this fix.🤖 Generated with Claude Code