Meilleur traitement de #line

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2348 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Xavier Leroy 1999-03-10 10:05:03 +00:00
parent 56c7d1136e
commit 1fe54415e8
2 changed files with 10 additions and 10 deletions

View File

@ -211,9 +211,9 @@ rule token = parse
comment_start_pos := Lexing.lexeme_start lexbuf;
comment lexbuf;
token lexbuf }
| "#" [' ' '\t']* ['0'-'9']+ [' ' '\t']* "\"" [^ '\n' '\r'] *
| "#" ("line")? [' ' '\t']* ['0'-'9']+ [^ '\n' '\r'] *
('\n' | '\r' | "\r\n")
(* # linenum "filename" flags \n *)
(* # linenum ... or #line linenum ... *)
{ token lexbuf }
| "#" { SHARP }
| "&" { AMPERSAND }

View File

@ -26,20 +26,20 @@ let parse_sharp_line s =
while let c = s.[!l1] in c < '0' || c > '9' do incr l1 done;
let l2 = ref (!l1 + 1) in
while let c = s.[!l2] in c >= '0' && c <= '9' do incr l2 done;
let f1 = ref (!l2 + 1) in
while s.[!f1] <> '"' do incr f1 done;
let f2 = ref (!f1 + 1) in
while s.[!f2] <> '"' do incr f2 done;
linenum := int_of_string(String.sub s !l1 (!l2 - !l1));
filename := String.sub s (!f1 + 1) (!f2 - !f1 - 1)
let f1 = ref (!l2 + 1) in
while !f1 < String.length s && s.[!f1] <> '"' do incr f1 done;
let f2 = ref (!f1 + 1) in
while !f2 < String.length s && s.[!f2] <> '"' do incr f2 done;
if !f1 < String.length s then
filename := String.sub s (!f1 + 1) (!f2 - !f1 - 1)
with Failure _ | Invalid_argument _ ->
Misc.fatal_error "Linenum.parse_sharp_line"
}
rule skip_line = parse
"#" [' ' '\t']*
['0'-'9']+ [' ' '\t']*
"\"" [^ '\n' '\r' '"' (* '"' *) ] * "\""
"#" ("line")? [' ' '\t']* ['0'-'9']+ [' ' '\t']*
("\"" [^ '\n' '\r' '"' (* '"' *) ] * "\"")?
[^ '\n' '\r'] *
('\n' | '\r' | "\r\n")
{ parse_sharp_line(Lexing.lexeme lexbuf);