nested comment block

This commit is contained in:
Mylloon 2023-10-25 09:58:44 +02:00
parent 75e2d0e78c
commit 899dae5ea1
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -107,12 +107,16 @@ let str_char = ascii_table
| '\''
| "\\\""
(* Commentaires *)
let open_comment = "{*"
let close_comment = "*}"
rule token = parse
(** Layout *)
| newline { next_line_and token lexbuf }
| blank+ { token lexbuf }
| eof { EOF }
| "{*" { commentary lexbuf }
| open_comment { commentary 1 lexbuf }
| "##" { commentary_line lexbuf }
(** Keywords *)
@ -181,7 +185,7 @@ rule token = parse
| '"' { read_string (Buffer.create 16) lexbuf }
(* Characters *)
| "'" (char as c) "'" { CHAR c }
| "'" (char as c) "'" { CHAR c }
| "'" (atom as a) "'" { CHAR (recup_char a lexbuf) }
(** Lexing errors *)
@ -189,16 +193,18 @@ rule token = parse
| "'" ascii_trop_grand "'" { error lexbuf None "" }
| _ as _c { error lexbuf None (* (Some _c) *) err_msg }
(* TODO: Gérer les imbrications de commentaires *)
and commentary = parse
| "*}" { token lexbuf }
| newline { next_line_and commentary lexbuf }
and commentary nest = parse
(* Support nesting *)
| close_comment { if nest = 1 then token lexbuf
else commentary (nest - 1) lexbuf }
| open_comment { commentary (nest + 1) lexbuf }
(** Error *)
| eof { error lexbuf None "unclosed commentary." }
| eof { error lexbuf None "unclosed commentary." }
(** Commentary content *)
| _ { commentary lexbuf }
| newline { next_line_and (commentary nest) lexbuf }
| _ { commentary nest lexbuf }
and commentary_line = parse
| newline { next_line_and token lexbuf }