Provide character-based positions in @$ #105

Closed
sltam opened this Issue Jun 21, 2012 · 5 comments

Projects

None yet

2 participants

@sltam

Currently, @$ provides first_line, first_column, last_line and last_column. These are useful if the input is intended to be read line by line. Otherwise, it is useful to provide also character indexes to the input character string, so that we can do our computations at the string.

In the past, I worked around this issue by replace(/\n/g, '\r') so that first_column + last_column is what I need. But in 0.3.10 jison also treats \r as line breaks!

@zaach
Owner

You're in luck -- ranges were added in 0.3.10 also. Try %options ranges and @$ will have a range property with absolute character position.

@sltam

That works neatly. Thanks for being forward-looking!

@sltam sltam closed this Jun 21, 2012
@sltam sltam reopened this Jun 25, 2012
@sltam

I just hit issues with wrong values from the "range" property when the string covered by the current node contains line break(s). Sorry that I don't have time to make a reduced test case yet. Hope you can reproduce the issue.

@zaach
Owner

Hmm, I've used ranges on a large-ish project without trouble. Create a new issue if you have something we can work of off to try and reproduce.

@zaach zaach closed this Jun 25, 2012
@sltam

Oops. It is more like my fault. Sorry about that.

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