Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/parser/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ let trim_leading_whitespace : string -> string = fun s ->
let count_leading_whitespace : string -> int = fun line ->
let rec count_leading_whitespace' : int -> int = fun index ->
if index >= String.length line then
index
(* Ignore empty and whitespace-only lines. *)
max_int
else
match line.[index] with
| ' ' | '\t' -> count_leading_whitespace' (index + 1)
Expand All @@ -92,10 +93,13 @@ let trim_leading_whitespace : string -> string = fun s ->
|> List.fold_left min max_int
in
let remove_whitespace : string -> string = fun line ->
String.sub
if String.length line < least_amount_of_whitespace then
line
least_amount_of_whitespace
(String.length line - least_amount_of_whitespace)
else
String.sub
line
least_amount_of_whitespace
(String.length line - least_amount_of_whitespace)
in
lines
|> List.map remove_whitespace
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
((output (ok (((f.ml (1 0) (3 6)) (code_block "foo\
\n\
\nbar")))))
(warnings ()))
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
((output (ok (((f.ml (1 0) (3 6)) (code_block "foo\
\n \
\nbar")))))
(warnings ()))
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
((output (ok (((f.ml (1 0) (3 7)) (code_block "foo\
\n \
\nbar")))))
(warnings ()))
3 changes: 3 additions & 0 deletions test/parser/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ let tests : test_suite list = [
t "leading-whitespace-two-cr-lf" "{[ foo\r\n bar]}";
t "leading-whitespace-two-different-indent" "{[ foo\n bar]}";
t "leading-whitespace-two-different-indent-rev" "{[ foo\n bar]}";
t "leading-whitespace-with-empty-line" "{[ foo\n\n bar]}";
t "leading-whitespace-with-whitespace-line-short" "{[ foo\n \n bar]}";
t "leading-whitespace-with-whitespace-line-long" "{[ foo\n \n bar]}";
t "leading-tab" "{[\tfoo]}";
t "leading-tab-two" "{[\tfoo\n\tbar]}";
t "leading-tab-two-different-indent" "{[\tfoo\n\t\tbar]}";
Expand Down