diff options
| author | Alain Frisch <alain@frisch.fr> | 2013-11-29 11:35:50 +0000 |
|---|---|---|
| committer | Alain Frisch <alain@frisch.fr> | 2013-11-29 11:35:50 +0000 |
| commit | 15da6d18042500c6e8f9698bf05bebcec456e9d3 (patch) | |
| tree | 6a6ca58efb888f2b644f889164441cedd4081bea | |
| parent | f093afd67d03cecb0e6cf5d1250104a151037a07 (diff) | |
| download | ocaml-15da6d18042500c6e8f9698bf05bebcec456e9d3.tar.gz | |
Reports the beginning of the string literal in 'This comment contains an unterminated string literal' errors.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14328 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
| -rw-r--r-- | parsing/lexer.mli | 2 | ||||
| -rw-r--r-- | parsing/lexer.mll | 16 |
2 files changed, 10 insertions, 8 deletions
diff --git a/parsing/lexer.mli b/parsing/lexer.mli index b067b2aa3e..b54f111041 100644 --- a/parsing/lexer.mli +++ b/parsing/lexer.mli @@ -21,7 +21,7 @@ type error = | Illegal_escape of string | Unterminated_comment of Location.t | Unterminated_string - | Unterminated_string_in_comment of Location.t + | Unterminated_string_in_comment of Location.t * Location.t | Keyword_as_label of string | Literal_overflow of string ;; diff --git a/parsing/lexer.mll b/parsing/lexer.mll index 8aed03b2fc..175d1c9d7c 100644 --- a/parsing/lexer.mll +++ b/parsing/lexer.mll @@ -22,7 +22,7 @@ type error = | Illegal_escape of string | Unterminated_comment of Location.t | Unterminated_string - | Unterminated_string_in_comment of Location.t + | Unterminated_string_in_comment of Location.t * Location.t | Keyword_as_label of string | Literal_overflow of string ;; @@ -235,8 +235,9 @@ let report_error ppf = function fprintf ppf "Comment not terminated" | Unterminated_string -> fprintf ppf "String literal not terminated" - | Unterminated_string_in_comment _ -> - fprintf ppf "This comment contains an unterminated string literal" + | Unterminated_string_in_comment (_, loc) -> + fprintf ppf "This comment contains an unterminated string literal@.%aString literal begins here" + Location.print_error loc | Keyword_as_label kwd -> fprintf ppf "`%s' is a keyword, it cannot be used as label name" kwd | Literal_overflow ty -> @@ -492,13 +493,14 @@ and comment = parse store_string_char '"'; is_in_string := true; begin try string lexbuf - with Error (Unterminated_string, _) -> + with Error (Unterminated_string, str_start) -> match !comment_start_loc with | [] -> assert false | loc :: _ -> let start = List.hd (List.rev !comment_start_loc) in comment_start_loc := []; - raise (Error (Unterminated_string_in_comment start, loc)) + raise (Error (Unterminated_string_in_comment (start, str_start), + loc)) end; is_in_string := false; store_string_char '"'; @@ -511,13 +513,13 @@ and comment = parse store_lexeme lexbuf; is_in_string := true; begin try quoted_string delim lexbuf - with Error (Unterminated_string, _) -> + with Error (Unterminated_string, str_start) -> match !comment_start_loc with | [] -> assert false | loc :: _ -> let start = List.hd (List.rev !comment_start_loc) in comment_start_loc := []; - raise (Error (Unterminated_string_in_comment start, loc)) + raise (Error (Unterminated_string_in_comment (start, str_start), loc)) end; is_in_string := false; store_string_char '|'; |
