This repository was archived by the owner on Jun 15, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +29
-2
lines changed Expand file tree Collapse file tree 3 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -72,4 +72,4 @@ src/res_scanner.cmi : src/res_token.cmx src/res_diagnostics.cmi
72
72
src/res_token.cmx : src/res_comment.cmx
73
73
tests/res_test.cmx : src/res_token.cmx src/res_parser.cmx \
74
74
src/res_outcome_printer.cmx src/res_multi_printer.cmx src/res_io.cmx \
75
- src/res_driver.cmx
75
+ src/res_driver.cmx src/res_core.cmx
Original file line number Diff line number Diff line change @@ -98,9 +98,12 @@ let _printDebug ~startPos ~endPos scanner token =
98
98
let next scanner =
99
99
let nextOffset = scanner.offset + 1 in
100
100
(match scanner.ch with
101
- | '\n' | '\r' ->
101
+ | '\n' ->
102
102
scanner.lineOffset < - nextOffset;
103
103
scanner.lnum < - scanner.lnum + 1 ;
104
+ (* What about CRLF (\r + \n) on windows?
105
+ * \r\n will always be terminated by a \n
106
+ * -> we can just bump the line count on \n *)
104
107
| _ -> () );
105
108
if nextOffset < String. length scanner.src then (
106
109
scanner.offset < - nextOffset;
Original file line number Diff line number Diff line change @@ -147,8 +147,32 @@ module ParserApiTest = struct
147
147
assert (parser.token = Res_token. Let );
148
148
print_endline " ✅ Parser make: initializes parser and checking offsets"
149
149
150
+ let unixLf () =
151
+ let src = " let x = 1\n let y = 2\n let z = 3" in
152
+ let parser = Res_parser. make src " test.res" in
153
+ (match Res_core. parseImplementation parser with
154
+ | [x; y; z] ->
155
+ assert (x.pstr_loc.loc_start.pos_lnum = 1 );
156
+ assert (y.pstr_loc.loc_start.pos_lnum = 2 );
157
+ assert (z.pstr_loc.loc_start.pos_lnum = 3 )
158
+ | _ -> assert false );
159
+ print_endline " ✅ Parser handles LF correct"
160
+
161
+ let windowsCrlf () =
162
+ let src = " let x = 1\r\n let y = 2\r\n let z = 3" in
163
+ let parser = Res_parser. make src " test.res" in
164
+ (match Res_core. parseImplementation parser with
165
+ | [x; y; z] ->
166
+ assert (x.pstr_loc.loc_start.pos_lnum = 1 );
167
+ assert (y.pstr_loc.loc_start.pos_lnum = 2 );
168
+ assert (z.pstr_loc.loc_start.pos_lnum = 3 )
169
+ | _ -> assert false );
170
+ print_endline " ✅ Parser handles CRLF correct"
171
+
150
172
let run () =
151
173
makeDefault() ;
174
+ unixLf() ;
175
+ windowsCrlf()
152
176
153
177
end
154
178
You can’t perform that action at this time.
0 commit comments