Skip to content
A universal S-expression parser for Ruby.
Ruby
Branch: develop
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin Renamed bin/sxp2yml to bin/sxp2yaml. Dec 21, 2009
doc Imported .gitignore. Dec 21, 2009
etc
lib Change NaN and INF representations to, e.g., `+inf.0`. Mar 1, 2019
spec Change NaN and INF representations to, e.g., `+inf.0`. Mar 1, 2019
.gitignore ignore .bundle directory Dec 30, 2013
.travis.yml
.yardopts Added a CREDITS file. Nov 1, 2010
AUTHORS Update documentation and dependencies. Mar 12, 2013
CREDITS
Gemfile Update Gemfile. Jan 1, 2019
README.md
Rakefile Add release basics to Rakefile. Mar 11, 2013
TODO
UNLICENSE Unlicensed the project into the public domain. Dec 21, 2009
VERSION Version 1.0.1. Dec 15, 2017
sxp.gemspec Change NaN and INF representations to, e.g., `+inf.0`. Mar 1, 2019

README.md

SXP.rb: S-Expressions for Ruby

This is a Ruby implementation of a universal S-expression parser.

Gem Version Build Status

Features

  • Parses S-expressions in universal, Scheme, Common Lisp, or SPARQL syntax.
  • Adds a #to_sxp method to Ruby objects.
  • Compatible with Ruby >= 2.2.2, Rubinius >= 3.0, and JRuby 9+.

Examples

require 'sxp'

Parsing basic S-expressions

SXP.read "(* 6 7)"  #=> [:*, 6, 7]

SXP.read <<-EOF
  (define (fact n)
    (if (= n 0)
        1
        (* n (fact (- n 1)))))
EOF

#=> [:define, [:fact, :n],
      [:if, [:"=", :n, 0],
            1,
            [:*, :n, [:fact, [:-, :n, 1]]]]]

Parsing Scheme S-expressions

SXP::Reader::Scheme.read %q((and #t #f))             #=> [:and, true, false]

Parsing Common Lisp S-expressions

SXP::Reader::CommonLisp.read %q((or t nil))          #=> [:or, true, nil]

Parsing SPARQL S-expressions

require 'rdf'

SXP::Reader::SPARQL.read %q((base <http://ar.to/>))  #=> [:base, RDF::URI('http://ar.to/')]

Writing an SXP with formatting

SXP::Generator.print([:and, true, false])   #=> (and #t #f)

Documentation

  • Full documentation available on RubyDoc

  • {SXP}

Parsing SXP

  • {SXP::Reader}
    • {SXP::Reader::Basic}
      • {SXP::Reader::CommonLisp}
      • {SXP::Reader::Extended}
        • {SXP::Reader::Scheme}
        • {SXP::Reader::SPARQL}

Manipulating SXP

  • {SXP::Pair}
    • {SXP::List}

Generating SXP

  • {SXP::Generator}

Dependencies

  • Ruby (>= 2.2.2)
  • RDF.rb (~> 3.0), only needed for SPARQL S-expressions

Installation

The recommended installation method is via RubyGems. To install the latest official release of the SXP.rb gem, do:

% [sudo] gem install sxp

Download

To get a local working copy of the development repository, do:

% git clone git://github.com/dryruby/sxp.rb.git

Alternatively, you can download the latest development version as a tarball as follows:

% wget http://github.com/dryruby/sxp.rb/tarball/master

Resources

Authors

Contributors

License

SXP.rb is free and unencumbered public domain software. For more information, see http://unlicense.org/ or the accompanying UNLICENSE file.

You can’t perform that action at this time.