A subset of S-expressions as a lightweight data-interchange format.

S-expressions is an elegant markup: simple, unambiguius, and easy to parse.

(value
 (#t #f
  string number
  (object
   (#hash()
    #hash(pairs)))
  (array
   (()
    (values))))

(pair
 (string . value))

(pairs
 (pair
  (pair values)))

(values
 (value
  (value values)))

Unlike JSON, a value cannot be null.

Example:

Suppose we have a strip containing the following s-expression:

#hash(("name" . "Introduction to Ceylon")
      ("authors" . ("Stef Epardaud" "Emmanuel Bernard")))

We can parse it as following:

String get_name(String sexp) {
  Value parsed = parse(sexp);
  assert (is SexpObject parsed);
  return parsed.getString("name");
}
Packages
io.github.weakish.sexp

Currently only implemented decoding.

Dependencies
ceylon.json1.3.2
ceylon.test1.3.2

Currently only implemented decoding. See TODO.md for planned features.

APIs are similar to ceylon.json.

Aliases
Valueshared Value=> String|Boolean|Integer|Float|SexpObject|SexpArray

An SEXP value, a String, Boolean, Integer, Float, SexpObject, or SexpArray.

Annotations
licensedUndershared LicensedUnderAnnotation licensedUnder(String description)

Like license but not limited to modules.

LicensedUnderAnnotationshared final sealed LicensedUnderAnnotation

Class for licensedUnder annotation.

Functions
parseshared Value parse(String string)

Parses an SEXP string into an SEXP value

Throws
  • Exception

    the SEXP string is invalid

parseBoolshared Boolean parseBool(Tokenizer tokenizer)

Parse #t, #T, #f, #F, consuming any initial whitespace.

Throws
  • ParseException

    taking values other than #t or #f

parseKeyOrStringshared String parseKeyOrString(Tokenizer tokenizer)

Parse a String literal, consuming any initial whitespace

parseNumbershared Integer|Float parseNumber(Tokenizer tokenizer)

Parse a number, consuming any initial whitespace.

visitshared void visit(Value subject, Visitor visitor, Boolean sortedKeys = false)

Recursively visit the given subject using the given visitor. If sortedKeys is true then the keys of Objects will be visited in alphabetical order

Parameters:
  • subject

    The value to visit.

  • visitor

    The visitor to apply.

  • sortedKeys = false

    Whether keys should be visited in alphabetical order, when visiting objects.

Classes
Buildershared Builder

A Visitor that constructs a Value.

This would usually be used in conjunction with a Parser.

Parsershared Parser

A parser for SEXP data presented as a Tokenizer which calls the given visitor for each matched rule.

To construct a JSON model the visitor would be a Builder.

SexpArrayshared SexpArray

S-expression array.

SexpObjectshared SexpObject

S-expression object (hashmap).