diff --git a/flap/src/hopix/hopixLexer.mll b/flap/src/hopix/hopixLexer.mll index 0b9c1d1..f220a5b 100644 --- a/flap/src/hopix/hopixLexer.mll +++ b/flap/src/hopix/hopixLexer.mll @@ -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 }