HumanReadableSExpressions.jl Documentation

Getting Started

HumanReadableSExpressions.jl is a Julia package for reading and writing files written in HRSE, or Human Readable S-Expressions, which are a human-readable format for representing data and configuration files that is equivalent and and interchangeable with s-expressions.

HumanReadableSExpressions.jl provides two main functions, readhrse and writehrse, which read and write HRSE files, respectively. Both functions support custom serialization and deserialization of types using StructTypes.jl.

API

HumanReadableSExpressions.readhrseFunction
readhrse(hrse::IO; options=HrseReadOptions(); type=nothing)
readhrse(hrse::String; options=HrseReadOptions(); type=nothing)

Reads an HRSE file from the given IO object or string and returns the corresponding Julia object. The options argument can be used to configure the parser. Lists will be read as vectors, pairs as a Pair, symbols and strings as a String, and numeric types as the corresponding Julia type defined in the parser options. If type is given, the result will be parsed as the given type using its StructTypes.StructType.

Examples

julia> using HumanReadableSExpressions

julia> hrse = """
       alpha:
           1 2 3 4
           5 6
           7 8 9
       beta: (0 . 3)
       gamma:
           a: 1
           b: 2
           c: "c"
       """;

julia> readhrse(hrse)
3-element Vector{Pair{String}}:
 "alpha" => [[1, 2, 3, 4], [5, 6], [7, 8, 9]]
  "beta" => (0 => 3)
 "gamma" => Pair{String}["a" => 1, "b" => 2, "c" => "c"]

See also HrseReadOptions.

source
HumanReadableSExpressions.HrseReadOptionsType
HrseReadOptions(kwargs...)

Stores options for parsing HRSE files.

Arguments

  • integertypes = [Int64, BigInt]: A list of signed integer types to try parsing integers as. The first type that can represent the integer will be used.
  • floattype = Float64: The floating point type to parse floating point numbers as.
  • readcomments = false: Whether to read comments and store them in CommentedElement objects; if false, comments are ignored.
  • extensions: A collection of Extensions to HRSE.

See also readhrse.

source
HumanReadableSExpressions.writehrseFunction
writehrse(io::IO, obj, options::HrsePrintOptions)
writehrse(obj, options::HrsePrintOptions)

Writes the given Julia object to the given IO object as a HRSE file. The options argument can be used to configure the behavior of the printer. If no IO object is given, the output is written to stdout. Arbitrary objects are serialized using their StructTypes.StructType.

Examples

julia> using HumanReadableSExpressions

julia> hrse = [
           :alpha => [
               [1, 2, 3, 4],
               [5, 6],
               [7, 8, 9]
           ],
           :beta => (0 => 3),
           :gamma => [
               :a => 1
               :b => 2
               :c => :c
           ]
       ];

julia> writehrse(hrse, HumanReadableSExpressions.HrsePrintOptions())
alpha: 
  1 2 3 4
  5 6
  7 8 9
beta: 0: 3
gamma: 
  a: 1
  b: 2
  c: c

See also HrsePrintOptions.

source
HumanReadableSExpressions.HrsePrintOptionsType
HrsePrintOptions(kwargs...)

Stores options for printing HRSE structures to text.

Arguments

  • indent = " ": The string to use for indentation.
  • comments = true: Whether to print comments from CommentedElement objects; if false, comments are ignored.
  • extensions: A collection of Extensions to HRSE.
  • pairmode = COLON_MODE: The PairMode to use when printing pairs.
  • inlineprimitives = 20: The maximum string length of a list of primitives to print on a single line instead of adding a new indentation level.
  • trailingnewline = true: Whether to print a trailing newline at the end of the file.

See also writehrse, ashrse.

source
HumanReadableSExpressions.COLON_MODEConstant

A pair printing mode; pairs should all be displayed using colon-deliminated pairs with implied parentheses, using indentation to show nesting and avoiding parentheses around lists as possible.

See also PairMode.

source