Skip to content

Obtaining position data (Line, Column) while parsing #369

Discussion options

You must be logged in to vote

The built-in conversion from offset to line/col for error reporting is O(n), so you wouldn't want to use it for every AST node. Usually you'd store the byte offsets or similar in the AST and convert to line and column only when reporting errors or for use in protocols like LSP. A data structure like codemap may be useful for this, which also includes line number mapping using binary search into an array of line start offsets.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@TheRealGlumfish
Comment options

Answer selected by TheRealGlumfish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants