From fa2c5fafb78e05628e7d63275c8d26489a4f9d88 Mon Sep 17 00:00:00 2001 From: Torben Ewert Date: Fri, 8 May 2026 14:39:49 +0200 Subject: [PATCH] fix: print nested comments --- lib/02_parsing/Lexer.ml | 12 ++++++++++-- test/component/run.t | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/02_parsing/Lexer.ml b/lib/02_parsing/Lexer.ml index 0d30908..e7784f5 100644 --- a/lib/02_parsing/Lexer.ml +++ b/lib/02_parsing/Lexer.ml @@ -708,16 +708,20 @@ let scan_comment t = found ;; -let rec scan_block_comment t = +let rec scan_block_comment ?(inside_comment = false) t = let start_pos = make_position t in eat2 t; let rec loop buf t = match t.current with | `Chr '*' when peek t = `Chr '/' -> eat2 t; + let () = + if inside_comment then + Buffer.add_string buf "*/" + in Buffer.contents buf | `Chr '/' when peek t = `Chr '*' -> - Buffer.add_string buf (scan_block_comment t); + Buffer.add_string buf (scan_block_comment ~inside_comment:true t); loop buf t | `EOF -> Diagnostics.raise_error @@ -729,6 +733,10 @@ let rec scan_block_comment t = loop buf t in let buf = Buffer.create 512 in + let () = + if inside_comment then + Buffer.add_string buf "/*" + in let found = loop buf t in found ;; diff --git a/test/component/run.t b/test/component/run.t index 68ded34..ed19ff4 100644 --- a/test/component/run.t +++ b/test/component/run.t @@ -36,7 +36,7 @@ 0...3 }; - /* COMMENT with nested COMMENT!! */ + /* COMMENT with nested /* COMMENT!! */ */
{/* {config} */} -- 2.51.2