Skip to content

Commit

Permalink
Merge pull request #1 from ymyzk/lexing
Browse files Browse the repository at this point in the history
Fix a bug in Lexing.flush_input and in counting # of lines
  • Loading branch information
ymyzk authored Oct 15, 2018
2 parents 2e02874 + b44f10b commit 544a582
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions bin/main.ml
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -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']+
{
Expand Down

0 comments on commit 544a582

Please sign in to comment.