nested comment block
This commit is contained in:
parent
75e2d0e78c
commit
899dae5ea1
1 changed files with 14 additions and 8 deletions
|
@ -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 }
|
||||||
|
|
Reference in a new issue