Skip to content

Commit

Permalink
Count lines in all cases. (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
toots authored Jun 26, 2023
1 parent fa49875 commit 7581a9d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
- Use `Sedlexing.{Utf8,Utf16}.from_gen` to initialize UTF8 (resp. UTF16) lexing buffers from
string.
- Delay raising Malformed until actually reading the malformed part of the imput. (#140)
- Count lines in all cases (#130). Previously, certain functions for initiating the
lexical buffer would disable lines counting.

# 3.1:
- Fix directly nested sedlex matches (@smuenzel, PR #117, fixes: #12)
Expand Down
11 changes: 3 additions & 8 deletions src/lib/sedlexing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let empty_lexbuf =
offset = 0;
pos = 0;
curr_bol = 0;
curr_line = 0;
curr_line = 1;
start_pos = 0;
start_bol = 0;
start_line = 0;
Expand All @@ -71,12 +71,7 @@ let dummy_uchar = Uchar.of_int 0
let nl_uchar = Uchar.of_int 10

let create refill =
{
empty_lexbuf with
refill;
buf = Array.make chunk_size dummy_uchar;
curr_line = 1;
}
{ empty_lexbuf with refill; buf = Array.make chunk_size dummy_uchar }

let set_position lexbuf position =
lexbuf.offset <- position.Lexing.pos_cnum - lexbuf.pos;
Expand Down Expand Up @@ -139,7 +134,7 @@ let refill lexbuf =
if n = 0 then lexbuf.finished <- true else lexbuf.len <- lexbuf.len + n

let new_line lexbuf =
if lexbuf.curr_line != 0 then lexbuf.curr_line <- lexbuf.curr_line + 1;
lexbuf.curr_line <- lexbuf.curr_line + 1;
lexbuf.curr_bol <- lexbuf.pos + lexbuf.offset

let[@inline always] next_aux some none lexbuf =
Expand Down

0 comments on commit 7581a9d

Please sign in to comment.