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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
(** Common to lus2lic and lic2loc *)
let new_line ( lexbuf ) = (
Lv6MainArgs.global_opt.Lv6MainArgs.line_start_pos <- Lexing.lexeme_end lexbuf;
Lv6MainArgs.global_opt.Lv6MainArgs.line_num <- Lv6MainArgs.global_opt.Lv6MainArgs.line_num +1;
()
)
type pragma = Pragma of string * string
type t = {
_file : string ;
_str : string ;
_line : int ;
_cstart : int ;
_cend : int;
_pragma : pragma list
}
let str x = (x._str)
let id x = (Lv6Id.of_string x._str)
let line x = (x._line)
let cstart x = (x._cstart)
let cend x = (x._cend)
let file x = x._file
let pragma x = x._pragma
let details lxm = (
let file = if Lv6MainArgs.global_opt.Lv6MainArgs.nonreg_test then
Filename.basename lxm._file
else
lxm._file
in
Printf.sprintf "in file \"%s\", line %d, col %d to %d, token '%s'"
file lxm._line lxm._cstart lxm._cend lxm._str
)
let short_details lxm = (
let file = Filename.basename lxm._file in
Printf.sprintf "f:%s, l:%d, c:%d-%d, t:'%s'"
file lxm._line lxm._cstart lxm._cend lxm._str
)
let position lxm = (
Printf.sprintf "line:%d, col:%d to %d"
lxm._line lxm._cstart lxm._cend
)
let (override_name : string -> t -> t) =
fun nname lxm ->
{ lxm with _str=nname }
type 'a srcflagged = {
src : t ;
it : 'a
}
let (flagit : 'a -> t -> 'a srcflagged) =
fun x lxm ->
{ it = x; src = lxm }
let dummy str =
{
_str = str ;
_file = "dummy";
_line = 0 ;
_cstart = 0 ;
_cend = 0 ;
_pragma = []
}
let last_lexeme = ref (dummy "")
open Lv6MainArgs
let make ( lexbuf ) = (
let s = (Lexing.lexeme lexbuf) in
let l = global_opt.line_num in
let c1 = (Lexing.lexeme_start lexbuf - global_opt.line_start_pos) in
let c2 = (Lexing.lexeme_end lexbuf - global_opt.line_start_pos - 1) in
last_lexeme :=
{ _str = s ;
_file = global_opt.current_file;
_line = l;
_cstart = c1 ;
_cend = c2 ;
_pragma = []
};
!last_lexeme
)
let add_pragma lxm pl = { lxm with _pragma = pl }
let make_string ( lexbuf ) =
let lxm = make lexbuf in
{ lxm with _str = String.sub lxm._str 1 ((String.length lxm._str)-2) }
let last_made () = !last_lexeme