Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A universal S-expression parser for Ruby.
Ruby
Branch: master

README.md

SXP.rb: S-Expressions for Ruby

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

Features

  • 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.

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

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 (>= 1.8.7) or (>= 1.8.1 with Backports)
  • RDF.rb (>= 1.0.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/bendiken/sxp-ruby.git

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

% wget http://github.com/bendiken/sxp-ruby/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.

Something went wrong with that request. Please try again.