@@ -24,6 +24,13 @@ let has_comments = ref false
24
24
25
25
let lexer_error message =
26
26
failwith (Printf. sprintf " Tsl lexer: %s" message)
27
+
28
+ let lexer_error_at pos message =
29
+ let file = pos.Lexing. pos_fname in
30
+ let line = pos.Lexing. pos_lnum in
31
+ let column = pos.Lexing. pos_cnum - pos.Lexing. pos_bol in
32
+ let message = Printf. sprintf " %s:%d:%d: %s" file line column message in
33
+ lexer_error message
27
34
}
28
35
29
36
let newline = ('\013' * '\010' )
@@ -86,12 +93,7 @@ and token = parse
86
93
| _
87
94
{
88
95
let pos = Lexing. lexeme_start_p lexbuf in
89
- let file = pos.Lexing. pos_fname in
90
- let line = pos.Lexing. pos_lnum in
91
- let column = pos.Lexing. pos_cnum - pos.Lexing. pos_bol in
92
- let message = Printf. sprintf " %s:%d:%d: unexpected character %s"
93
- file line column (Lexing. lexeme lexbuf) in
94
- lexer_error message
96
+ lexer_error_at pos (" unexpected character %s" ^ Lexing. lexeme lexbuf)
95
97
}
96
98
| eof
97
99
{ lexer_error " unexpected eof" }
@@ -117,6 +119,8 @@ and string acc = parse
117
119
{string (acc ^ " \\ " ) lexbuf}
118
120
| '"'
119
121
{acc}
122
+ | newline
123
+ {lexer_error_at (Lexing. lexeme_start_p lexbuf) " unescaped newline in string" }
120
124
and comment = parse
121
125
| " (*"
122
126
{
@@ -132,12 +136,7 @@ and comment = parse
132
136
| eof
133
137
{
134
138
let pos = List. hd ! comment_start_pos in
135
- let file = pos.Lexing. pos_fname in
136
- let line = pos.Lexing. pos_lnum in
137
- let column = pos.Lexing. pos_cnum - pos.Lexing. pos_bol in
138
- let message = Printf. sprintf " %s:%d:%d: unterminated comment"
139
- file line column in
140
- lexer_error message
139
+ lexer_error_at pos " unterminated comment"
141
140
}
142
141
| _
143
142
{
0 commit comments