Repository navigation
Accept a UTF-8 byte order mark and end a line at a lone CR - #9120
Conversation
Changelog🐛 Bug fix
Semantic Diff1 commit · Full page Skip a UTF-8 byte order mark and end a line at a lone CR467af56 · cknitt + Claude · Oct 28, 2026, 15:56 UTC
Diagnostic removed (byte order mark) \xEF\xBB\xBFlet x = 1
-Syntax error!
-A.res:1:1
-
-Not sure what to do with this character: "\239".
-… the same for "\187" and "\191"
+noneDiagnostic removed (lone CR) let x = 1 // c\rlet y = 2
-Syntax error!
-B.res:1:10-18
-
-Consecutive statements on a line must be separated by ';' or a newline
+noneFormat modified (lone CR) let x = 1 // c\rlet y = 2
let x = 1 // c
let y = 2Fixes #9108 Review
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## fix-9100-format-line-endings-strings #9120 +/- ##
=====================================================================
Coverage 81.47% 81.47%
=====================================================================
Files 460 460
Lines 64680 64701 +21
=====================================================================
+ Hits 52696 52714 +18
- Misses 11984 11987 +3
🚀 New features to boost your workflow:
|
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Why:
Some Windows editors write a byte order mark, and bsc and bsc -format
rejected it byte by byte. A CR without an LF ended a `//` comment but
did not start a new line, so the next statement counted as on the same
line. The scanner now starts after a byte order mark and ends a line
at a CR not followed by LF, as editors and JavaScript do; code frames
show lines the same way, and the formatter keeps the byte order mark.
Diagnostic removed (byte order mark):
Example:
\xEF\xBB\xBFlet x = 1
Before (diagnostic):
Syntax error!
A.res:1:1
Not sure what to do with this character: "\239".
… the same for "\187" and "\191"
After (diagnostic): none
Diagnostic removed (lone CR):
Example:
let x = 1 // c\rlet y = 2
Before (diagnostic):
Syntax error!
B.res:1:10-18
Consecutive statements on a line must be separated by ';' or a newline
After (diagnostic): none
Format modified (lone CR):
Example:
let x = 1 // c\rlet y = 2
Before (text): Syntax error
After (rescript):
let x = 1 // c
let y = 2
Review: Why convert a CR-only file to LF when formatting? The formatter
writes CRLF when the first line break is CRLF and LF otherwise (#9116);
CR-only files are rare enough not to get their own newline.
Fixes #9108
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Kbf3gGkPma9LAZimuQjnrP
Signed-off-by: Christoph Knittel <[email protected]>
be57a8b to
467af56
Compare
cristianoc
left a comment
There was a problem hiding this comment.
Reviewed BOM handling, lone-CR scanning, diagnostic frames and regression tests against the #9116 base. No blocking issues found. CI, including BOM/lone-CR and syntax tests, passes; not rerun locally.
Some Windows editors save files with a UTF-8 byte order mark, and both
bscandbsc -formatrejected such files with one "Not sure what to do with this character" error per BOM byte. Separately, a\rwithout a following\nended a//comment but did not count as a line break, solet x = 1 // c\rlet y = 2failed with "Consecutive statements on a line must be separated by ';' or a newline".Stacked on #9116 (it touches
Res_multi_printer.printand the analysisformatcommand that #9116 reworks); the base isfix-9100-format-line-endings-strings.The fix:
Res_scanner.byte_order_mark). The first line'spos_bolis the byte offset after the mark, so columns don't count it andpos_cnumremains a byte offset into the source for ASCII text, which the parser relies on (e.g.is_binary_op).bsc -formatand the analysisformatcommand keep a byte order mark.Tests in
tests/syntax_tests/res_test.ml: formatting keeps a BOM (LF and CRLF files) and is idempotent; formatting with a lone CR after a//comment, and a CR-only file; line and column of statements after lone CRs, after\r\r,\n\r, CRLF, and after a BOM; a regex literal with a lone CR is rejected; code frames for a BOM file and a CR-only file. Each assertion group fails with the corresponding part of the fix removed.Open questions:
res_parser -print res(the syntax test tool) does not keep the BOM; onlybsc -formatand the editor's format command do.Fixes #9108
🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gGkPma9LAZimuQjnrP