-module(toon_codec@types). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/toon_codec/types.gleam"). -export([delimiter_to_string/1, default_encode_options/0, default_decode_options/0, new_parsed_line/5, parsed_line_depth/1, parsed_line_content/1, parsed_line_number/1, parsed_line_indent/1]). -export_type([json_value/0, delimiter/0, length_marker/0, encode_options/0, decode_options/0, parsed_line/0, array_header/0, root_form/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( " Core type definitions for the TOON encoder/decoder.\n" "\n" " This module defines the JSON value representation, configuration options,\n" " and internal types used throughout the library.\n" " Represents a JSON value that can be encoded/decoded to TOON format.\n" "\n" " This type is compatible with standard JSON representations and preserves\n" " key ordering for objects.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " let user = Object([\n" " #(\"name\", String(\"Alice\")),\n" " #(\"age\", Number(30.0)),\n" " #(\"active\", Bool(True)),\n" " ])\n" " ```\n" " Delimiter character used to separate values in arrays and tabular rows.\n" "\n" " The delimiter determines how inline primitive arrays and tabular data\n" " are formatted and parsed.\n" " Converts a delimiter to its string representation.\n" " Optional marker to prefix array lengths in headers.\n" "\n" " When set to HashMarker, arrays render as [#N] instead of [N].\n" " Configuration options for encoding JSON values to TOON format.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " let options = EncodeOptions(\n" " indent: 2,\n" " delimiter: Comma,\n" " length_marker: NoMarker,\n" " )\n" " ```\n" " Returns the default encoding options.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " let options = default_encode_options()\n" " // EncodeOptions(indent: 2, delimiter: Comma, length_marker: NoMarker)\n" " ```\n" " Configuration options for decoding TOON format to JSON values.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " let options = DecodeOptions(indent: 2, strict: True)\n" " ```\n" " Returns the default decoding options.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " let options = default_decode_options()\n" " // DecodeOptions(indent: 2, strict: True)\n" " ```\n" " Internal: Represents a parsed line with depth and metadata.\n" "\n" " This opaque type is used internally by the decoder to track line information\n" " during parsing. The depth indicates the indentation level.\n" " Create a new ParsedLine.\n" " Get the depth of a parsed line.\n" " Get the content of a parsed line.\n" " Get the line number of a parsed line.\n" " Get the indent of a parsed line.\n" " Internal: Information parsed from an array header line.\n" "\n" " This type represents the structured data extracted from headers like:\n" " - `[3]:` (inline primitive array)\n" " - `items[2]:` (named array)\n" " - `users[2]{id,name}:` (tabular array)\n" " Internal: Type of root value in a TOON document.\n" ). -type json_value() :: null | {bool, boolean()} | {number, float()} | {string, binary()} | {array, list(json_value())} | {object, list({binary(), json_value()})}. -type delimiter() :: comma | tab | pipe. -type length_marker() :: no_marker | hash_marker. -type encode_options() :: {encode_options, integer(), delimiter(), length_marker()}. -type decode_options() :: {decode_options, integer(), boolean()}. -opaque parsed_line() :: {parsed_line, binary(), integer(), integer(), binary(), integer()}. -type array_header() :: {array_header, gleam@option:option(binary()), integer(), delimiter(), gleam@option:option(list(binary())), boolean()}. -type root_form() :: root_array | root_object | {root_primitive, json_value()}. -file("src/toon_codec/types.gleam", 108). -spec delimiter_to_string(delimiter()) -> binary(). delimiter_to_string(Delimiter) -> case Delimiter of comma -> <<","/utf8>>; tab -> <<"\t"/utf8>>; pipe -> <<"|"/utf8>> end. -file("src/toon_codec/types.gleam", 138). -spec default_encode_options() -> encode_options(). default_encode_options() -> {encode_options, 2, comma, no_marker}. -file("src/toon_codec/types.gleam", 153). -spec default_decode_options() -> decode_options(). default_decode_options() -> {decode_options, 2, true}. -file("src/toon_codec/types.gleam", 174). -spec new_parsed_line(binary(), integer(), integer(), binary(), integer()) -> parsed_line(). new_parsed_line(Raw, Depth, Indent, Content, Line_number) -> {parsed_line, Raw, Depth, Indent, Content, Line_number}. -file("src/toon_codec/types.gleam", 190). -spec parsed_line_depth(parsed_line()) -> integer(). parsed_line_depth(Line) -> erlang:element(3, Line). -file("src/toon_codec/types.gleam", 194). -spec parsed_line_content(parsed_line()) -> binary(). parsed_line_content(Line) -> erlang:element(5, Line). -file("src/toon_codec/types.gleam", 198). -spec parsed_line_number(parsed_line()) -> integer(). parsed_line_number(Line) -> erlang:element(6, Line). -file("src/toon_codec/types.gleam", 202). -spec parsed_line_indent(parsed_line()) -> integer(). parsed_line_indent(Line) -> erlang:element(4, Line).