12 releases

0.2.7 Mar 16, 2023
0.2.6 Jan 9, 2021
0.2.5 Jul 13, 2020
0.2.4 Dec 11, 2019
0.1.2 Feb 24, 2019

#168 in Encoding

Download history 1920/week @ 2023-11-20 2251/week @ 2023-11-27 2195/week @ 2023-12-04 2463/week @ 2023-12-11 2003/week @ 2023-12-18 1160/week @ 2023-12-25 1605/week @ 2024-01-01 2217/week @ 2024-01-08 1859/week @ 2024-01-15 758/week @ 2024-01-22 706/week @ 2024-01-29 873/week @ 2024-02-05 1392/week @ 2024-02-12 1041/week @ 2024-02-19 854/week @ 2024-02-26 867/week @ 2024-03-04

4,193 downloads per month
Used in 25 crates (8 directly)

MIT/Apache

275KB
5.5K SLoC

lexpr: S-expressions for Rust Latest Version Rustc Version 1.45+

You may be looking for:

S-expressions are the human-readable, textual representation of code and data in the Lisp family of languages. lexpr aims to provide the tools to:

  • Embed S-expression data into Rust programs using the sexp macro:

    use lexpr::sexp;
    
    let address = sexp!(((name . "Jane Doe") (street . "4026 Poe Lane")));
    
  • Construct and destructure S-expression data using a full-featured API:

    use lexpr::Value;
    
    let names = Value::list(vec!["Alice", "Bob", "Mallory"]);
    println!("The bad guy is {}", names[2].as_str().unwrap());
    
  • Parse and serialize S-expression data from and to its textual representation.

  • Use S-expressions as surface syntax for a configuration file format or other domain-specific language (DSL). lexpr allows obtaining source location information for the parsed data, so you can give error messages that point to the exact place a problem was detected, in case the source was parsed successfully as S-expression data, but the parsed data does not meet the requirements of your DSL.

To get a better idea of the direction lexpr is headed, you may want to take at the TODO or the "why" document.

Rust version requirements

lexpr is CI-tested on current stable, beta and nightly channels of Rust. Additionally, it is made sure that the code still compiles on Rust 1.45.0. However, no tests are run for that build.

Supported Lisp dialects

Currently, lexpr focuses on Scheme, mostly based on R6RS and R7RS syntax, with some extensions, and Emacs Lisp.

Dialect-specific omissions, both ones that are planned to be fixed in the future, and deliberate ones, are listed below. If you are missing a feature that is not yet listed here, please [file an issue]!.

Scheme

  • Support for number syntax is currently quite limited, compared to Scheme's numeric tower. Integers (including hexadecimal, octal and binary notation) as well as floating point values should work though.
  • For strings, continuation line syntax (using a trailing slash) is not yet implemented.
  • Block comments.
  • Directives, such as #!fold-case and #!no-fold-case are not implemented. It's not clear if these will be implemented at all.

Emacs Lisp

  • A main area where lexpr only supports a subset of Emacs Lisp are strings and characters. You can have a look at the gory details.
  • Integer literals with an arbitrary base (radix), are not yet supported.

Licensing

The code and documentation in the lexpr crate is free software, dual-licensed under the MIT or Apache-2.0 license, at your choosing.

The lexpr repository contains code and documentation adapted from the following projects:

  • serde_json, also dual-licensed under MIT/Apache-2.0 licenses.
  • sexpr, Copyright 2017 Zephyr Pellerin, dual-licensed under the same licenses.

Dependencies

~160KB