Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A universal S-expression parser for Ruby.
branch: master
Failed to load latest commit information.
bin Renamed bin/sxp2yml to bin/sxp2yaml.
doc Imported .gitignore.
etc Update SXP doap description.
lib Remove rubinius stuff from gemspec (now in Gemfile).
spec Remove rubinius stuff from gemspec (now in Gemfile).
.gemspec Remove rubinius stuff from gemspec (now in Gemfile).
.gitignore ignore .bundle directory
.travis.yml Remove rubysl dependencies from gemspec and add generic for rbx platf…
.yardopts Added a CREDITS file.
AUTHORS Update documentation and dependencies.
CREDITS Update documentation and dependencies.
README Changed README format from RDoc to Markdown. Fixed the pluralization of a section heading in the README.
Rakefile Add release basics to Rakefile.
TODO Added a solicitation for Clojure S-expression syntax support.
UNLICENSE Unlicensed the project into the public domain.
VERSION Bumped the version to 0.1.6.
sxp.gemspec Added a gemspec symlink for Bundler compatibility.

SXP.rb: S-Expressions for Ruby

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


  • Parses S-expressions in universal, Scheme, Common Lisp, or SPARQL syntax.
  • Adds a #to_sxp method to Ruby objects.
  • Compatible with Ruby 1.8.7+, Ruby 1.9.x, Ruby 2.0.x, and JRuby 1.4/1.5.


require 'sxp'

Parsing basic S-expressions "(* 6 7)"  #=> [:*, 6, 7] <<-EOF
  (define (fact n)
    (if (= n 0)
        (* n (fact (- n 1)))))

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

Parsing Scheme S-expressions %q((and #t #f))             #=> [:and, true, false]

Parsing Common Lisp S-expressions %q((or t nil))          #=> [:or, true, nil]

Parsing SPARQL S-expressions

require 'rdf' %q((base <>))  #=> [:base, RDF::URI('')]

Writing an SXP with formatting

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


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}


  • Ruby (>= 1.8.7) or (>= 1.8.1 with Backports)
  • RDF.rb (>= 1.0.0), only needed for SPARQL S-expressions


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

% [sudo] gem install sxp


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

% git clone git://

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

% wget





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

Something went wrong with that request. Please try again.