SourcePosition

Functions for working with SourcePositions. These point to a specific line and column in a file.

The Gren AST has a lot of these in order to generate descriptive error messages and to enable source mapping.

type alias Position = { row : Int, col : Int }

A position is just a row (line) and column (character) pair.

emptyPos : Position

Points to the start of the file.

Note: the very first character in a file is on line 1, column 1 (not 0, 0).

type alias Region = { start : Position, end : Position }

A Region represents everything between two Positions.

type alias Located a = { start : Position, end : Position, value : a }

A Located value has a Region (start and end position).

at : Position -> Position -> a -> Located a

A simple function for creating a Located value. Can be more readable than a simple record literal.

parser : Parser c e v -> Parser c e (Located v)

Takes a parser for a value, and makes it Located.