Packages

A pure-Gleam YAML parser.

Current section

Files

Jump to
yamleam src yamleam@position.erl
Raw

src/yamleam@position.erl

-module(yamleam@position).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/yamleam/position.gleam").
-export([start/0, advance/2]).
-export_type([position/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Source position tracking.\n"
"\n"
" `Position` points at a single character in the source. Both fields are\n"
" 1-indexed so error messages match editor conventions (line 1 is the first\n"
" line, column 1 is the first character of a line).\n"
).
-type position() :: {position, integer(), integer()}.
-file("src/yamleam/position.gleam", 12).
?DOC(" The position of the first character of any source string.\n").
-spec start() -> position().
start() ->
{position, 1, 1}.
-file("src/yamleam/position.gleam", 17).
?DOC(" Advance the position by one character, handling newline wrap-around.\n").
-spec advance(position(), binary()) -> position().
advance(Pos, Char) ->
case Char of
<<"\n"/utf8>> ->
{position, erlang:element(2, Pos) + 1, 1};
_ ->
{position, erlang:element(2, Pos), erlang:element(3, Pos) + 1}
end.