summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2014-05-02 12:08:42 +0000
committerGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2014-05-02 12:08:42 +0000
commit16622052a7438287a09e15ef38e366a4999c0775 (patch)
tree39c34f4117eb43a8b4d80a25edce8027cbfca9c9
parente44ea4c845eaaa7d3e7f25ab053b4a86ef395e49 (diff)
Be less picky in the way we parse '#' lines
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2472 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
-rw-r--r--cparser/Lexer.mll34
1 files changed, 23 insertions, 11 deletions
diff --git a/cparser/Lexer.mll b/cparser/Lexer.mll
index 4fa0552..e0f36f4 100644
--- a/cparser/Lexer.mll
+++ b/cparser/Lexer.mll
@@ -310,9 +310,9 @@ rule initial = parse
else
UNKNOWN_NAME(id, ref OtherId, currentLoc lexbuf) }
| eof { EOF }
- | _ {
- Cerrors.fatal_error "%s:%d Error:@ invalid symbol"
- lexbuf.lex_curr_p.pos_fname lexbuf.lex_curr_p.pos_lnum }
+ | _ as c {
+ Cerrors.fatal_error "%s:%d Error:@ invalid symbol %C"
+ lexbuf.lex_curr_p.pos_fname lexbuf.lex_curr_p.pos_lnum c }
and initial_linebegin = parse
| '\n' { new_line lexbuf; initial_linebegin lexbuf }
@@ -320,14 +320,19 @@ and initial_linebegin = parse
| '#' { hash lexbuf }
| "" { initial lexbuf }
-(* We assume gcc -E syntax. **)
+(* We assume gcc -E syntax but try to tolerate variations. *)
and hash = parse
- | ' ' (decimal_constant as n) " \"" (([^ '\n']#whitespace_char_no_newline)* as file) "\"" [^ '\n']* '\n'
+ | whitespace_char_no_newline +
+ (decimal_constant as n)
+ whitespace_char_no_newline *
+ "\"" ([^ '\n' '\"']* as file) "\""
+ [^ '\n']* '\n'
{ let n =
try int_of_string n
with Failure "int_of_string" ->
- Cerrors.fatal_error "%s:%d Error:@ invalid line number"
- lexbuf.lex_curr_p.pos_fname lexbuf.lex_curr_p.pos_lnum
+ Cerrors.warning "%s:%d Warning:@ invalid line number"
+ lexbuf.lex_curr_p.pos_fname lexbuf.lex_curr_p.pos_lnum;
+ lexbuf.lex_curr_p.pos_lnum
in
lexbuf.lex_curr_p <- {
lexbuf.lex_curr_p with
@@ -336,14 +341,21 @@ and hash = parse
pos_bol = lexbuf.lex_curr_p.pos_cnum
};
initial_linebegin lexbuf }
- | "pragma" whitespace_char_no_newline ([^ '\n']* as s) '\n'
+ | whitespace_char_no_newline *
+ "pragma"
+ whitespace_char_no_newline +
+ ([^ '\n']* as s) '\n'
{ new_line lexbuf; PRAGMA (s, currentLoc lexbuf) }
+ | [^ '\n']* '\n'
+ { Cerrors.warning "%s:%d Warning:@ unrecognized '#' line"
+ lexbuf.lex_curr_p.pos_fname lexbuf.lex_curr_p.pos_lnum;
+ new_line lexbuf; initial_linebegin lexbuf }
| [^ '\n']* eof
{ Cerrors.fatal_error "%s:%d Error:@ unexpected end of file"
lexbuf.lex_curr_p.pos_fname lexbuf.lex_curr_p.pos_lnum }
- | _
- { Cerrors.fatal_error "%s:%d Error:@ invalid symbol"
- lexbuf.lex_curr_p.pos_fname lexbuf.lex_curr_p.pos_lnum }
+ | _ as c
+ { Cerrors.fatal_error "%s:%d Error:@ invalid symbol %C"
+ lexbuf.lex_curr_p.pos_fname lexbuf.lex_curr_p.pos_lnum c }
{
open Streams