summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamien Doligez <damien.doligez-inria.fr>2002-03-21 17:24:56 +0000
committerDamien Doligez <damien.doligez-inria.fr>2002-03-21 17:24:56 +0000
commitad2496238313a88ba1856627d39fda873d62af1b (patch)
tree76a5f0a632048105d6fd374453129994ab04ca8a
parent424fd989f5cf395fc187b6ae726a65b067e20122 (diff)
warning sur illegal escape
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@4554 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--lex/lexer.mll25
1 files changed, 21 insertions, 4 deletions
diff --git a/lex/lexer.mll b/lex/lexer.mll
index e8d62758e..d1b37f601 100644
--- a/lex/lexer.mll
+++ b/lex/lexer.mll
@@ -67,12 +67,22 @@ let handle_lexical_error fn lexbuf =
fn lexbuf
with Lexical_error(msg, _, _) ->
raise(Lexical_error(msg, line, column))
+
+let warning lexbuf msg =
+ Printf.eprintf "ocamllex warning:\nFile \"%s\", line %d, character %d: %s.\n"
+ Sys.argv.(1) !line_num
+ (Lexing.lexeme_start lexbuf - !line_start_pos) msg;
+ flush stderr;
+;;
+
}
let identstart =
['A'-'Z' 'a'-'z' '_' '\192'-'\214' '\216'-'\246' '\248'-'\255']
let identbody =
['A'-'Z' 'a'-'z' '_' '\192'-'\214' '\216'-'\246' '\248'-'\255' '\'' '0'-'9']
+let backslash_escapes =
+ ['\\' '"' '\'' 'n' 't' 'b' 'r']
rule main = parse
[' ' '\013' '\009' '\012' ] +
@@ -100,7 +110,7 @@ rule main = parse
Tstring(get_stored_string()) }
| "'" [^ '\\'] "'"
{ Tchar(Char.code(Lexing.lexeme_char lexbuf 1)) }
- | "'" '\\' ['\\' '"' '\'' 'n' 't' 'b' 'r'] "'"
+ | "'" '\\' backslash_escapes "'"
{ Tchar(Char.code(char_for_backslash (Lexing.lexeme_char lexbuf 2))) }
| "'" '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] "'"
{ Tchar(Char.code(char_for_decimal_code lexbuf 2)) }
@@ -143,7 +153,7 @@ and action = parse
action lexbuf }
| "'" [^ '\\' '\''] "'"
{ action lexbuf }
- | "'" '\\' ['\\' '"' '\'' 'n' 't' 'b' 'r'] "'"
+ | "'" '\\' backslash_escapes "'"
{ action lexbuf }
| "'" '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] "'"
{ action lexbuf }
@@ -167,7 +177,7 @@ and string = parse
{ line_start_pos := Lexing.lexeme_end lexbuf;
incr line_num;
string lexbuf }
- | '\\' ['\\' '"' '\'' 'n' 't' 'b' 'r']
+ | '\\' backslash_escapes
{ store_string_char(char_for_backslash(Lexing.lexeme_char lexbuf 1));
string lexbuf }
| '\\' ['0'-'9'] ['0'-'9'] ['0'-'9']
@@ -180,6 +190,13 @@ and string = parse
line_start_pos := Lexing.lexeme_end lexbuf;
incr line_num;
string lexbuf }
+ | '\\' _
+ { warning lexbuf
+ (Printf.sprintf "illegal backslash escape in string: `\\%c'"
+ (Lexing.lexeme_char lexbuf 1));
+ store_string_char(Lexing.lexeme_char lexbuf 0);
+ store_string_char(Lexing.lexeme_char lexbuf 1);
+ string lexbuf }
| _
{ store_string_char(Lexing.lexeme_char lexbuf 0);
string lexbuf }
@@ -199,7 +216,7 @@ and comment = parse
{ comment lexbuf }
| "'" [^ '\\' '\''] "'"
{ comment lexbuf }
- | "'\\" ['\\' '\'' 'n' 't' 'b' 'r'] "'"
+ | "'\\" backslash_escapes "'"
{ comment lexbuf }
| "'\\" ['0'-'9'] ['0'-'9'] ['0'-'9'] "'"
{ comment lexbuf }