Skip to content

Commit

Permalink
bring comment parser in sync with alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
rvantonder committed Jan 4, 2020
1 parent f3e0cec commit 9a7b398
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
28 changes: 20 additions & 8 deletions lib/parsers/comments.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,30 @@ module Omega = struct
let (|>>) p f =
p >>= fun x -> return (f x)

let between left _right p =
left *> p (*<* right*)
let any_char_except ~reserved =
List.fold reserved
~init:(return `OK)
~f:(fun acc reserved_sequence ->
option `End_of_input
(peek_string (String.length reserved_sequence)
>>= fun s ->
if s = reserved_sequence then
return `Reserved_sequence
else
acc))
>>= function
| `OK -> any_char
| `End_of_input -> any_char
| `Reserved_sequence -> fail "reserved sequence hit"

let between left right p =
left *> p <* right

let to_string from until between : string =
from ^ (String.of_char_list between) ^ until

let anything_including_newlines ~until =
(* until is not consumed in Alpha. Angstrom consumes it. It needs to not
consume because we're doing that for 'between'; but now between is
changed to not expect it. The point is: it does the right thing but
diverges from Alpha and is a little bit... weird *)
(many_till any_char (string until))
many (any_char_except ~reserved:[until])

let anything_excluding_newlines () =
anything_including_newlines ~until:"\n"
Expand Down Expand Up @@ -45,7 +57,7 @@ module Omega = struct
shouldn't need to reintroduce it.*)
let until_newline start =
(string start *> anything_excluding_newlines ()
|>> fun l -> start^(String.of_char_list l)^"\n")
|>> fun l -> start^(String.of_char_list l))

module Until_newline = struct
module type S = sig
Expand Down
2 changes: 0 additions & 2 deletions test/omega/test_cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,6 @@ let%expect_test "matcher_override" =
print_string result;
[%expect{| |}]

(* 2.
let%expect_test "infer_and_honor_extensions" =
let source = "doesn't matter" in
let src_dir = "example" ^/ "src" ^/ "honor-file-extensions" in
Expand Down Expand Up @@ -697,7 +696,6 @@ let%expect_test "infer_and_honor_extensions" =
}

WARNING: the GENERIC matcher was used, because a language could not be inferred from the file extension(s). The GENERIC matcher may miss matches. See '-list' to set a matcher for a specific language and to remove this warning. |}]
*)

let%expect_test "diff_only" =
let source = "hello world" in
Expand Down

0 comments on commit 9a7b398

Please sign in to comment.