/sexp

package sexp provides the data structure and parser for s-expressions in Go.

Primary LanguageGoMIT LicenseMIT

sexp Build Status Coverage Status GoDoc

package sexp provides the data structure and parser for s-expressions in Go.

Installation

go get -u github.com/chewxy/sexp

This package does not use any dependencies other than those found in the standard library.

FAQ

1. Why another package?

Why write another package for s-expressions when there are two other great packages - one by Shane Hanna and another by nsf? In fact, s-expressions are so simple, they can be snippetted in Rosetta Code. So why yet another package?

The main reason is simple - I work with a lot of s-expressions in different formats. I wanted the ability to reuse a lot of parsing code to parse into different types of Atoms and Sexps. More importantly, I needed the ability to compose my parsers. Making a general parser that implements io.Runescanner means this *Parser is composable.

2. Why AtomReader instead of making Sexps implement MarshalText and UnmarshalText?##

The reason for this is mainly historical. I have a large number of libraries which use the AtomReader format instead of MarshalText. I'd argue that MarshalText and UnmarshalText is more elegant, but we're all stuck with the cruft of our past, eh?

3. Your definition of "Reader" is weird.

Yes. It is. AtomReader reads a string and returns a Atom. It doesn't read the same way as io.Reader does. It's retained the Reader suffix because of historical reasons. As an aside, wouldn't it be nice if we could do this: go:generate reverseStringer --type=..., kinda like a deriving Read in Haskell.

4. Linecounts and stuff would be nice, especially for error reporting

Yes. It would be. I started writing it with those in mind but ended up not having them due to time constraints. Never really went back to adding it. Feel free to send a pull request for that.

5. Comments are not supported??!!!

Yes. For now. The basics for handling comments are in the code. I just never finished it. Feel free to send a pull request.

Contributing

  1. File an issue on github if you find any.
  2. Fork the project on Github.
  3. Write your changes.
  4. Make sure the tests (which are sparse for now) passes.
  5. Send a pull request.
  6. I'll review the code, suggest changes if any, and then merge.

Topic branches aren't necessary because the package is small. Most changes will be directly merged into Master.

Licence

Package sexp is licenced under the MIT licence.