From bee021d78e1fe2967fb41085bbfa366683effcdb Mon Sep 17 00:00:00 2001 From: Atsushi Igarashi Date: Mon, 15 Oct 2018 23:45:28 +0900 Subject: [PATCH 1/2] Reset pos_bol everytime Lexing.flush_input is called --- bin/main.ml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/main.ml b/bin/main.ml index 632ebf6..69a8387 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1,6 +1,11 @@ open Format open Lambda_dti +(* Altenative to Lexing.flush_input so that pos_bol is also reset to 0 *) +let flush_input lexbuf = + Lexing.flush_input lexbuf; + lexbuf.lex_curr_p <- {lexbuf.lex_curr_p with pos_bol = 0} + let debug = ref false let rec read_eval_print lexbuf env tyenv = @@ -47,11 +52,11 @@ let rec read_eval_print lexbuf env tyenv = with | Failure message -> print "Failure: %s\n" message; - Lexing.flush_input lexbuf + flush_input lexbuf | Parser.Error -> (* Menhir *) let token = Lexing.lexeme lexbuf in print "Parser.Error: unexpected token %s\n" token; - Lexing.flush_input lexbuf + flush_input lexbuf | Typing.Type_error message -> print "Type_error: %s\n" message | Eval.Blame (r, p) -> begin From b44f10b15b826725f6d824d11ac829f2c2c7cc10 Mon Sep 17 00:00:00 2001 From: Atsushi Igarashi Date: Mon, 15 Oct 2018 23:45:51 +0900 Subject: [PATCH 2/2] Do not squash a sequence of newlines in counting # of lines --- lib/lexer.mll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lexer.mll b/lib/lexer.mll index bf47347..2164509 100644 --- a/lib/lexer.mll +++ b/lib/lexer.mll @@ -26,7 +26,7 @@ let range_of lexbuf = rule main = parse [' ' '\t']+ { main lexbuf } -| [' ' '\t']* '\n'+ { Lexing.new_line lexbuf; main lexbuf } +| [' ' '\t']* '\n' { Lexing.new_line lexbuf; main lexbuf } | "(*" { comment lexbuf; main lexbuf } | ['0'-'9']+ {