feat: Support file as argument and better error message

This commit is contained in:
Lucàs
2024-07-03 17:05:54 +02:00
parent e3c26ba702
commit 6cbfb1c6a6
4 changed files with 42 additions and 44 deletions
+8 -5
View File
@@ -4,9 +4,8 @@
exception Error of char
}
let line_comment = "//" [^ '\n']*
let block_comment = "/*" [^'.']* "*/"
let comment = line_comment | block_comment
let line_comment = "//" [^'.']*'\n'
let block_comment = "/*" [^'.']* "*/"
let letter = ['a'-'z' 'A'-'Z']
let digit = ['0'-'9']
@@ -20,8 +19,12 @@ let char = "'" [^'.'] "'"
let string = '"' [^'.']* '"'
rule token = parse
| [' ' '\t'] | comment { token lexbuf }
| ['\n'] { Lexing.new_line lexbuf; token lexbuf }
| ' ' | '\t' { token lexbuf }
| '\n' | line_comment { Lexing.new_line lexbuf; token lexbuf }
| block_comment as comment {
String.iter (fun c -> if c = '\n' then Lexing.new_line lexbuf) comment;
token lexbuf
}
| '+' { PLUS }
| '-' { MINUS }