# Type Lexbuf explanation

**URL:** <https://discuss.ocaml.org/t/type-lexbuf-explanation/6406>\
**Category:** Learning\
**Tags:** ocamllex\
**Created:** [September 12, 2020, 6:00am UTC](https://discuss.ocaml.org/t/type-lexbuf-explanation/6406 "2020-09-12T06:00:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![teja\_pr](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/teja_pr/32/2229_2.png) [@teja\_pr](https://discuss.ocaml.org/u/teja_pr)\
**Post date:** [September 12, 2020, 6:00am UTC](https://discuss.ocaml.org/t/type-lexbuf-explanation/6406/1 "2020-09-12T06:00:47Z")

</div>

```auto
type lexbuf =
  { refill_buff : lexbuf -> unit;
    mutable lex_buffer : bytes;
    mutable lex_buffer_len : int;
    mutable lex_abs_pos : int;
    mutable lex_start_pos : int;
    mutable lex_curr_pos : int;
    mutable lex_last_pos : int;
    mutable lex_last_action : int;
    mutable lex_eof_reached : bool;
    mutable lex_mem : int array;
    mutable lex_start_p : position;
    mutable lex_curr_p : position;
  }

```

`lex_abs_pos` is an integer indicating the number of characters read so far?! Or something else? What do `lex_start_pos`, `let_curr_pos`, and `lex_last_pos` mean?

Don’t we already have `lex_start_p` for the start of the current token, and `lex_curr_p` for the end of the current token?

---

<div class="post-metadata">

**Author:** ![Chet\_Murthy](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/chet_murthy/32/1501_2.png) [@Chet\_Murthy](https://discuss.ocaml.org/u/Chet_Murthy)\
**Post date:** [September 12, 2020, 9:25am UTC](https://discuss.ocaml.org/t/type-lexbuf-explanation/6406/2 "2020-09-12T09:25:37Z")

</div>

It’s been forever since the last time I dug thru the meaning of all these various `_pos` and `_p` fields, but  
(1) remember that some of them are relative to the beginning of the buffer, hence not absolute. E.g. `lex_start_pos`, `lex_curr_pos`, but maybe others  
(2) `lex_abs_pos` is absolute  
(3) I think the `_p` fields are there for `lexeme_start` and `lexeme_end` and not for the internal use of the lexing algorithms  
Whenever I need to understand the meanings of the fields, a quick search around in stdlib/lexing.ml usually does the trick.
