Crate anysexpr

source ·
Expand description

This is an S-Expression parser and formatter with the following goals:

  • Offering direct access to the tokenizer, anysexpr::parse, but also anysexpr::read to build an in-memory tree easily.

  • Good error reporting (precise location information and messages).

  • (Future) Make the data constructors for anysexpr::read parametrizable (generic), e.g. like in the sexpr_parser crate.

  • Streaming: allow to read from and print to file handles lazily, for use e.g. in communications. This currently works by using anysexpr::parse directly for input, or creating tokens to print via a custom loop for output. Future: more possibilities, e.g. turn a tree into a token stream, or parameterize with a tree that’s generated on demand while printing.

  • (Future) Support various s-expression variants (R*RS, Guile, Clojure, Common Lisp, ..) via runtime (and compile-time?) settings.

  • (Perhaps) be usable on microcontrollers (small code, no-std?).

The author is quite new to Rust. There will be API guideline entries not currently being followed, help in that area is as welcome as in other areas.

Modules

  • Get characters and their positions from anything implementing BufRead. This exists because it’s not clear if any dependency (some of them large) would be better.
  • Holding the static information about the source or sink of a stream (i.e. other than position).
  • Utilities for debugging the anysexpr library
  • A representation of the number types possible in S-expressions (numeric tower).
  • Translating a character stream to a token stream. This is (currently) called “parser” because it fully parses atoms (like strings, symbols, etc.), thus “tokenizer” may be selling it short (?). The only tokens denoting nesting are Token::Open and Token::Close. See read if interested in trees rather than atoms / tokens.
  • A position within a stream. For building full context, also see context. Both line and col are zero based; Emacs uses 1-based line numbering, so line is incremented by 1 in Display.
  • The implementation of the lisp read function (as well as helpers around it), i.e. parsing a character stream to an S-expression tree representation. See parse for using the underlying tokenizer directly.
  • Settings for both reading (parsing) and writing (serializing) data.
  • Runtime data types representing an S-expression value. Whereas Atom does not include lists, VValue adds lists implemented using Rust vectors. VValue can represent improper lists, but no cycles.