@@ -6,10 +6,10 @@ Without --name argument, all **OCaml** code blocks are extracted
66
77 (** By default , an odoc code block is assumed to contain OCaml code * )
88 let () = ()
9- let x = 5
10- let () = print_int x
9+ let five = 5
10+ let () = print_int five
1111
12- let y = x + 6 . (* This is a typing error * )
12+ let y = five +. five (* This is a typing error * )
1313
1414
1515With -- name argument, language does not matter
@@ -26,14 +26,14 @@ Multiple name can be given
2626
2727 $ odoc extract-code -- line-directives -- name error. ml -- name printing main. mld
2828 # 18 "main.mld"
29- let x = 5
29+ let five = 5
3030 # 20 "main.mld"
3131
32- let () = print_int x
32+ let () = print_int five
3333
3434 # 25 "main.mld"
3535
36- let y = x + 6 . (* This is a typing error * )
36+ let y = five +. five (* This is a typing error * )
3737
3838
3939------ - Line directives -------------------------------------- -
@@ -47,49 +47,49 @@ We can add (OCaml) line directives
4747 let () = ()
4848
4949 # 18 "main.mld"
50- let x = 5
50+ let five = 5
5151 # 20 "main.mld"
5252
53- let () = print_int x
53+ let () = print_int five
5454
5555 # 25 "main.mld"
5656
57- let y = x + 6 . (* This is a typing error * )
57+ let y = five +. five (* This is a typing error * )
5858
5959
6060Let's restrict to a named code blocks
6161
6262 $ odoc extract-code -- line-directives -- name error. ml main. mld
6363 # 18 "main.mld"
64- let x = 5
64+ let five = 5
6565 # 25 "main.mld"
6666
67- let y = x + 6 . (* This is a typing error * )
67+ let y = five +. five (* This is a typing error * )
6868
6969
7070We can output to a file
7171
7272 $ odoc extract-code -- line-directives -- name error. ml -o error. ml main. mld
7373 $ cat error. ml
7474 # 18 "main.mld"
75- let x = 5
75+ let five = 5
7676 # 25 "main.mld"
7777
78- let y = x + 6 . (* This is a typing error * )
78+ let y = five +. five (* This is a typing error * )
7979
8080
8181Let's check line directive work (" -color always" to make sure the error message
8282is the same in all context ):
8383
8484 $ 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
8888 [2 ]
8989
90- Here is the line 26 , and the characters 15 -17 :
90+ Here is the line 26 , and the characters 11 -12 :
9191
9292 $ 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