Commit d527d7b8 authored by gerd's avatar gerd

Added "include file".


git-svn-id: https://godirepo.camlcity.org/svn/lib-xstrp4/trunk@9 56444827-45db-0310-81c6-95464f7ca4c4
parent 04e9ac02
version = "1.0"
version = "1.1"
requires = "camlp4"
# This line counts when the compiler is invoked with
......
......@@ -48,6 +48,21 @@ let f = 3.14 in
let i = 42 in
print_string interpolate file "sample.file";;
(**********************************************************************)
(* include file *)
(**********************************************************************)
(* include file "filename":
* expands to the contents of the file but _no_ brace expansion is performed.
* If "filename" is written without "/", it is always searched in the
* same directory as the source file being compiled. Otherwise "filename"
* is interpreted as relative or absolute path name.
*
* IMPORTANT NOTE: Of course, the file is only read during compile time.
*)
print_string "sample.file: ";
print_string include file "sample.file";;
(**********************************************************************)
(* <:here< quotations>> *)
......
(* $Id: xstrp4_here.ml,v 1.1 1999/07/18 16:42:38 gerd Exp $
(* $Id: xstrp4_here.ml,v 1.2 2001/04/21 16:53:15 gerd Exp $
* ----------------------------------------------------------------------
*
*)
......@@ -95,6 +95,23 @@ let interpolated_file filename =
;;
let included_file filename =
let pathname =
if Filename.is_implicit filename then
Filename.concat (Filename.dirname !input_file) filename
else
filename
in
let f = open_in pathname in
let n = in_channel_length f in
let s = String.create n in
really_input f s 0 n;
close_in f;
let loc = (0, String.length s) in
<:expr< $str:s$ >>
;;
let here_pat s =
failwith "<<:here< >> documents not allowed in patterns"
;;
......@@ -103,7 +120,9 @@ let here_pat s =
EXTEND
expr: AFTER "simple"
[[ "interpolate"; "file"; s = STRING -> interpolated_file s
| "interpolate"; s = STRING -> interpolated_expr s ]];
| "interpolate"; s = STRING -> interpolated_expr s
| "include"; "file"; s = STRING -> included_file s
]];
END
;;
......@@ -118,6 +137,9 @@ Quotation.add
* History:
*
* $Log: xstrp4_here.ml,v $
* Revision 1.2 2001/04/21 16:53:15 gerd
* Added "include file".
*
* Revision 1.1 1999/07/18 16:42:38 gerd
* Initial revision.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment