From 2dac693e02c7f467f4faf5d95cd3017002beb060 Mon Sep 17 00:00:00 2001 From: Alasdair Armstrong Date: Fri, 19 Jan 2018 19:15:49 +0000 Subject: Added C-style single line comments // is a comment as well as /* is a comment */ --- src/lexer.mll | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/lexer.mll b/src/lexer.mll index fb33552b..2f101b8e 100644 --- a/src/lexer.mll +++ b/src/lexer.mll @@ -233,6 +233,7 @@ rule token = parse | "->" { MinusGt } | "=>" { EqGt(r "=>") } | "<=" { (LtEq(r"<=")) } + | "//" { line_comment (Lexing.lexeme_start_p lexbuf) lexbuf; token lexbuf } | "/*" { comment (Lexing.lexeme_start_p lexbuf) 0 lexbuf; token lexbuf } | "*/" { raise (LexError("Unbalanced comment", Lexing.lexeme_start_p lexbuf)) } | "infix" ws (digit as p) ws (operator as op) @@ -270,6 +271,11 @@ rule token = parse Lexing.lexeme_start_p lexbuf)) } +and line_comment pos = parse + | "\n" { () } + | _ { line_comment pos lexbuf } + | eof { raise (LexError("File ended before newline in comment", pos)) } + and comment pos depth = parse | "/*" { comment pos (depth+1) lexbuf } | "*/" { if depth = 0 then () -- cgit v1.2.3