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

Cheaper/simpler way to get column information out-of-the-box #48

Open
alberth opened this issue Feb 20, 2020 · 1 comment
Open

Cheaper/simpler way to get column information out-of-the-box #48

alberth opened this issue Feb 20, 2020 · 1 comment

Comments

@alberth
Copy link

alberth commented Feb 20, 2020

In SLY, the recommended way to get column information for a token is to use its stored offset, find the offset of the last newline, and use that to compute the column.

While coding a scanner, I realized there is a simpler/cheaper way to get column information for each token.

If you instead store the offset of the start of a line at the same time you update the line number information, and copy that line start offset into each token together with the line number, the token has sufficient information to compute its offset by itself.

Abstracting this to "a position-information" object makes this even simpler. Instead of copying a line number, copy an object named position or something similar. Create a new Position object with line number and line start offset each time a newline is found, and done.

@alberth
Copy link
Author

alberth commented Feb 20, 2020

Affects #44

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

No branches or pull requests

1 participant