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;
64 INT (int_of_string int)
67 | (alpha (alpha | num | '_')* as id) {
75 | "function" -> FUNCTION
89 (* Eat unimplemented. FIXME: stop indiscriminate eating *)
93 and string_literal = parse
94 (* Keep escaped quote marks as part of the string literal *)
96 Buffer.add_char string_buf '"';
101 let string = Buffer.contents string_buf in
102 Buffer.reset string_buf;
108 Buffer.add_char string_buf c;
109 string_literal lexbuf
113 (* TODO: Error: unterminated comment? or we don't care? *)
117 (* Track line number *)
119 Lexing.new_line lexbuf;
130 match !comment_level with
132 | n when n > 0 -> comment lexbuf
136 (* Drop comment contents *)