forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.ml
62 lines (54 loc) · 997 Bytes
/
driver.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#directory "+compiler-libs";;
#load "ocamlcommon.cma";;
#mod_use "/Users/hzhang295/git/ocaml-wk/parsing/lexer.ml";;
let d token lexbuf =
let c = ref [] in
try
while true do
let t = token lexbuf in
if t <> Parser.EOF then
c := t :: !c
else raise End_of_file
done;
!c
with
| End_of_file -> List.rev !c
| Lexer.Error(e,loc) ->
Format.fprintf Format.err_formatter
"@[%a : %a @]@."
Lexer.report_error e Location.print loc ;
List.rev !c ;;
let f str =
Lexer.init () ;
d (fun lexbuf -> Lexer.token lexbuf )
(Lexing.from_string str) ;;
f {|
#if ocaml_major > 3 && ocaml_minor > 1
1 + 2
#else
32
#end
|}
;; f {|
#if ocaml_major > 3 && ocaml_minor > 10
1 + 2
#end
|}
;; f {|
#if ocaml_major > 3 && ocaml_minor > 1
1 + 2
#end
|}
;; f {|
#if ocaml_major > 3 && ocaml_minor > 1
1 + 2
#else
#end
|}
;; f {|
#if ocaml_major > 3 && ocaml_minor > 1
1 + 2
#else
#if
#end
|}