Skip to content

Continue a line comment over a trailing underscore - #5

Open
MarioRial22 wants to merge 2 commits into
scriptandcompile:masterfrom
seguridadea1:comment-continuation
Open

Continue a line comment over a trailing underscore#5
MarioRial22 wants to merge 2 commits into
scriptandcompile:masterfrom
seguridadea1:comment-continuation

Conversation

@MarioRial22

Copy link
Copy Markdown

A comment ending in a space and an underscore continues onto the next line, the same way any other logical line does. The lexer stopped at the newline, so that next line was tokenized as code.

'LOS PUNTOS DE PROYECTO TIENEN EN CUENTA LAS LINEAS DE HORAS DONDE COINCIDAN _
 S/NºPROYECTO Y DEPARTAMENTO DE LA CABECERA DEL PARTE ACTUAL

The second line has no ' of its own, so it was read as code. Two consequences:

  • Prose becomes identifiers. Any non-ASCII character in it reaches the tokenizer fallback and is reported as an unknown token. On the code base I tested this on, 307 lines are continuations of a comment, and they produced 651 spurious findings — all accented vowels from Spanish prose.
  • Commented-out code is parsed as live code. test-data already contains a case: in environment/ExifRead.cls, '.Value = _ is followed by a call that was being parsed as a real CallStatement.

The fix

Keep taking lines while the one just taken ends in a continuation, and emit the run as a single comment token.

Two limits, and I want to flag that each was found by one of your own snapshots, not by me:

  • The space before the _ is required. 'm_oSocket.Close_ is an identifier ending in an underscore, not a continuation. environment_ctlsclient1 caught my first version, which got this wrong.
  • A continuation line that opens its own comment stays its own token. Nothing is misread there, so there is no reason to change the tokenization of source that already worked. environment_cregistry caught this.

Snapshot change

environment_exifread is regenerated, and it is the one deliberate behaviour change here: the commented-out call described above now sits inside the comment token where it belongs. That is the point of the PR rather than a side effect, so I would rather call it out than have it noticed in review.

Tests

Seven in lexer::tests: continuation onto plain text, over several lines in a row, with trailing whitespace after the _, the no-continuation case, an underscore without a leading space, a continuation onto another comment, and the same for REM.

cargo test -p vb6parse: 5656 pass. The eight class_load failures are the pre-existing ones with no committed .snap baseline (five audiostation, three cdiu_beat_up_editor); they fail identically on an unmodified master here.

Independent of #2 and #4 — touches only the comment path in the lexer.

Mario Rial added 2 commits August 13, 2026 07:27
VB6 continues a logical line with a space followed by an underscore, and a
comment is a logical line: the text on the next line is still comment, even
though it does not start with its own `'`. The lexer stopped at the newline,
so that next line was tokenized as code.

Two things fall out of that. Prose from a comment becomes identifiers, and
any character in it that is not ASCII reaches the tokenizer's fallback and is
reported as an unknown token -- on the code base I tried this on, 307 lines
are continuations of a comment and they accounted for 651 spurious findings,
all of them accented vowels from Spanish prose. Worse, commented-out code is
parsed as real code: test-data has a case where `'.Value = _` is followed by
a call that was being analyzed as though it were live.

Keep taking lines while the one just taken ends in a continuation, and emit
the run as a single comment token. Two limits, each pinned down by one of
their own snapshots:

- The space before the `_` is required. `Close_` at the end of a line is an
  identifier ending in an underscore, not a continuation. The
  environment_ctlsclient1 snapshot caught this.
- A continuation line that opens its own comment is left as its own token.
  Nothing is misread there, so there is no reason to change how source that
  already worked is tokenized. environment_cregistry caught this one.

environment_exifread is regenerated: it holds the commented-out call
described above, which now sits inside the comment token where it belongs.
REM comments go through the same path and get the same treatment.
The check for a `REM` on the continuation line used `line[..4]`, which
panics when the line begins with a multi-byte character -- exactly what a
continuation line holding Spanish prose does:

    end byte index 4 is not a char boundary; it is inside 'á'

Found by running the built binary over a real code base rather than only the
test suite. `str::get` returns `None` at a non-boundary instead.
@MarioRial22

Copy link
Copy Markdown
Author

Correction to what I wrote above about the eight failing class_load snapshot tests. I said they fail because there is no committed .snap baseline. That is wrong — the baselines are committed, and the failures are an artefact of my machine, not of this repo.

The cause is line endings. The test-data blobs hold LF; this Windows checkout had core.autocrlf=true globally, so they materialised as CRLF, and the snapshots — generated from LF — no longer match. Every diff is text: "\n" against text: "\r\n" and nothing else.

So: those eight are green in your CI, they are unrelated to this PR, and there is nothing here for you to fix. I should have looked at the diff before explaining it rather than after.

The one thing that might be worth having is a note for contributors on Windows to set core.autocrlf=false, since .gitattributes in the superproject does not reach submodule checkouts. Happy to send that separately if you want it.

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.

1 participant