3 releases (breaking)

0.2.0 Oct 31, 2024
0.1.0 Nov 16, 2023
0.0.0-reserve.0 Mar 28, 2023

#265 in Parser implementations

Download history 12/week @ 2024-08-16 19/week @ 2024-08-23 34/week @ 2024-08-30 19/week @ 2024-09-06 17/week @ 2024-09-13 27/week @ 2024-09-20 23/week @ 2024-09-27 10/week @ 2024-10-04 7/week @ 2024-10-11 8/week @ 2024-10-18 80/week @ 2024-10-25 84/week @ 2024-11-01 8/week @ 2024-11-08 13/week @ 2024-11-15 18/week @ 2024-11-22 18/week @ 2024-11-29

64 downloads per month
Used in 3 crates

MIT/Apache

280KB
7K SLoC

Rsn - Rusty Notation

This crate is very early in development. Please report any issues on our GitHub.

rsn forbids unsafe code rsn is considered alpha crate version Live Build Status HTML Coverage Report for main Documentation for main

A UTF-8 based text format that looks very similar to valid Rust code. This format adheres closely to Rust's lexical rules

no_std support

This crate supports no_std targets that support the alloc crate.

Data Types

ExampleStruct {
  integers: [42, 0xFF, 0o77, 0b101],
  floats: [42., 3.14, 1e10],
  bools: [true, false],
  chars: ['a', '\''],
  string: "Hello, World!",
  raw_string: r#"I said, "Hello, World!""#,
  bytes: [b'a', b'\''],
  byte_string: b"Hello, World!",
  raw_byte_string: br#"I said, "Hello, World!""#,
  named_map: StructLike {
    field: 42,
  },
  named_tuple: TupleLike(42),
  r#raw_identifiers: true,
  array: [1, 2, 3],
  tuple: (1, 2, 3),
  map: {
    "a": 1,
    "b": 2,
  },
}
  • Integers (42, 0xFF, 0o77, 0b101)

  • Floats (42., 3.14)

  • Bool (true, false)

  • Character ('a', '\'')

  • Byte (b'a', b'\'')

  • String ("hello, world")

  • Raw Strings (r#"They said, "Hello World!""#)

  • Byte Strings (b"hello, world")

  • Named

    • Ident or Raw Ident (r#foo)
    • Map or Tuple
  • Map

    • List of <Value>: <Value> pairs, delimited by comma
    • Trailing comma is optional
  • Tuple (empty tuple = Unit)

    • List of <Value>s, delimited by comma
    • Trailing comma is optional
  • Array

    • List of <Value>s, delimited by comma
    • Trailing comma is optional
  • Comments // and /* */

  • Potential Extensions via #[] syntax

    • Semi-strict comma-delimited list
    • #[foo(...), bar = ...,]
    • All braces/brackets/parens must be paired correctly?
  • rsn-fmt: A formatter project for rsn.
  • rsn.vim: A plugin for Vim/NeoVim.

Why not Ron?

Ron is a great format. There were a few design decisions that led to this very-similar-yet-not-the-same format being invented:

  • ron differentiates between Tuples and Lists, while rsn treats all sequences the same.
  • ron uses a different syntax for structures and maps. rsn uses the same syntax for both concepts.
  • ron has special support for Option<T>. rsn treats Option<T> like any other enum.
  • ron's parsing rules are close but not the same as Rust, while rsn attempts to match implementations:
    • Unicode white space and idents (added in ron-rs/ron#444)
    • Rust allows _ in float literals
    • Rust allows for raw line endings to be escaped in string literals.
    • Rust supports byte strings and byte literals, while Ron elected to use base64 encoded strings for byte values.

Differences between Rust syntax and Rsn

The syntax differs from valid Rust code for:

  • Map literals. Rust has no syntax for map literals.
  • Enum Variants being used without the type name -- Red vs Color::Red
    • This is technically valid Rust syntax if use Color::* is present.
  • Infinity and Not-A-Number floats are represented as +inf/-inf/+NaN/-NaN.
    • For compatibility with Rust syntax, support for f64::INFINITY is being considered.

The rules for parsing literals should match Rust's rules as closely as possible.

Dependencies

~105–350KB