@@ -6,10 +6,10 @@ Without --name argument, all **OCaml** code blocks are extracted
6
6
7
7
(** By default , an odoc code block is assumed to contain OCaml code * )
8
8
let () = ()
9
- let x = 5
10
- let () = print_int x
9
+ let five = 5
10
+ let () = print_int five
11
11
12
- let y = x + 6 . (* This is a typing error * )
12
+ let y = five +. five (* This is a typing error * )
13
13
14
14
15
15
With -- name argument, language does not matter
@@ -26,14 +26,14 @@ Multiple name can be given
26
26
27
27
$ odoc extract-code -- line-directives -- name error. ml -- name printing main. mld
28
28
# 18 "main.mld"
29
- let x = 5
29
+ let five = 5
30
30
# 20 "main.mld"
31
31
32
- let () = print_int x
32
+ let () = print_int five
33
33
34
34
# 25 "main.mld"
35
35
36
- let y = x + 6 . (* This is a typing error * )
36
+ let y = five +. five (* This is a typing error * )
37
37
38
38
39
39
------ - Line directives -------------------------------------- -
@@ -47,49 +47,49 @@ We can add (OCaml) line directives
47
47
let () = ()
48
48
49
49
# 18 "main.mld"
50
- let x = 5
50
+ let five = 5
51
51
# 20 "main.mld"
52
52
53
- let () = print_int x
53
+ let () = print_int five
54
54
55
55
# 25 "main.mld"
56
56
57
- let y = x + 6 . (* This is a typing error * )
57
+ let y = five +. five (* This is a typing error * )
58
58
59
59
60
60
Let's restrict to a named code blocks
61
61
62
62
$ odoc extract-code -- line-directives -- name error. ml main. mld
63
63
# 18 "main.mld"
64
- let x = 5
64
+ let five = 5
65
65
# 25 "main.mld"
66
66
67
- let y = x + 6 . (* This is a typing error * )
67
+ let y = five +. five (* This is a typing error * )
68
68
69
69
70
70
We can output to a file
71
71
72
72
$ odoc extract-code -- line-directives -- name error. ml -o error. ml main. mld
73
73
$ cat error. ml
74
74
# 18 "main.mld"
75
- let x = 5
75
+ let five = 5
76
76
# 25 "main.mld"
77
77
78
- let y = x + 6 . (* This is a typing error * )
78
+ let y = five +. five (* This is a typing error * )
79
79
80
80
81
81
Let's check line directive work (" -color always" to make sure the error message
82
82
is the same in all context ):
83
83
84
84
$ ocaml -color always error. ml
85
- File " main.mld" , line 26 , characters 15 -17 :
86
- Error: This expression has type float but an expression was expected of type
87
- int
85
+ File " main.mld" , line 26 , characters 11 -15 :
86
+ Error: This expression has type int but an expression was expected of type
87
+ float
88
88
[2 ]
89
89
90
- Here is the line 26 , and the characters 15 -17 :
90
+ Here is the line 26 , and the characters 11 -12 :
91
91
92
92
$ sed -n ' 26p' main. mld
93
- let y = x + 6 . (* This is a typing error * )
94
- $ sed -n ' 26p' main. mld | cut -c15-17
95
- 6 .
93
+ let y = five +. five (* This is a typing error * )
94
+ $ sed -n ' 26p' main. mld | cut -c11-15
95
+ five
0 commit comments