sexpistol 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = Sexpistol
2
2
 
3
- Sexpistol is a simple library for parsing S-Expressions in Ruby. Sexpistol takes an S-Expression and turns it into a native Ruby data structure made up of nested sets of arrays.
3
+ Sexpistol is a very fast and easy-to-use library for parsing S-Expressions in Ruby. Sexpistol takes an S-Expression in string form and turns it into a native Ruby data structure made up of nested sets of arrays.
4
4
 
5
5
  === Example
6
6
 
@@ -42,6 +42,15 @@ Sexpistol also supports mapping the Ruby keyword literals (nil, true, false) to
42
42
  @parser.parse_string("nil false true")
43
43
  #=> [nil, false, true]
44
44
 
45
+ == Scheme compatibility
46
+
47
+ Above all Sexpistol strives to be compatible with Scheme-style S-Expressions. This means that Sexpistol supports comma quoting, though quasi-quoting is not yet implemented. Sexpistol can also generate Scheme compatible external representations when the 'scheme_compatability' options is set to true:
48
+
49
+ @parser = Sexpistol.new
50
+ @parser.scheme_compatability = true
51
+ @parser.to_sexp([:test, false, true, nil])
52
+ #=> "(test #f #t ())"
53
+
45
54
  === Installation
46
55
 
47
56
  For convenience Sexpistol is packaged as a RubyGem, to install it simply enter the following at your command line:
@@ -66,8 +75,15 @@ For convenience Sexpistol is packaged as a RubyGem, to install it simply enter t
66
75
  @parser.to_sexp( ast )
67
76
  #=> "( string ( is ( parsed ) ) )"
68
77
 
78
+ === Performance
79
+
80
+ The core of Sexpistol was recently re-written using StringScanner and the new version is roughly twice as fast as the older ones.
81
+
82
+ Parsing throughput on my test machine (2Ghz Core 2 Duo, 4GB RAM, Ruby 1.9) is approximately 1 Megabytes/sec. This is fairly high given that Sexpistol is pure Ruby. Benchmarking Sexpistol against other popular S-Expression parser gems shows that it is roughly 8x faster than the nearest competitor.
83
+
69
84
  === Author & Credits
70
85
 
71
86
  Author:: {Aaron Gough}[mailto:aaron@aarongough.com]
87
+ Contributors:: {Shane Hanna}[http://github.com/shanna]
72
88
 
73
89
  Copyright (c) 2010 {Aaron Gough}[http://thingsaaronmade.com/] ({thingsaaronmade.com}[http://thingsaaronmade.com/]), released under the MIT license
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
data/lib/sexpistol.rb CHANGED
@@ -1 +1,2 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'sexpistol', 'sexpistol_parser.rb'))
1
2
  require File.expand_path(File.join(File.dirname(__FILE__), 'sexpistol', 'sexpistol.rb'))
@@ -4,151 +4,73 @@
4
4
  # [:def, :something [:lambda, [:a], [:do_something]]]
5
5
  class Sexpistol
6
6
 
7
- attr_accessor :ruby_keyword_literals
8
-
9
- def initialize
10
- @ruby_keyword_literals = false
11
-
12
- # Setup all of our token patterns as instance variables
13
- # so they don't have to be re-instantiated for each
14
- # run & match
15
- @string_literal_pattern = /"([^"\\]|\\.)*"/
16
- @integer_literal_pattern = /[\-\+]?[0-9]+/
17
- @float_literal_pattern = /[\-\+]?[0-9]+\.[0-9]+(e[0-9]+)?/
18
- @symbol_pattern = /[^\"\'\,\(\)]+/
19
-
20
- @string_replacement_token = "__++STRING_LITERAL++__"
21
- end
7
+ attr_accessor :ruby_keyword_literals, :scheme_compatability
22
8
 
23
9
  # Parse a string containing an S-Expression into a
24
10
  # nested set of Ruby arrays
25
- def parse_string( string )
26
- string_array = split_outside_strings(string)
27
- tokens = process_tokens( string_array )
28
- structure( tokens )[1]
11
+ def parse_string(string)
12
+ tree = SexpistolParser.new(string).parse
13
+ return convert_ruby_keyword_literals(tree) if(@ruby_keyword_literals)
14
+ return tree
29
15
  end
30
16
 
31
- # Iterate over an array of strings and turn each
32
- # item into it's relevant token. ie: "string" -> :string, "1" -> 1
33
- def process_tokens( token_array )
34
- tokens = []
35
- token_array.each do |t|
36
- if(@ruby_keyword_literals)
37
- tokens << nil and next if(t == "nil")
38
- tokens << true and next if(t == "true")
39
- tokens << false and next if(t == "false")
17
+ # Convert symbols corresponding to Ruby's keyword literals
18
+ # into their literal forms
19
+ def convert_ruby_keyword_literals(expression)
20
+ return recursive_map(expression) do |x|
21
+ case x
22
+ when :'nil' then nil
23
+ when :'true' then true
24
+ when :'false' then false
25
+ else x
40
26
  end
41
- tokens << "'" and next if(t == "'")
42
- tokens << t and next if(t == "(" || t == ")")
43
- tokens << t.to_f and next if( is_float?(t))
44
- tokens << t.to_i and next if( is_integer?(t))
45
- tokens << t.to_sym and next if( is_symbol?(t))
46
- tokens << eval(t) and next if( is_string_literal?(t))
47
- raise "\nUnrecognized token: #{t}\n"
48
27
  end
49
- return tokens
50
- end
51
-
52
- # Iterate over a flat array of tokens and turn it
53
- # a nested set of arrays by detecting '(' and ')'
54
- def structure( token_array, offset = 0, internal = false )
55
- program = []
56
- while(offset < token_array.length)
57
- if( token_array[offset] == "(" )
58
- offset, array = structure( token_array, offset + 1, true )
59
- program << array
60
- elsif( token_array[offset] == "'" )
61
- offset, array = structure( token_array, offset + 1, true )
62
- program << array.unshift( :quote )
63
- elsif( token_array[offset] == ")" )
64
- break
65
- else
66
- program << token_array[offset]
67
- end
68
- offset += 1
69
- end
70
- return [offset, program]
71
28
  end
72
29
 
73
- # Split up a string into an array where delimited by whitespace,
74
- # except inside string literals
75
- def split_outside_strings( string )
76
- # Find and extract all the string literals
77
- string_literals = []
78
- string = string.gsub(@string_literal_pattern) do |x|
79
- string_literals << x
80
- @string_replacement_token
81
- end
82
- # Make sure the s-expression is valid
83
- unless( string.count("(") == string.count(")") )
84
- raise Exception, "Invalid S-Expression. The number of opening and closing parentheses does not match."
85
- end
86
- # Split the string up on whitespace and parentheses
87
- array = string.gsub("(", " ( ").gsub(")", " ) ").split(" ")
88
- # replace the special string token with the original string literals
89
- array.collect! do |x|
90
- if( x == @string_replacement_token)
91
- string_literals.shift
92
- else
93
- x
30
+ # Convert nil, true and false into (), #t and #f for compatability
31
+ # with Scheme
32
+ def convert_scheme_literals(data)
33
+ return recursive_map(data) do |x|
34
+ case x
35
+ when nil then []
36
+ when true then :"#t"
37
+ when false then :"#f"
38
+ else x
94
39
  end
95
- end
96
- return array
97
- end
98
-
99
- # Test to see whether or not a string represents an integer
100
- def is_integer?( string )
101
- is_match?( string, @integer_literal_pattern )
102
- end
103
-
104
- # Test to see whether or not a string represents a float
105
- def is_float?( string )
106
- is_match?( string, @float_literal_pattern )
107
- end
108
-
109
- # Test to see whether or not a string represents a symbol
110
- def is_symbol?( string )
111
- is_match?( string, @symbol_pattern )
112
- end
113
-
114
- # Test to see whether or not a string represents a string literal
115
- def is_string_literal?( string )
116
- is_match?( string, @string_literal_pattern )
40
+ end
117
41
  end
118
42
 
119
43
  # Convert a set of nested arrays back into an S-Expression
120
- def to_sexp( data )
44
+ def to_sexp(data)
45
+ data = convert_scheme_literals(data) if(@scheme_compatability)
121
46
  if( data.is_a?(Array))
122
47
  mapped = data.map do |item|
123
48
  if( item.is_a?(Array))
124
49
  to_sexp(item)
125
50
  else
126
- if(item === false)
127
- "#f"
128
- elsif(item === true)
129
- "#t"
130
- else
131
- item.to_s
132
- end
51
+ item.to_s
133
52
  end
134
53
  end
135
54
  "(" + mapped.join(" ") + ")"
136
55
  else
137
- if(data === false)
138
- "#f"
139
- elsif(data === true)
140
- "#t"
141
- else
142
- data.to_s
143
- end
56
+ data.to_s
144
57
  end
145
58
  end
146
-
59
+
147
60
  private
148
-
149
- def is_match?( string, pattern )
150
- match = string.match(pattern)
151
- return false unless match
152
- match[0].length == string.length
61
+
62
+ def recursive_map(data, &block)
63
+ if(data.is_a?(Array))
64
+ return data.map do |x|
65
+ if(x.is_a?(Array))
66
+ recursive_map(x, &block)
67
+ else
68
+ block.call(x)
69
+ end
70
+ end
71
+ else
72
+ block.call(data)
73
+ end
153
74
  end
154
- end
75
+
76
+ end
@@ -0,0 +1,64 @@
1
+ require 'strscan'
2
+
3
+ class SexpistolParser < StringScanner
4
+
5
+ def initialize(string)
6
+ unless(string.count('(') == string.count(')'))
7
+ raise Exception, "Missing closing parentheses"
8
+ end
9
+ super(string)
10
+ end
11
+
12
+ def parse
13
+ exp = []
14
+ while true
15
+ case fetch_token
16
+ when '('
17
+ exp << parse
18
+ when ')'
19
+ break
20
+ when :"'"
21
+ case fetch_token
22
+ when '(' then exp << [:quote].concat([parse])
23
+ else exp << [:quote, @token]
24
+ end
25
+ when String, Fixnum, Float, Symbol
26
+ exp << @token
27
+ when nil
28
+ break
29
+ end
30
+ end
31
+ exp
32
+ end
33
+
34
+ def fetch_token
35
+ skip(/\s+/)
36
+ return nil if(eos?)
37
+
38
+ @token =
39
+ # Match parentheses
40
+ if scan(/[\(\)]/)
41
+ matched
42
+ # Match a string literal
43
+ elsif scan(/"([^"\\]|\\.)*"/)
44
+ eval(matched)
45
+ # Match a float literal
46
+ elsif scan(/[\-\+]? [0-9]+ ((e[0-9]+) | (\.[0-9]+(e[0-9]+)?))/x)
47
+ matched.to_f
48
+ # Match an integer literal
49
+ elsif scan(/[\-\+]?[0-9]+/)
50
+ matched.to_i
51
+ # Match a comma (for comma quoting)
52
+ elsif scan(/'/)
53
+ matched.to_sym
54
+ # Match a symbol
55
+ elsif scan(/[^\(\)\s]+/)
56
+ matched.to_sym
57
+ # If we've gotten here then we have an invalid token
58
+ else
59
+ near = scan %r{.{0,20}}
60
+ raise "Invalid character at position #{pos} near '#{near}'."
61
+ end
62
+ end
63
+
64
+ end
data/sexpistol.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sexpistol}
8
- s.version = "0.0.6"
8
+ s.version = "0.0.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aaron Gough"]
12
- s.date = %q{2010-10-11}
12
+ s.date = %q{2010-10-15}
13
13
  s.description = %q{Sexpistol is an easy-to-use S-Expression parser for Ruby. It is fast and has no dependencies.}
14
14
  s.email = %q{aaron@aarongough.com}
15
15
  s.extra_rdoc_files = [
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
24
24
  "VERSION",
25
25
  "lib/sexpistol.rb",
26
26
  "lib/sexpistol/sexpistol.rb",
27
+ "lib/sexpistol/sexpistol_parser.rb",
27
28
  "sexpistol.gemspec",
28
29
  "test/performance/benchmark_test.rb",
29
30
  "test/setup/test_unit_extensions.rb",
@@ -3,31 +3,43 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper.rb
3
3
  class BenchmarkTest < Test::Unit::TestCase
4
4
 
5
5
  require 'benchmark'
6
+
7
+ def setup
8
+ @example_sexp = <<-EOD
9
+ (display "This is a test string!")
10
+
11
+ (define test (lambda () (begin
12
+ (display (== 1 1))
13
+ (display (== true true))
14
+ (display (== false false))
15
+ (display (== nil nil))
16
+ (display (== 2.09 1.08))
17
+ (display (== 2e6 2e12))
18
+ )))
19
+ EOD
20
+ end
6
21
 
7
22
  test "benchmark sexpistol" do
8
23
  puts "\nRunning performance test...\n"
24
+
9
25
  parser = Sexpistol.new
10
26
  parser.ruby_keyword_literals = true
27
+
11
28
  Benchmark.bmbm do |b|
12
- b.report do
29
+ b.report("Parse") do
30
+ 5000.times do
31
+ parser.parse_string(@example_sexp)
32
+ end
33
+ end
34
+
35
+ b.report("to_sexp") do
36
+ ast = parser.parse_string(@example_sexp)
13
37
  5000.times do
14
- parser.parse_string <<-EOD
15
-
16
- (display "This is a test string!")
17
-
18
- (define test (lambda () (begin
19
- (display (== 1 1))
20
- (display (== true true))
21
- (display (== false false))
22
- (display (== nil nil))
23
- (display (== 2.09 1.08))
24
- (display (== 2e6 2e12))
25
- )))
26
-
27
- EOD
38
+ parser.to_sexp(ast)
28
39
  end
29
40
  end
30
41
  end
42
+
31
43
  puts
32
44
  end
33
45
 
@@ -7,28 +7,33 @@ class FloatLiteralTest < Test::Unit::TestCase
7
7
  end
8
8
 
9
9
  test "should parse sexp containing an implicitly positive float literal" do
10
- ast = @parser.parse_string("10.00")
11
- assert_equal [10.00], ast
10
+ ast = @parser.parse_string("(10.00)")
11
+ assert_equal [[10.00]], ast
12
12
  end
13
13
 
14
14
  test "should parse sexp containing an explicitly positive float literal" do
15
- ast = @parser.parse_string("+910.00")
16
- assert_equal [910.00], ast
15
+ ast = @parser.parse_string("(+910.00)")
16
+ assert_equal [[910.00]], ast
17
17
  end
18
18
 
19
19
  test "should parse sexp containing an explicitly negative float literal" do
20
- ast = @parser.parse_string("-10.00")
21
- assert_equal [-10.00], ast
20
+ ast = @parser.parse_string("(-10.00)")
21
+ assert_equal [[-10.00]], ast
22
22
  end
23
23
 
24
24
  test "should parse sexp containing a large float literal" do
25
- ast = @parser.parse_string("1.0000127829")
26
- assert_equal [1.0000127829], ast
25
+ ast = @parser.parse_string("(1.0000127829)")
26
+ assert_equal [[1.0000127829]], ast
27
27
  end
28
28
 
29
29
  test "should parse sexp containing a float defined in scientific notation" do
30
- ast = @parser.parse_string("1.0e6")
31
- assert_equal [1.0e6], ast
30
+ ast = @parser.parse_string("(1.0e6)")
31
+ assert_equal [[1.0e6]], ast
32
+ end
33
+
34
+ test "should parse sexp containing a float defined in scientific notation with no decimal place" do
35
+ ast = @parser.parse_string("(10e2)")
36
+ assert_equal [[10e2]], ast
32
37
  end
33
38
 
34
39
 
@@ -7,18 +7,18 @@ class IntegerLiteralTest < Test::Unit::TestCase
7
7
  end
8
8
 
9
9
  test "should parse sexp containing an implicitly positive integer literal" do
10
- ast = @parser.parse_string("10")
11
- assert_equal [10], ast
10
+ ast = @parser.parse_string("(10)")
11
+ assert_equal [[10]], ast
12
12
  end
13
13
 
14
14
  test "should parse sexp containing an explicitly positive integer literal" do
15
- ast = @parser.parse_string("+910")
16
- assert_equal [910], ast
15
+ ast = @parser.parse_string("(+910)")
16
+ assert_equal [[910]], ast
17
17
  end
18
18
 
19
19
  test "should parse sexp containing an explicitly negative integer literal" do
20
- ast = @parser.parse_string("-10")
21
- assert_equal [-10], ast
20
+ ast = @parser.parse_string("(-10)")
21
+ assert_equal [[-10]], ast
22
22
  end
23
23
 
24
24
  end
@@ -8,38 +8,38 @@ class RubyKeywordLiteralsTest < Test::Unit::TestCase
8
8
 
9
9
  test "should parse nil as literal" do
10
10
  @parser.ruby_keyword_literals = true
11
- ast = @parser.parse_string('nil')
12
- assert_equal [nil], ast
11
+ ast = @parser.parse_string('(nil)')
12
+ assert_equal [[nil]], ast
13
13
  end
14
14
 
15
15
  test "should not parse nil as literal" do
16
16
  @parser.ruby_keyword_literals = false
17
- ast = @parser.parse_string('nil')
18
- assert_equal [:nil], ast
17
+ ast = @parser.parse_string('(nil)')
18
+ assert_equal [[:nil]], ast
19
19
  end
20
20
 
21
21
  test "should parse true as literal" do
22
22
  @parser.ruby_keyword_literals = true
23
- ast = @parser.parse_string('true')
24
- assert_equal [true], ast
23
+ ast = @parser.parse_string('(true)')
24
+ assert_equal [[true]], ast
25
25
  end
26
26
 
27
27
  test "should not parse true as literal" do
28
28
  @parser.ruby_keyword_literals = false
29
- ast = @parser.parse_string('true')
30
- assert_equal [:true], ast
29
+ ast = @parser.parse_string('(true)')
30
+ assert_equal [[:true]], ast
31
31
  end
32
32
 
33
33
  test "should parse false as literal" do
34
34
  @parser.ruby_keyword_literals = true
35
- ast = @parser.parse_string('false')
36
- assert_equal [false], ast
35
+ ast = @parser.parse_string('(false)')
36
+ assert_equal [[false]], ast
37
37
  end
38
38
 
39
39
  test "should notparse false as literal" do
40
40
  @parser.ruby_keyword_literals = false
41
- ast = @parser.parse_string('false')
42
- assert_equal [:false], ast
41
+ ast = @parser.parse_string('(false)')
42
+ assert_equal [[:false]], ast
43
43
  end
44
44
 
45
45
  end
@@ -4,26 +4,43 @@ class SchemeCompatabilityTest < Test::Unit::TestCase
4
4
 
5
5
  def setup
6
6
  @parser = Sexpistol.new
7
+ @parser.scheme_compatability = true
7
8
  end
8
9
 
9
- test "should parse #t as true" do
10
- ast = @parser.parse_string('#t')
11
- assert_equal [:"#t"], ast
10
+ test "should parse #t as symbol" do
11
+ ast = @parser.parse_string('(#t)')
12
+ assert_equal [[:"#t"]], ast
12
13
  end
13
14
 
14
- test "should parse #f as false" do
15
- ast = @parser.parse_string('#f')
16
- assert_equal [:"#f"], ast
15
+ test "should parse #f as symbol" do
16
+ ast = @parser.parse_string('(#f)')
17
+ assert_equal [[:"#f"]], ast
17
18
  end
18
19
 
19
20
  test "should allow comma quoting" do
20
- ast = @parser.parse_string("(this is '( a test))")
21
- assert_equal [[:this, :is, [:quote, [:a, :test]]]], ast
21
+ ast = @parser.parse_string("(this is '( a test) too foo)(foo)")
22
+ assert_equal [[:this, :is, [:quote, [:a, :test]], :too, :foo ],[:foo]], ast
22
23
  end
23
24
 
24
25
  test "should allow complicated comma quoting" do
25
- ast = @parser.parse_string("(this is '( a test (also)))")
26
- assert_equal [[:this, :is, [:quote, [:a, :test, [:also]]]]], ast
26
+ ast = @parser.parse_string("(this is '( a test) (also))")
27
+ assert_equal [[:this, :is, [:quote, [:a, :test]], [:also]]], ast
28
+ end
29
+
30
+ test "should allow comma quoting of integer literal" do
31
+ ast = @parser.parse_string("(this is '1 (also))")
32
+ assert_equal [[:this, :is, [:quote, 1], [:also]]], ast
33
+ end
34
+
35
+ test "should allow comma quoting of string literal" do
36
+ ast = @parser.parse_string("(this is '\"test\" (also))")
37
+ assert_equal [[:this, :is, [:quote, "test"], [:also]]], ast
38
+ end
39
+
40
+ test "should return scheme compatible external representation" do
41
+ ast = [true, false, nil]
42
+ string = @parser.to_sexp(ast)
43
+ assert_equal "(#t #f ())", string
27
44
  end
28
45
 
29
46
  end
@@ -7,33 +7,33 @@ class StringLiteralTest < Test::Unit::TestCase
7
7
  end
8
8
 
9
9
  test "should parse empty string literal" do
10
- ast = @parser.parse_string('""')
11
- assert_equal [""], ast
10
+ ast = @parser.parse_string('("")')
11
+ assert_equal [[""]], ast
12
12
  end
13
13
 
14
14
  test "should parse string literal" do
15
- ast = @parser.parse_string('"test"')
16
- assert_equal ["test"], ast
15
+ ast = @parser.parse_string('("test")')
16
+ assert_equal [["test"]], ast
17
17
  end
18
18
 
19
19
  test "should parse string literal containing escaped quotes" do
20
- ast = @parser.parse_string('"te\"st"')
21
- assert_equal ["te\"st"], ast
20
+ ast = @parser.parse_string('("te\"st")')
21
+ assert_equal [["te\"st"]], ast
22
22
  end
23
23
 
24
24
  test "should parse string literal containing escaped characters" do
25
- ast = @parser.parse_string('"\n\t\r"')
26
- assert_equal ["\n\t\r"], ast
25
+ ast = @parser.parse_string('("\n\t\r")')
26
+ assert_equal [["\n\t\r"]], ast
27
27
  end
28
28
 
29
29
  test "should parse string literal containing spaces" do
30
- ast = @parser.parse_string('"blah foo"')
31
- assert_equal ["blah foo"], ast
30
+ ast = @parser.parse_string('("blah foo")')
31
+ assert_equal [["blah foo"]], ast
32
32
  end
33
33
 
34
34
  test "should parse string literal containing newlines" do
35
- ast = @parser.parse_string('"blah' + "\n" + 'foo"')
36
- assert_equal ["blah\nfoo"], ast
35
+ ast = @parser.parse_string('("blah' + "\n" + 'foo")')
36
+ assert_equal [["blah\nfoo"]], ast
37
37
  end
38
38
 
39
39
  end
@@ -7,68 +7,68 @@ class SymbolTest < Test::Unit::TestCase
7
7
  end
8
8
 
9
9
  test "should parse simple symbol" do
10
- ast = @parser.parse_string("test")
11
- assert_equal [:test], ast
10
+ ast = @parser.parse_string("(test)")
11
+ assert_equal [[:test]], ast
12
12
  end
13
13
 
14
14
  test "should parse symbol with trailing exclamation mark" do
15
- ast = @parser.parse_string("test!")
16
- assert_equal [:test!], ast
15
+ ast = @parser.parse_string("(test!)")
16
+ assert_equal [[:test!]], ast
17
17
  end
18
18
 
19
19
  test "should parse symbol with trailing question mark" do
20
- ast = @parser.parse_string("test?")
21
- assert_equal [:test?], ast
20
+ ast = @parser.parse_string("(test?)")
21
+ assert_equal [[:test?]], ast
22
22
  end
23
23
 
24
24
  test "should parse symbol containing underscores" do
25
- ast = @parser.parse_string("te__st")
26
- assert_equal [:te__st], ast
25
+ ast = @parser.parse_string("(te__st)")
26
+ assert_equal [[:te__st]], ast
27
27
  end
28
28
 
29
29
  test "should parse symbol with leading underscores" do
30
- ast = @parser.parse_string("__test")
31
- assert_equal [:__test], ast
30
+ ast = @parser.parse_string("(__test)")
31
+ assert_equal [[:__test]], ast
32
32
  end
33
33
 
34
34
  test "should parse symbol with trailing underscores" do
35
- ast = @parser.parse_string("test__")
36
- assert_equal [:test__], ast
35
+ ast = @parser.parse_string("(test__)")
36
+ assert_equal [[:test__]], ast
37
37
  end
38
38
 
39
39
  test "should parse CamelCase symbol" do
40
- ast = @parser.parse_string("TestSymbol")
41
- assert_equal [:TestSymbol], ast
40
+ ast = @parser.parse_string("(TestSymbol)")
41
+ assert_equal [[:TestSymbol]], ast
42
42
  end
43
43
 
44
44
  test "should parse complex symbol" do
45
- ast = @parser.parse_string("__TestSymbol_TEST__?")
46
- assert_equal [:__TestSymbol_TEST__?], ast
45
+ ast = @parser.parse_string("(__TestSymbol_TEST__?)")
46
+ assert_equal [[:__TestSymbol_TEST__?]], ast
47
47
  end
48
48
 
49
49
  test "should parse symbol containing addition operators" do
50
- ast = @parser.parse_string("+")
51
- assert_equal [:+], ast
50
+ ast = @parser.parse_string("(+)")
51
+ assert_equal [[:+]], ast
52
52
  end
53
53
 
54
54
  test "should parse symbol containing multiplication operators" do
55
- ast = @parser.parse_string("*")
56
- assert_equal [:*], ast
55
+ ast = @parser.parse_string("(*)")
56
+ assert_equal [[:*]], ast
57
57
  end
58
58
 
59
59
  test "should parse symbol containing subtraction operators" do
60
- ast = @parser.parse_string("-")
61
- assert_equal [:-], ast
60
+ ast = @parser.parse_string("(-)")
61
+ assert_equal [[:-]], ast
62
62
  end
63
63
 
64
64
  test "should parse symbol containing division operators" do
65
- ast = @parser.parse_string("/")
66
- assert_equal [:"/"], ast
65
+ ast = @parser.parse_string("(/)")
66
+ assert_equal [[:"/"]], ast
67
67
  end
68
68
 
69
69
  test "should parse symbol containing any character except single and double quotes, backquote, parentheses and comma" do
70
- ast = @parser.parse_string("~1!2@3#4$%5^6&7*890-_+=|\]}[{poiuytrewqasdfghjklmnbvcxzZXCVBNMLKJHGFDSAQWERTYUIOP:;/?><")
71
- assert_equal [:"~1!2@3#4$%5^6&7*890-_+=|\]}[{poiuytrewqasdfghjklmnbvcxzZXCVBNMLKJHGFDSAQWERTYUIOP:;/?><"], ast
70
+ ast = @parser.parse_string("(~1!2@3#4$%5^6&7*890-_+=|\]}[{poiuytrewqasdfghjklmnbvcxzZXCVBNMLKJHGFDSAQWERTYUIOP:;/?><)")
71
+ assert_equal [[:"~1!2@3#4$%5^6&7*890-_+=|\]}[{poiuytrewqasdfghjklmnbvcxzZXCVBNMLKJHGFDSAQWERTYUIOP:;/?><"]], ast
72
72
  end
73
73
 
74
74
  end
@@ -18,10 +18,10 @@ class ToSexpTest < Test::Unit::TestCase
18
18
  assert_equal "(String! (1 (2 Other string.)))", sexp
19
19
  end
20
20
 
21
- test "should output true and false using scheme notation" do
21
+ test "should not output true and false using scheme notation when scheme compat is off" do
22
22
  ast = [true, [false, [true, false]]]
23
23
  sexp = @parser.to_sexp(ast)
24
- assert_equal "(#t (#f (#t #f)))", sexp
24
+ assert_equal "(true (false (true false)))", sexp
25
25
  end
26
26
 
27
27
  test "when not passed array to_sexp should print value (integer)" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 6
9
- version: 0.0.6
8
+ - 7
9
+ version: 0.0.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Aaron Gough
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-11 00:00:00 -04:00
17
+ date: 2010-10-15 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -35,6 +35,7 @@ files:
35
35
  - VERSION
36
36
  - lib/sexpistol.rb
37
37
  - lib/sexpistol/sexpistol.rb
38
+ - lib/sexpistol/sexpistol_parser.rb
38
39
  - sexpistol.gemspec
39
40
  - test/performance/benchmark_test.rb
40
41
  - test/setup/test_unit_extensions.rb