Skip to content

Commit 01daa94

Browse files
committed
feature: annotation in the dependencies
1 parent 177f0ff commit 01daa94

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

src/grader/grading.ml

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,33 @@ let get_grade
156156
match Filename.extension path with
157157
| ".mli" -> load_dependencies ((modname,content) :: signatures) fs
158158
| ".ml" ->
159+
let included,content =
160+
(* the first line of an .ml file can contain an annotation *)
161+
(* @included which denotes that this file has to be included *)
162+
(* directly in the toplevel environment, and not in an module. *)
163+
match String.index_opt content '\n' with
164+
| None -> (false,content)
165+
| Some i ->
166+
(match String.trim (String.sub content 0 i) with
167+
| "@included" ->
168+
let content' = String.sub content i @@
169+
(String.length content - i)
170+
in (true,content')
171+
| _ -> (false,content))
172+
in
159173
(handle_error (internal_error [%i"while loading user dependencies"]) @@
160-
let use_mod =
161-
Toploop_ext.use_mod_string ~print_outcome ~ppf_answer ~modname in
162-
match List.assoc_opt modname signatures with
163-
| Some sig_code -> use_mod ~sig_code content
164-
| None -> use_mod content);
165-
load_dependencies signatures fs
174+
match included with
175+
| true -> Toploop_ext.use_string ~print_outcome ~ppf_answer
176+
~filename:(Filename.basename path) content
177+
| false ->
178+
let use_mod =
179+
Toploop_ext.use_mod_string ~print_outcome ~ppf_answer ~modname in
180+
match List.assoc_opt modname signatures with
181+
| Some sig_code -> use_mod ~sig_code content
182+
| None -> use_mod content);
183+
load_dependencies signatures fs
166184
| _ -> failwith ("uninterpreted dependency \"" ^ path ^
167-
"\".file extension expected : .ml or .mli") in
185+
"\", file extension expected : .ml or .mli") in
168186
load_dependencies [] files
169187
in
170188

src/repo/learnocaml_exercise.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,8 @@ module File = struct
210210
| None -> line
211211
| Some index -> String.sub line 0 index in
212212
let lines = String.split_on_char '\n' txt in
213-
List.filter (function "" -> false | _ -> true) @@
214-
List.map (fun line -> String.trim @@
215-
remove_comment ~start:'#' @@
216-
remove_comment ~start:';' line) lines
213+
List.filter ((<>) "") @@
214+
List.map (fun line -> String.trim (remove_comment ~start:'#' line)) lines
217215

218216
let dependencies = function
219217
| None -> []

0 commit comments

Comments
 (0)