From 70a08a62b9312ed1bbcb7c89d47f9a25fa221e34 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 6 Jan 2020 20:51:39 +0000 Subject: [PATCH] parser: Fix tracking of beginning of line for error messages. --- src/lexer.mll | 2 +- src/parse.ml | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lexer.mll b/src/lexer.mll index ae4a030..8f56d5b 100644 --- a/src/lexer.mll +++ b/src/lexer.mll @@ -28,7 +28,7 @@ exception SyntaxError of string let new_line lexbuf = let pos = lexbuf.lex_curr_p in lexbuf.lex_curr_p <- - { pos with pos_bol = lexbuf.lex_curr_pos; pos_lnum = pos.pos_lnum + 1 } + { pos with pos_bol = pos.pos_cnum; pos_lnum = pos.pos_lnum + 1 } } let white = [' ' '\t']+ diff --git a/src/parse.ml b/src/parse.ml index 6e1ff95..19c57ac 100644 --- a/src/parse.ml +++ b/src/parse.ml @@ -53,8 +53,9 @@ let parse_expr lexbuf = let parse_goalfile env filename = Cmdline.debug "parse file: %s" filename; let fp = open_in filename in - let lexbuf = Lexing.from_channel fp in - lexbuf.lex_curr_p <- { lexbuf.lex_curr_p with pos_fname = filename }; + let lexbuf = Lexing.from_channel ~with_positions:true fp in + let pos = lexbuf.lex_curr_p in + lexbuf.lex_curr_p <- { pos with pos_fname = filename }; let env' = parse_file env lexbuf in close_in fp; env' @@ -64,6 +65,7 @@ let parse_goalfile env filename = *) let parse_expr source str = Cmdline.debug "parse expression: %S" str; - let lexbuf = Lexing.from_string str in - lexbuf.lex_curr_p <- { lexbuf.lex_curr_p with pos_fname = source }; + let lexbuf = Lexing.from_string ~with_positions:true str in + let pos = lexbuf.lex_curr_p in + lexbuf.lex_curr_p <- { pos with pos_fname = source }; parse_expr lexbuf -- 1.8.3.1