Skip to content

Commit

Permalink
attempt to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Destaq committed May 15, 2024
1 parent f13c0c8 commit f1d7dbc
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,25 @@ let replace_all str old_substring new_substring =
in
replace_helper str old_substring new_substring 0

(*Helper function to ensure that tests pass on ci/cd.*)
let ends_with ~suffix s =
let len_s = String.length s and len_suf = String.length suffix in
let diff = len_s - len_suf in
let rec aux i =
if i = len_suf then true
else if String.unsafe_get s (diff + i) <> String.unsafe_get suffix i then
false
else aux (i + 1)
in
diff >= 0 && aux 0

(**Group and merge tokens based on quotations.*)
let rec quote_grouping acc cur_group in_group tokens =
match tokens with
| [] -> List.rev acc
| h :: t ->
if in_group then
if String.ends_with ~suffix:"\"" h then
if ends_with ~suffix:"\"" h then
quote_grouping
((cur_group ^ " " ^ replace_all h "\"" "") :: acc)
"" false t
Expand All @@ -65,8 +77,7 @@ let rec quote_grouping acc cur_group in_group tokens =
(cur_group ^ " " ^ replace_all h "\"" "")
in_group t
else if
String.starts_with ~prefix:"\"" h
&& not (String.ends_with ~suffix:"\"" h)
String.starts_with ~prefix:"\"" h && not (ends_with ~suffix:"\"" h)
then quote_grouping acc (replace_all h "\"" "") true t
else quote_grouping (replace_all h "\"" "" :: acc) cur_group in_group t

Expand Down

0 comments on commit f1d7dbc

Please sign in to comment.