The #ASDF <file-format-version> line and the comment lines that follow it.
File format version 1.0.z is the only layout this library parses. The
optional #ASDF_STANDARD <version> comment records the specification
version. It is not part of the header grammar in the file-layout chapter;
the versioning chapter shows it as the comment that carries that version.
Summary
Types
One parsed header.
A major.minor.patch triple. Each component is a non-negative integer
without a leading zero in the file text.
Types
@type t() :: %ASDF.Header{ bytes: non_neg_integer(), comments: [String.t()], format_version: version(), standard_version: version() | nil }
One parsed header.
:format_version— the#ASDFversion:standard_version— the#ASDF_STANDARDcomment, ornil:bytes— bytes consumed, including the header newline and comments:comments— comment lines after the format line, including#and any#ASDF_STANDARDline
@type version() :: {non_neg_integer(), non_neg_integer(), non_neg_integer()}
A major.minor.patch triple. Each component is a non-negative integer
without a leading zero in the file text.
Functions
@spec parse(binary(), keyword()) :: {:ok, t()} | {:error, ASDF.Error.t()}
Parses a header from the front of binary.
binary is the start of a file. opts accepts :limits, an
%ASDF.Limits{} or a keyword list of its fields.
Returns {:ok, header}. :bytes includes the header newline and the
comment lines that follow it. Bytes after the comments are left for the
tree or the first block.
Returns {:error, %ASDF.Error{}} and does not raise. Reasons:
:not_asdf— the input does not start with#ASDF:truncated_header— the header line has no newline:unsupported_format_version— the version is not1.0.z:duplicate_standard_version— more than one#ASDF_STANDARDline:line_too_long— a header line exceedsmax_header_line_bytes:too_many_comments— more comments thanmax_comment_lines:invalid_encoding— a header line is not UTF-8:invalid_limitor:unknown_limit—:limitsis not usable
Examples
iex> {:ok, header} = ASDF.Header.parse("#ASDF 1.0.0\n#ASDF_STANDARD 1.5.0\n# note\n")
...> {header.format_version, header.standard_version, header.comments, header.bytes}
{{1, 0, 0}, {1, 5, 0}, ["#ASDF_STANDARD 1.5.0", "# note"], 40}
iex> {:error, error} = ASDF.Header.parse("nope\n")
...> error.reason
:not_asdf
iex> {:error, error} = ASDF.Header.parse("#ASDF 2.0.0\n")
...> error.reason
:unsupported_format_version
iex> text = "#ASDF 1.0.0\n#ASDF_STANDARD 1.5.0\n#ASDF_STANDARD 1.6.0\n"
...> {:error, error} = ASDF.Header.parse(text)
...> error.reason
:duplicate_standard_version
Parses a header and returns the struct.
binary and opts are the same as parse/2. Returns the %ASDF.Header{}.
Raises ASDF.Error for the same reasons parse/2 returns an error.
Examples
iex> ASDF.Header.parse!("#ASDF 1.0.0\n").format_version
{1, 0, 0}
iex> ASDF.Header.parse!("nope\n")
** (ASDF.Error) input does not start with an #ASDF file-format header