You are unlikely to need any of this under normal circumstances.
Run a parser with a given indentation level. So you will likely
use getCol to get the current column, andThen give that to
withIndentLevel.
Code editors treat code like a grid. There are rows and columns.
In most editors, rows and colums are 1-indexed. You move to a new row
whenever you see a \n character.
The getPosition parser succeeds with your current row and column
within the string you are parsing.
The getRow parser succeeds with your current row within
the string you are parsing.
The getCol parser succeeds with your current column within
the string you are parsing.
Editors think of code as a grid, but behind the scenes it is just
a flat array of UTF16 characters. getOffset tells you your index in
that flat array. So if you have read "\n\n\n\n" you are on row 5,
column 1, and offset 4.
Note: browsers use UTF16 strings, so characters may be one or two 16-bit words. This means you can read 4 characters, but your offset will move by 8.
Get the entire string you are parsing right now. Paired with
getOffset this can let you use String.slice to grab substrings
with very little intermediate allocation.
This parser tracks “indentation level” so you can parse indentation sensitive languages. Indentation levels correspond to column numbers, so it starts at 1.