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 rule token = parse
(** Layout *) (** Layout *)
| newline { next_line_and token lexbuf } | newline { next_line_and token lexbuf }
| blank+ { token lexbuf } | blank+ { token lexbuf }
| eof { EOF } | eof { EOF }
| "{*" { commentary lexbuf } | open_comment { commentary 1 lexbuf }
| "##" { commentary_line lexbuf } | "##" { commentary_line lexbuf }
(** Keywords *) (** Keywords *)
@ -189,16 +193,18 @@ rule token = parse
| "'" ascii_trop_grand "'" { error lexbuf None "" } | "'" ascii_trop_grand "'" { error lexbuf None "" }
| _ as _c { error lexbuf None (* (Some _c) *) err_msg } | _ as _c { error lexbuf None (* (Some _c) *) err_msg }
(* TODO: Gérer les imbrications de commentaires *) and commentary nest = parse
and commentary = parse (* Support nesting *)
| "*}" { token lexbuf } | close_comment { if nest = 1 then token lexbuf
| newline { next_line_and commentary lexbuf } else commentary (nest - 1) lexbuf }
| open_comment { commentary (nest + 1) lexbuf }
(** Error *) (** Error *)
| eof { error lexbuf None "unclosed commentary." } | eof { error lexbuf None "unclosed commentary." }
(** Commentary content *) (** Commentary content *)
| _ { commentary lexbuf } | newline { next_line_and (commentary nest) lexbuf }
| _ { commentary nest lexbuf }
and commentary_line = parse and commentary_line = parse
| newline { next_line_and token lexbuf } | newline { next_line_and token lexbuf }