diff --git a/lib/lexer.mll b/lib/lexer.mll index 19ec168e..474de438 100644 --- a/lib/lexer.mll +++ b/lib/lexer.mll @@ -170,7 +170,7 @@ rule read = { let v = decimal_code c d u in if v > 255 then raise (SyntaxError - (Printf.sprintf "illegal escape sequence \\%c%c%c" c d u)) + (Printf.sprintf "Illegal escape sequence \\%c%c%c" c d u)) else U8 (Char.chr v) } | "'" '\\' 'x' @@ -216,6 +216,14 @@ and read_string buf = | '\\' 'r' { Buffer.add_char buf '\r'; read_string buf lexbuf } | '\\' 't' { Buffer.add_char buf '\t'; read_string buf lexbuf } | '\\' '"' { Buffer.add_char buf '"'; read_string buf lexbuf } + | '\\' (['0'-'9'] as c) (['0'-'9'] as d) (['0'-'9'] as u) + { let v = decimal_code c d u in + if v > 255 then + raise (SyntaxError (Printf.sprintf + "Illegal backslash escape in string: '\\%c%c%c'" c d u)) + else + Buffer.add_char buf (Char.chr v); + read_string buf lexbuf } | [^ '"' '\\' '\n' '\r']+ { Buffer.add_string buf (Lexing.lexeme lexbuf); read_string buf lexbuf diff --git a/test/typing.ml b/test/typing.ml index 23a3b1fe..44820757 100644 --- a/test/typing.ml +++ b/test/typing.ml @@ -65,6 +65,10 @@ let test_const_i32 () = test "i32" "let a = 123i32\na" let test_const_neg_i32 () = test "i32" "let a = -123i32\na" let test_const_f32 () = test "f32" "let a = 1.0f32\na" let test_const_neg_f32 () = test "f32" "let a = -1.0f32\na" + +let test_const_string_ansi () = + test "string/t" "let s = \"\\027[2K\ram idling: \"\ns" + let test_hint_int () = test "int" "let a : int = 1\na" let test_func_id () = test "('a) -> 'a" "fun (a): copy(a)" let test_func_id_hint () = test "(int) -> int" "fun (a : int): a" @@ -1426,6 +1430,7 @@ let () = case "-i32" test_const_neg_i32; case "f32" test_const_f32; case "-f32" test_const_neg_f32; + case "string ansi" test_const_string_ansi; ] ); ("hints", [ case "int" test_hint_int ]); ( "funcs",