Skip to content

Commit

Permalink
Diff parser: add old_mode/new_mode
Browse files Browse the repository at this point in the history
Signed-off-by: Kakadu <kakadu@pm.me>
  • Loading branch information
Kakadu committed Jan 15, 2024
1 parent 816cef2 commit 2f2a79d
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 2 deletions.
2 changes: 2 additions & 0 deletions review/diff_parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ let file_head : _ option parser =
; Line_parser.(run ~info:"rename" rename)
; Line_parser.(run ~info:"index" index)
; Line_parser.(run ~info:"binary files differ" binary_files_differ)
; Line_parser.(run ~info:"old_mode" old_mode)
; Line_parser.(run ~info:"new_mode" new_mode)
])
*> return ()
in
Expand Down
7 changes: 6 additions & 1 deletion review/dune
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
(synopsis "Parser for diff file format")
(modules types line_parser diff_parser)
(wrapped false)
(libraries angstrom)
(libraries
angstrom
;ppx_show.runtime
)
; (preprocess
; (pps ppx_show))
(instrumentation
(backend bisect_ppx)))

Expand Down
10 changes: 10 additions & 0 deletions review/line_parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ let binary_files_differ : unit parser =
many any_char *> return ()
;;

let old_mode : unit parser =
let* _ = string "old mode" <?> "old mode" in
many any_char *> return ()
;;

let new_mode : unit parser =
let* _ = string "new mode" <?> "new mode" in
many any_char *> return ()
;;

let remove_file : string parser =
let* _ = string "--- " in
let* _ = string "a/" <|> return "" in
Expand Down
2 changes: 2 additions & 0 deletions review/line_parser.mli
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ val similarity : unit Angstrom.t
val rename : unit Angstrom.t
val index : unit Angstrom.t
val binary_files_differ : unit Angstrom.t
val old_mode : unit Angstrom.t
val new_mode : unit Angstrom.t
val remove_file : string Angstrom.t
val add_file : string Angstrom.t
val pos_num : int Angstrom.t
Expand Down
11 changes: 10 additions & 1 deletion review/parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,16 @@ let () =
in
match Diff_parser.parse_string input with
| Result.Ok parsed ->
(* Format.printf "Parsed stuff:@[%a@]\n%!" [%show: Types.file_info list] parsed; *)
(* Format.printf
"Parsed stuff:@[%a@]\n%!"
(Format.pp_print_list (fun ppf { Types.old_file; new_file; chunks } ->
Format.fprintf
ppf
"@['%s -> %s with %d chunks'@]"
old_file
new_file
(List.length chunks)))
parsed; *)
(match cfg with
| { file = Some file; line = Some line } ->
(match Diff_parser.lookup parsed ~file ~line with
Expand Down
104 changes: 104 additions & 0 deletions review_tests/112.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
diff --git a/Lua/.gitignore b/Lua/.gitignore
index 7102a822..a18e0840 100644
--- a/Lua/.gitignore
+++ b/Lua/.gitignore
@@ -1,6 +1,29 @@
-_build
-_coverage
-/_esy
-/node_modules
-/esy.lock
-/.melange.eobjs
+*.annot
+*.cmo
+*.cma
+*.cmi
+*.a
+*.o
+*.cmx
+*.cmxs
+*.cmxa
+
+# ocamlbuild working directory
+_build/
+
+# ocamlbuild targets
+*.byte
+*.native
+
+# oasis generated files
+setup.data
+setup.log
+
+# Merlin configuring file for Vim and Emacs
+.merlin
+
+# Dune generated files
+*.install
+
+# Local OPAM switch
+_opam/
diff --git a/Lua/.ocamlformat b/Lua/.ocamlformat
old mode 100644
new mode 100755
index a7138292..5e2215c2
--- a/Lua/.ocamlformat
+++ b/Lua/.ocamlformat
@@ -1,4 +1,3 @@
profile=janestreet
sequence-style=terminator
max-indent=2
-
diff --git a/Lua/DONT_REMOVE_THIS_DIRECTORY.md b/Lua/DONT_REMOVE_THIS_DIRECTORY.md
deleted file mode 100644
index e0530079..00000000
--- a/Lua/DONT_REMOVE_THIS_DIRECTORY.md
+++ /dev/null
@@ -1,3 +0,0 @@
-This file should be contained in template directoty `Lambda`.
-You should remove it when you copy `Lambda` for your
-personal pet project.
diff --git a/Lua/Lambda.opam b/Lua/Lambda.opam
deleted file mode 100644
index 1bd9c9da..00000000
--- a/Lua/Lambda.opam
+++ /dev/null
@@ -1,35 +0,0 @@
-# This file is generated by dune, edit dune-project instead
-opam-version: "2.0"
-version: "0.1"
-synopsis: "FIXME An interpreter for language"
-description:
- "FIXME. A longer description, for example, which are the most interesing features being supported, etc."
-maintainer: ["FIXME Vasya Pupkin"]
-authors: ["FIXME Vasya Pupkin"]
-license: "LGPL-3.0-or-later"
-homepage: "FIXME Homepage"
-bug-reports: "FIXME where to put bug reports about the code"
-depends: [
- "dune" {>= "3.7"}
- "angstrom"
- "ppx_inline_test" {with-test}
- "ppx_expect"
- "ppx_deriving"
- "bisect_ppx"
- "odoc" {with-doc}
- "ocamlformat" {build}
-]
-build: [
- ["dune" "subst"] {dev}
- [
- "dune"
- "build"
- "-p"
- name
- "-j"
- jobs
- "@install"
- "@runtest" {with-test}
- "@doc" {with-doc}
- ]
-]
diff --git a/Lua/Lua.opam b/Lua/Lua.opam
new file mode 100644
index 00000000..91e21ac9
3 changes: 3 additions & 0 deletions review_tests/112.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$ cat 112.diff | ../review/parser.exe - -f Lua/.gitignore -l 14 #-vdp -vlp
Got something. It should be at 20 lines below from the first chunk header of file in diff

4 changes: 4 additions & 0 deletions review_tests/dune
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@
(cram
(applies_to 40)
(deps 40.diff))

(cram
(applies_to 112)
(deps 112.diff))

0 comments on commit 2f2a79d

Please sign in to comment.