summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlasdair Armstrong2018-01-19 19:15:49 +0000
committerAlasdair Armstrong2018-01-19 19:15:49 +0000
commit2dac693e02c7f467f4faf5d95cd3017002beb060 (patch)
tree1ece7d085e0a842c937bc590434fce7ec258370b /src
parentb3cb23aeb3d555b6256fbb027e55378efc2cdc12 (diff)
Added C-style single line comments
// is a comment as well as /* is a comment */
Diffstat (limited to 'src')
-rw-r--r--src/lexer.mll6
1 files changed, 6 insertions, 0 deletions
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 ()