Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'development'

  • Loading branch information...
commit 9166f716839ced3241c899f64ea4eb213c9260a1 2 parents 97a8ef9 + 029675e
@aarongough authored
View
2  VERSION
@@ -1 +1 @@
-0.0.3
+0.0.5
View
14 lib/sexpistol/sexpistol.rb
@@ -38,6 +38,7 @@ def process_tokens( token_array )
tokens << true and next if(t == "true")
tokens << false and next if(t == "false")
end
+ tokens << "'" and next if(t == "'")
tokens << t and next if(t == "(" || t == ")")
tokens << t.to_f and next if( is_float?(t))
tokens << t.to_i and next if( is_integer?(t))
@@ -56,6 +57,9 @@ def structure( token_array, offset = 0, internal = false )
if( token_array[offset] == "(" )
offset, array = structure( token_array, offset + 1, true )
program << array
+ elsif( token_array[offset] == "'" )
+ offset, array = structure( token_array, offset + 1, true )
+ program << array.unshift( :quote )
elsif( token_array[offset] == ")" )
break
else
@@ -118,10 +122,16 @@ def to_sexp( data )
if( item.is_a?(Array))
to_sexp(item)
else
- item.to_s
+ if(item === false)
+ "#f"
+ elsif(item === true)
+ "#t"
+ else
+ item.to_s
+ end
end
end
- "( " + mapped.join(" ") + " )"
+ "(" + mapped.join(" ") + ")"
end
private
View
6 sexpistol.gemspec
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{sexpistol}
- s.version = "0.0.3"
+ s.version = "0.0.5"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Aaron Gough"]
- s.date = %q{2010-10-06}
+ s.date = %q{2010-10-11}
s.description = %q{Sexpistol is an easy-to-use S-Expression parser for Ruby. It is fast and has no dependencies.}
s.email = %q{aaron@aarongough.com}
s.extra_rdoc_files = [
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
"test/unit/float_literal_test.rb",
"test/unit/integer_literal_test.rb",
"test/unit/ruby_keyword_literals_test.rb",
+ "test/unit/scheme_compatability_test.rb",
"test/unit/string_literal_test.rb",
"test/unit/structure_test.rb",
"test/unit/symbol_test.rb",
@@ -48,6 +49,7 @@ Gem::Specification.new do |s|
"test/unit/float_literal_test.rb",
"test/unit/integer_literal_test.rb",
"test/unit/ruby_keyword_literals_test.rb",
+ "test/unit/scheme_compatability_test.rb",
"test/unit/string_literal_test.rb",
"test/unit/structure_test.rb",
"test/unit/symbol_test.rb",
View
29 test/unit/scheme_compatability_test.rb
@@ -0,0 +1,29 @@
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper.rb'))
+
+class SchemeCompatabilityTest < Test::Unit::TestCase
+
+ def setup
+ @parser = Sexpistol.new
+ end
+
+ test "should parse #t as true" do
+ ast = @parser.parse_string('#t')
+ assert_equal [:"#t"], ast
+ end
+
+ test "should parse #f as false" do
+ ast = @parser.parse_string('#f')
+ assert_equal [:"#f"], ast
+ end
+
+ test "should allow comma quoting" do
+ ast = @parser.parse_string("(this is '( a test))")
+ assert_equal [[:this, :is, [:quote, [:a, :test]]]], ast
+ end
+
+ test "should allow complicated comma quoting" do
+ ast = @parser.parse_string("(this is '( a test (also)))")
+ assert_equal [[:this, :is, [:quote, [:a, :test, [:also]]]]], ast
+ end
+
+end
View
7 test/unit/structure_test.rb
@@ -1,6 +1,6 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper.rb'))
-class RubyKeywordLiteralsTest < Test::Unit::TestCase
+class StructureTest < Test::Unit::TestCase
def setup
@parser = Sexpistol.new
@@ -21,5 +21,10 @@ def setup
ast = @parser.parse_string('(this (is (an (s_expression) too)')
end
end
+
+ test "should parser () as empty list" do
+ ast = @parser.parse_string('()')
+ assert_equal [[]], ast
+ end
end
View
14 test/unit/to_sexp_test.rb
@@ -9,7 +9,19 @@ def setup
test "should convert nested arrays back into an S-Expression" do
ast = [:string, [:is, [:parsed]]]
sexp = @parser.to_sexp(ast)
- assert_equal "( string ( is ( parsed ) ) )", sexp
+ assert_equal "(string (is (parsed)))", sexp
+ end
+
+ test "should structure containing integers and strings back into an S-Expression" do
+ ast = ["String!", [1, [2, "Other string."]]]
+ sexp = @parser.to_sexp(ast)
+ assert_equal "(String! (1 (2 Other string.)))", sexp
+ end
+
+ test "should output true and false using scheme notation" do
+ ast = [true, [false, [true, false]]]
+ sexp = @parser.to_sexp(ast)
+ assert_equal "(#t (#f (#t #f)))", sexp
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.