Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wish: implement line position information in lexing #3431

Closed
vicuna opened this issue Jan 13, 2005 · 3 comments
Closed

Wish: implement line position information in lexing #3431

vicuna opened this issue Jan 13, 2005 · 3 comments

Comments

@vicuna
Copy link

vicuna commented Jan 13, 2005

Original bug ID: 3431
Reporter: administrator
Status: closed
Resolution: won't fix
Priority: normal
Severity: feature
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Berke Durak
Version: 3.08.2
OS: Debian
Submission from: vol75-1-81-57-79-249.fbx.proxad.net (81.57.79.249)

Hello,

The fields pos_lnum, pos_bol and pos_fname are not computed (this is
acknowledges
in the manual).

They would be really useful. Every time I write a parser, I have to write a
location module to store the byte offsets of line positions... Last time I was
pleased to see that this had finally been implemented only to find out that the
fields weren't computed.

type position = {
pos_fname : string;
pos_lnum : int;
pos_bol : int;
pos_cnum : int;
}

@vicuna
Copy link
Author

vicuna commented Jan 18, 2005

Comment author: administrator

Full_Name: Berke Durak
Version: 3.08.2

The fields pos_lnum, pos_bol and pos_fname are not computed (this is
acknowledges in the manual).

They would be really useful. Every time I write a parser, I have to write a
location module to store the byte offsets of line positions... Last time I
was
pleased to see that this had finally been implemented only to find out that
the
fields weren't computed.

But the fields have to be computed by the lexer, since it is the only part of
the
code that has a notion of lines. So it has to be done by user-written code.

-- Damien

@vicuna
Copy link
Author

vicuna commented Jan 18, 2005

Comment author: administrator

Can't do that in a general way -DD

@vicuna vicuna closed this as completed Jan 18, 2005
@vicuna
Copy link
Author

vicuna commented Jan 18, 2005

Comment author: administrator

On Tue, Jan 18, 2005 at 03:43:46PM +0100, Damien Doligez wrote:

Full_Name: Berke Durak
Version: 3.08.2

The fields pos_lnum, pos_bol and pos_fname are not computed (this is
acknowledges in the manual).

They would be really useful. Every time I write a parser, I have to write a
location module to store the byte offsets of line positions... Last time I
was
pleased to see that this had finally been implemented only to find out that
the
fields weren't computed.

But the fields have to be computed by the lexer, since it is the only part of
the
code that has a notion of lines.

Yes.

So it has to be done by user-written code.

Why ? A Lexing.of_channel_with_lines, implemented as follows,
would be nice in the standard library.

let lexbuf_from_channel_with_lines p ic =
let x = ref 0 (* Byte count )
in
Lexing.from_function
(fun s n ->
let n = input ic s 0 n in
for i = 0 to n - 1 do
if s.[i] = '\n' then
(
put offset etc. *)
done;
x := !x + n;
n)
;;

-- Damien

--
Berke Durak

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant