2 open Tiger_parser.Token
4 let comment_level = ref 0
5 let string_buf = Buffer.create 100
8 let alpha = ['a'-'z' 'A'-'Z']
10 let newline = '\n' | '\r' | "\n\r"
17 (* Track line number *)
19 Lexing.new_line lexbuf;
43 | ';' {Some SEMICOLON}
64 Some (INT (int_of_string int))
67 | (alpha (alpha | num | '_')* as id) {
69 | "array" -> Some ARRAY
70 | "break" -> Some BREAK
75 | "function" -> Some FUNCTION
85 | "while" -> Some WHILE
88 and string_literal = parse
89 (* Keep escaped quote marks as part of the string literal *)
91 Buffer.add_char string_buf '"';
96 let string = Buffer.contents string_buf in
97 Buffer.reset string_buf;
103 Buffer.add_char string_buf c;
104 string_literal lexbuf
108 (* TODO: Error: unterminated comment? or we don't care? *)
112 (* Track line number *)
114 Lexing.new_line lexbuf;
125 match !comment_level with
127 | n when n > 0 -> comment lexbuf
131 (* Drop comment contents *)