Skip to content

Commit b701fa5

Browse files
committed
Reimplement use for importing files
1 parent c6e3c64 commit b701fa5

File tree

5 files changed

+23
-17
lines changed

5 files changed

+23
-17
lines changed

examples/syntax.sg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,4 @@
113113
(== test ok)
114114

115115
'import file
116-
'(use examples automata)
116+
'(use "examples/automata.sg")

src/expr.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ let rec sgen_expr_of_expr (e : expr) : sgen_expr =
172172
(* linear exec *)
173173
| List [ Symbol k; g ] when equal_string k "linexec" ->
174174
Exec (true, sgen_expr_of_expr g)
175-
(* linear exec *)
175+
(* eval *)
176176
| List [ Symbol k; g ] when equal_string k "eval" ->
177177
Eval (sgen_expr_of_expr g)
178178
(* KEEP LAST -- raw constellation *)
@@ -204,6 +204,8 @@ let decl_of_expr : expr -> declaration = function
204204
Expect (ray_of_expr x, sgen_expr_of_expr g, const "default")
205205
| List [ Symbol k; x; g; m ] when equal_string k expect_op ->
206206
Expect (ray_of_expr x, sgen_expr_of_expr g, ray_of_expr m)
207+
(* use *)
208+
| List [ Symbol k; r ] when equal_string k "use" -> Use (ray_of_expr r)
207209
| _ -> failwith "error: invalid declaration"
208210

209211
let program_of_expr = List.map ~f:decl_of_expr

src/lexer.ml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,20 @@ and string_literal lexbuf =
5454
match%sedlex lexbuf with
5555
| '"' -> STRING (Buffer.contents buffer)
5656
| '\\', any ->
57-
let escaped =
58-
match%sedlex lexbuf with
59-
| 'n' -> '\n'
60-
| 't' -> '\t'
61-
| '\\' -> '\\'
62-
| '"' -> '"'
63-
| _ -> failwith "Unknown escape sequence"
64-
in
65-
Buffer.add_char buffer escaped;
66-
loop ()
57+
let escaped =
58+
match%sedlex lexbuf with
59+
| 'n' -> '\n'
60+
| 't' -> '\t'
61+
| '\\' -> '\\'
62+
| '"' -> '"'
63+
| _ -> failwith "Unknown escape sequence"
64+
in
65+
Buffer.add_char buffer escaped;
66+
loop ()
6767
| eof -> failwith "Unterminated string literal"
6868
| any ->
69-
Buffer.add_string buffer (Sedlexing.Utf8.lexeme lexbuf);
70-
loop ()
69+
Buffer.add_string buffer (Sedlexing.Utf8.lexeme lexbuf);
70+
loop ()
7171
| _ -> failwith "Invalid character in string literal"
7272
in
7373
loop ()

src/sgen_ast.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ type declaration =
4040
| Trace of sgen_expr
4141
| Run of sgen_expr
4242
| Expect of ident * sgen_expr * ident
43-
| Use of ident list
43+
| Use of ident
4444

4545
type program = declaration list

src/sgen_eval.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,12 @@ let rec eval_decl ~typecheckonly ~notyping env :
238238
Error (ExpectError (eval_x, eval_e, message))
239239
else Ok env
240240
| Use path ->
241-
let path = List.map path ~f:string_of_ray in
242-
let formatted_filename = String.concat ~sep:"/" path ^ ".sg" in
241+
let open Lsc_ast.StellarRays in
242+
let formatted_filename : string =
243+
match path with
244+
| Func ((Null, f), [ s ]) when equal_string f "%string" -> string_of_ray s
245+
| path -> string_of_ray path ^ ".sg"
246+
in
243247
let lexbuf =
244248
Sedlexing.Utf8.from_channel (Stdlib.open_in formatted_filename)
245249
in

0 commit comments

Comments
 (0)