@@ -149,10 +149,12 @@ let op_char = [
149
149
'~' '*' '%' ';' ',' '=' '|' ':' '.' '/'
150
150
]
151
151
152
+ let comment_name = [^ '\000' - ' ' '\x7f' '{' '}' ]*
153
+
152
154
rule token = parse
153
155
whitespace+ { token lexbuf }
154
156
| '\n' { Lexing. new_line lexbuf; token lexbuf }
155
- | " {#" { block_comment 1 lexbuf }
157
+ | " {#" (comment_name as name) { block_comment name lexbuf }
156
158
| " #" { skip_line lexbuf; token lexbuf }
157
159
| '(' { YaccParser. BR_OPN }
158
160
| ')' { YaccParser. BR_CLS }
@@ -205,25 +207,19 @@ and string_token pos buf = parse
205
207
(Position. of_lexing 0 lexbuf.Lexing. lex_start_p))
206
208
}
207
209
208
- and block_comment depth = parse
209
- '\n' { Lexing. new_line lexbuf; block_comment depth lexbuf }
210
- | " {#" { block_comment (depth+ 1 ) lexbuf }
211
- | " #}" {
212
- if depth = 1 then token lexbuf
213
- else block_comment (depth-1 ) lexbuf
210
+ and block_comment name = parse
211
+ '\n' { Lexing. new_line lexbuf; block_comment name lexbuf }
212
+ | (comment_name as name') " #}" {
213
+ if String. ends_with ~suffix: name name' then token lexbuf
214
+ else block_comment name lexbuf
214
215
}
215
- | '"' {
216
- let buf = Buffer. create 32 in
217
- let _ : YaccParser.token =
218
- string_token lexbuf.Lexing. lex_start_p buf lexbuf in
219
- block_comment depth lexbuf
220
- }
221
- | " #" { skip_line lexbuf; block_comment depth lexbuf }
216
+ | comment_name { block_comment name lexbuf }
222
217
| eof {
223
218
Error. fatal (Error. eof_in_comment
224
- (Position. of_lexing 0 lexbuf.Lexing. lex_start_p))
219
+ (Position. of_lexing 0 lexbuf.Lexing. lex_start_p)
220
+ name)
225
221
}
226
- | _ { block_comment depth lexbuf }
222
+ | _ { block_comment name lexbuf }
227
223
228
224
and skip_line = parse
229
225
'\n' { Lexing. new_line lexbuf }
0 commit comments