Commit e0ce2cd4 authored by Julien Lopez's avatar Julien Lopez
Browse files

Fix string with simple quotes

parent 6ae713f4
......@@ -210,7 +210,7 @@ let rec token = lexer
return lexbuf (KEYWORD (L.utf8_lexeme lexbuf))
| '"' ->
let start = L.lexeme_start lexbuf in
string (L.lexeme_start lexbuf) lexbuf;
string (L.lexeme_start lexbuf) '"' lexbuf;
let s = get_stored_string () in
return_loc start (L.lexeme_end lexbuf) (STRING s)
| "'" -> return lexbuf SQUOTE
......@@ -235,8 +235,12 @@ and comment start = lexer
comment start lexbuf
| "*)" ->
()
| '"' | "'" ->
string (L.lexeme_start lexbuf) lexbuf;
| '"' ->
string (L.lexeme_start lexbuf) '"' lexbuf;
clear_buff ();
comment start lexbuf
| "'" ->
string (L.lexeme_start lexbuf) '\'' lexbuf;
clear_buff ();
comment start lexbuf
| eof ->
......@@ -252,20 +256,23 @@ and tcomment start = lexer
| _ ->
tcomment start lexbuf
and string start = lexer
| '"' -> ()
and string start endchar = lexer
| '"' -> if endchar = '"' then ()
else (store_lexeme lexbuf; string start endchar lexbuf)
| "'" -> if endchar = '\'' then ()
else (store_lexeme lexbuf; string start endchar lexbuf)
| '\\' ['\\' '"' '\''] ->
store_ascii (L.latin1_lexeme_char lexbuf 1); string start lexbuf
| "\\n" -> store_ascii '\n'; string start lexbuf
| "\\t" -> store_ascii '\t'; string start lexbuf
| "\\r" -> store_ascii '\r'; string start lexbuf
store_ascii (L.latin1_lexeme_char lexbuf 1); string start endchar lexbuf
| "\\n" -> store_ascii '\n'; string start endchar lexbuf
| "\\t" -> store_ascii '\t'; string start endchar lexbuf
| "\\r" -> store_ascii '\r'; string start endchar lexbuf
| '\\' ['0'-'9']+ ';' ->
store_code (parse_char lexbuf 10 1); string start lexbuf
store_code (parse_char lexbuf 10 1); string start endchar lexbuf
| '\\' 'x' ['0'-'9' 'a'-'f' 'A'-'F']+ ';' ->
store_code (parse_char lexbuf 16 2); string start lexbuf
store_code (parse_char lexbuf 16 2); string start endchar lexbuf
| '\\' -> illegal lexbuf;
| eof -> error start (start+1) "Unterminated string"
| _ -> store_lexeme lexbuf; string start lexbuf
| _ -> store_lexeme lexbuf; string start endchar lexbuf
let lexbuf = ref None
let last_tok = ref (KEYWORD "DUMMY")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment