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: Helper function for maintaining lexer position info #3930

Closed
vicuna opened this issue Dec 21, 2005 · 2 comments
Closed

Wish: Helper function for maintaining lexer position info #3930

vicuna opened this issue Dec 21, 2005 · 2 comments

Comments

@vicuna
Copy link

vicuna commented Dec 21, 2005

Original bug ID: 3930
Reporter: aballier
Status: closed (set by @damiendoligez on 2008-01-22T16:24:00Z)
Resolution: fixed
Priority: normal
Severity: feature
Version: 3.09.0
Fixed in version: 3.11+dev
Category: ~DO NOT USE (was: OCaml general)
Monitored by: n8gray

Bug description

The code required to maintain the line/col info in a lexer is identical in almost any lexer you can imagine. I propose that we add a function to Lexing called "start_next_line" (or any other sensible name) that can be called in a lexer action to update the position info after a line ending has been reached. For example:

rule tokenize = parse
'\n' { start_next_line lexbuf; tokenize lexbuf }
| . . .

The code is simple:

let start_next_line lexbuf =
let lcp = lexbuf.lex_curr_p in
lexbuf.lex_curr_p <- {
lcp with
pos_lnum = lcp.pos_lnum + 1;
pos_bol = lcp.pos_cnum; }

I've attached a patch against lexing.ml and lexing.mli that implements this, including ocamldoc comments.

File attachments

@vicuna
Copy link
Author

vicuna commented Dec 21, 2005

Comment author: anonymous

By the way, I reported this.
n8gray /at/ caltech \dot\ edu

@vicuna
Copy link
Author

vicuna commented Jan 22, 2008

Comment author: @damiendoligez

Done in 3.11+dev10 under the name "Lexing.new_line".

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