Skip to content

Commit

Permalink
Robust template parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
rvantonder committed May 30, 2019
1 parent eabf75d commit f49513f
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 331 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
_build
*.install
/dune-project
\#*
.\#*
45 changes: 17 additions & 28 deletions src/command_configuration.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,30 @@ open Core

open Language

let read = Fn.compose String.rstrip In_channel.read_all

let read_template =
Fn.compose
String.chop_suffix_exn ~suffix:"\n"
In_channel.read_all
let read filename =
In_channel.read_all filename
|> fun template ->
String.chop_suffix template ~suffix:"\n"
|> Option.value ~default:template

let parse_specification_directories match_only specification_directory_paths =
let parse_directory path =
let match_template =
let filename = path ^/ "match" in
try read_template filename
with _ -> failwith (Format.sprintf "Could not read required match file %s" filename)
in
let match_rule =
let filename = path ^/ "match_rule" in
try Some (read filename)
with _ -> None
match read filename with
| content -> content
| exception _ ->
Format.eprintf "Could not read required match file %s@." filename;
exit 1
in
let rewrite_template =
let filename = path ^/ "rewrite" in
if match_only then
None
else
try Some (read_template filename)
with _ -> None
in
let rewrite_rule =
let filename = path ^/ "rewrite_rule" in
if match_only then
None
else
try Some (read filename)
with _ -> None
let read_optional filename =
match read filename with
| content -> Some content
| exception _ -> None
in
let match_rule = read_optional (path ^/ "match_rule") in
let rewrite_template = read_optional (path ^/ "rewrite") in
let rewrite_rule = if match_only then None else read_optional (path ^/ "rewrite_rule") in
Specification.create ~match_template ?match_rule ?rewrite_template ?rewrite_rule ()
in
List.map specification_directory_paths ~f:parse_directory
Expand Down
300 changes: 0 additions & 300 deletions test/#test_cli.ml#

This file was deleted.

4 changes: 4 additions & 0 deletions test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@
cohttp-lwt-unix
core
camlzip))

(alias
(name runtest)
(deps (source_tree example)))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:[1]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
where true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:[1]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:[1]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
where true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:[1]
Loading

0 comments on commit f49513f

Please sign in to comment.