What is the unit of a text column number?
I’ve recently published my parsing combinator library lexy.
One of the things it does is issue a lexy::error
if the input does not match the grammar.
This error has a .position()
which gives you the position where the error occurred.
In order to keep the happy path fast, .position()
is not something that is easy to use for end users:
it is simply an iterator into the input range.
This is no good to a human user who wants something like line and column number to easily locate the problematic input.
Converting an iterator into line/column location seems simple enough:
set line = column = 1
and iterate over the entire input until you’ve reached the position of the iterator.
Every time you see a newline, increment the line number and set the column number back to 1
.
Otherwise, the column is implemented every time you … see what exactly?
What exactly is a “column” of a text and how do I compute it?
» read more »