bracer 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.rdoc +33 -32
- data/Rakefile +7 -7
- data/{sexpistol.gemspec → bracer.gemspec} +10 -10
- data/lib/bracer.rb +2 -0
- data/lib/{sexpistol/sexpistol.rb → bracer/bracer.rb} +0 -0
- data/lib/{sexpistol/sexpistol_parser.rb → bracer/bracer_parser.rb} +1 -1
- data/test/performance/benchmark_test.rb +1 -1
- data/test/test_helper.rb +1 -1
- data/test/unit/ruby_keyword_literals_test.rb +6 -6
- data/test/unit/scheme_compatability_test.rb +2 -2
- data/test/unit/symbol_test.rb +1 -1
- data/test/unit/to_sexp_test.rb +3 -3
- metadata +11 -12
- data/lib/sexpistol.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68b7eba940ce5013a279f57a94cbba368add0d66
|
4
|
+
data.tar.gz: b63ea697d67a60f3b9a933db81b9c6b2a84dac38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebed11cdb915de66cb9cfc24fbd18f3767740b15ab7a2f38e8eda5fcdf0d2c4572635754b2f574b41fa3f7012d576da9c27d67bbf01f6e364e9a866f56a3485f
|
7
|
+
data.tar.gz: e195bb00f717119b0102008927b6b24217366fdb00ebc03f8a0f415ea06da7c8dde06bf5a3cccb6c1a4500e52578f9f8ed0458a686ad00fdc1a35abb3f81e1f9
|
data/README.rdoc
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
=
|
1
|
+
= Bracer
|
2
2
|
|
3
|
-
|
3
|
+
Bracer is Sexpistol-with-braces, a very fast and easy-to-use library for parsing S-Expressions in Ruby. Bracer 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
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
[define test [lambda [] [
|
8
|
+
[print "Hello world!\n"]
|
9
|
+
[print 1]
|
10
|
+
[print 9.01]
|
11
|
+
[print 2.0e10]
|
12
|
+
[print (+ 10 12 13]]
|
13
|
+
]]]
|
14
14
|
|
15
|
-
would be parsed by
|
15
|
+
would be parsed by Bracer like so:
|
16
16
|
|
17
17
|
[:define, :test, [:lambda, [], [
|
18
18
|
[:print, "Hello world!\n"],
|
@@ -24,46 +24,46 @@ would be parsed by Sexpistol like so:
|
|
24
24
|
|
25
25
|
=== Type mappings
|
26
26
|
|
27
|
-
|
27
|
+
Bracer supports all of the standard datatypes and converts them directly to their Ruby equivalents:
|
28
28
|
|
29
|
-
* Lists
|
30
|
-
* Integers
|
31
|
-
* Floats
|
32
|
-
* Strings
|
33
|
-
* Symbols
|
29
|
+
* Lists [a b c]
|
30
|
+
* Integers [1 2 3]
|
31
|
+
* Floats [1.0 2.0 42.9 3e6 1.2e2]
|
32
|
+
* Strings ["\t\"Hello world!\"\n"]
|
33
|
+
* Symbols [symbol Symbol ____symbol____ symbo_l symbol? symbol! + - / ++ a+ e$, etc...]
|
34
34
|
|
35
|
-
|
35
|
+
Bracer also supports mapping the Ruby keyword literals [nil, true, false] to their native Ruby types, although this is disabled by default for compatibility. To enable it use `@parser.ruby_keyword_literals = true`, eg:
|
36
36
|
|
37
|
-
@parser =
|
38
|
-
@parser.parse_string
|
37
|
+
@parser = Bracer.new
|
38
|
+
@parser.parse_string "nil false true"
|
39
39
|
#=> [:nil, :false, :true]
|
40
40
|
|
41
41
|
@parser.ruby_keyword_literals = true
|
42
|
-
@parser.parse_string
|
42
|
+
@parser.parse_string "nil false true"
|
43
43
|
#=> [nil, false, true]
|
44
44
|
|
45
45
|
== Scheme compatibility
|
46
46
|
|
47
|
-
Above all
|
47
|
+
Above all Bracer strives to be compatible with Scheme-style S-Expressions. This means that Bracer supports comma quoting, though quasi-quoting is not yet implemented. Bracer can also generate Scheme compatible external representations when the 'scheme_compatability' options is set to true:
|
48
48
|
|
49
|
-
@parser =
|
49
|
+
@parser = Bracer.new
|
50
50
|
@parser.scheme_compatability = true
|
51
|
-
@parser.to_sexp
|
52
|
-
#=> "
|
51
|
+
@parser.to_sexp [:test, false, true, nil]
|
52
|
+
#=> "[test #f #t []]"
|
53
53
|
|
54
54
|
=== Installation
|
55
55
|
|
56
|
-
For convenience
|
56
|
+
For convenience Bracer is packaged as a RubyGem, to install it simply enter the following at your command line:
|
57
57
|
|
58
|
-
gem install
|
58
|
+
gem install Bracer
|
59
59
|
|
60
60
|
=== Usage
|
61
61
|
|
62
62
|
# Create a new parser instance
|
63
|
-
@parser =
|
63
|
+
@parser = Bracer.new
|
64
64
|
|
65
65
|
# Parse a string
|
66
|
-
ast = @parser.parse_string
|
66
|
+
ast = @parser.parse_string "[string [to [parse]]]"
|
67
67
|
#=> [:string, [:to, [:parse]]]
|
68
68
|
|
69
69
|
# Change the representation
|
@@ -72,18 +72,19 @@ For convenience Sexpistol is packaged as a RubyGem, to install it simply enter t
|
|
72
72
|
#=> [:string, [:is, [:parsed]]]
|
73
73
|
|
74
74
|
# Turn the array structure back into an S-Expression
|
75
|
-
@parser.to_sexp
|
76
|
-
#=> "
|
75
|
+
@parser.to_sexp[ ast ]
|
76
|
+
#=> "[ string [ is [ parsed ] ] ]"
|
77
77
|
|
78
78
|
=== Performance
|
79
79
|
|
80
|
-
The core of
|
80
|
+
The core of Bracer was recently re-written using StringScanner and the new version is roughly twice as fast as the older ones.
|
81
81
|
|
82
|
-
Parsing throughput on my test machine
|
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 Bracer is pure Ruby. Benchmarking Bracer against other popular S-Expression parser gems shows that it is roughly 8x faster than the nearest competitor.
|
83
83
|
|
84
84
|
=== Author & Credits
|
85
85
|
|
86
86
|
Author:: {Aaron Gough}[mailto:aaron@aarongough.com]
|
87
87
|
Contributors:: {Shane Hanna}[http://github.com/shanna]
|
88
|
+
Contributors:: {The Trung}[http://github.com/thetrung]
|
88
89
|
|
89
90
|
Copyright (c) 2010 {Aaron Gough}[http://thingsaaronmade.com/] ({thingsaaronmade.com}[http://thingsaaronmade.com/]), released under the MIT license
|
data/Rakefile
CHANGED
@@ -8,12 +8,12 @@ task :default => :test
|
|
8
8
|
begin
|
9
9
|
require 'jeweler'
|
10
10
|
Jeweler::Tasks.new do |gemspec|
|
11
|
-
gemspec.name = "
|
11
|
+
gemspec.name = "bracer"
|
12
12
|
gemspec.summary = "An S-Expression Parser Library for Ruby"
|
13
|
-
gemspec.description = "
|
14
|
-
gemspec.email = "aaron@aarongough.com"
|
15
|
-
gemspec.homepage = "http://github.com/
|
16
|
-
gemspec.authors = ["Aaron Gough"]
|
13
|
+
gemspec.description = "Bracer is an easy-to-use S-Expression Sexpistol parser with braces for Ruby. It is fast and has no dependencies."
|
14
|
+
gemspec.email = "aaron@aarongough.com, deulamco@gmail.com"
|
15
|
+
gemspec.homepage = "http://github.com/thetrung/bracer"
|
16
|
+
gemspec.authors = ["Aaron Gough, The Trung"]
|
17
17
|
gemspec.rdoc_options << '--line-numbers' << '--inline-source'
|
18
18
|
gemspec.extra_rdoc_files = ['README.rdoc', 'MIT-LICENSE']
|
19
19
|
end
|
@@ -22,7 +22,7 @@ rescue LoadError
|
|
22
22
|
end
|
23
23
|
|
24
24
|
|
25
|
-
desc 'Test
|
25
|
+
desc 'Test bracer.'
|
26
26
|
Rake::TestTask.new(:test) do |t|
|
27
27
|
t.libs << 'lib/*.rb'
|
28
28
|
t.libs << 'test'
|
@@ -31,7 +31,7 @@ Rake::TestTask.new(:test) do |t|
|
|
31
31
|
end
|
32
32
|
|
33
33
|
|
34
|
-
desc 'Generate documentation for
|
34
|
+
desc 'Generate documentation for bracer.'
|
35
35
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
36
36
|
rdoc.rdoc_dir = 'rdoc'
|
37
37
|
rdoc.title = 'Koi'
|
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bracer}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Aaron Gough
|
12
|
-
s.date = %q{
|
13
|
-
s.description = %q{
|
11
|
+
s.authors = ["Aaron Gough, The Trung"]
|
12
|
+
s.date = %q{2010-10-15}
|
13
|
+
s.description = %q{bracer 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, deulamco@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"MIT-LICENSE",
|
@@ -22,10 +22,10 @@ Gem::Specification.new do |s|
|
|
22
22
|
"README.rdoc",
|
23
23
|
"Rakefile",
|
24
24
|
"VERSION",
|
25
|
-
"lib/
|
26
|
-
"lib/
|
27
|
-
"lib/
|
28
|
-
"
|
25
|
+
"lib/bracer.rb",
|
26
|
+
"lib/bracer/bracer.rb",
|
27
|
+
"lib/bracer/bracer_parser.rb",
|
28
|
+
"bracer.gemspec",
|
29
29
|
"test/performance/benchmark_test.rb",
|
30
30
|
"test/setup/test_unit_extensions.rb",
|
31
31
|
"test/test_helper.rb",
|
@@ -38,11 +38,11 @@ Gem::Specification.new do |s|
|
|
38
38
|
"test/unit/symbol_test.rb",
|
39
39
|
"test/unit/to_sexp_test.rb"
|
40
40
|
]
|
41
|
-
s.homepage = %q{http://github.com/thetrung/
|
41
|
+
s.homepage = %q{http://github.com/thetrung/bracer}
|
42
42
|
s.rdoc_options = ["--charset=UTF-8", "--line-numbers", "--inline-source"]
|
43
43
|
s.require_paths = ["lib"]
|
44
44
|
s.rubygems_version = %q{1.3.7}
|
45
|
-
s.summary = %q{An
|
45
|
+
s.summary = %q{An S-Expression Parser Library for Ruby}
|
46
46
|
s.test_files = [
|
47
47
|
"test/performance/benchmark_test.rb",
|
48
48
|
"test/setup/test_unit_extensions.rb",
|
data/lib/bracer.rb
ADDED
File without changes
|
data/test/test_helper.rb
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'test/unit'
|
3
3
|
|
4
4
|
require_files = []
|
5
|
-
require_files << File.join(File.dirname(__FILE__), '..', 'lib', '
|
5
|
+
require_files << File.join(File.dirname(__FILE__), '..', 'lib', 'bracer.rb')
|
6
6
|
require_files.concat Dir[File.join(File.dirname(__FILE__), 'setup', '*.rb')]
|
7
7
|
|
8
8
|
require_files.each do |file|
|
@@ -8,37 +8,37 @@ 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(
|
11
|
+
ast = @parser.parse_string('[nil]')
|
12
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(
|
17
|
+
ast = @parser.parse_string('[nil]')
|
18
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(
|
23
|
+
ast = @parser.parse_string('[true]')
|
24
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(
|
29
|
+
ast = @parser.parse_string('[true]')
|
30
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(
|
35
|
+
ast = @parser.parse_string('[false]')
|
36
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(
|
41
|
+
ast = @parser.parse_string('[false]')
|
42
42
|
assert_equal [[:false]], ast
|
43
43
|
end
|
44
44
|
|
@@ -23,12 +23,12 @@ class SchemeCompatabilityTest < Test::Unit::TestCase
|
|
23
23
|
end
|
24
24
|
|
25
25
|
test "should allow complicated comma quoting" do
|
26
|
-
ast = @parser.parse_string("[this is '[ a test]
|
26
|
+
ast = @parser.parse_string("[this is '[ a test] [also]]")
|
27
27
|
assert_equal [[:this, :is, [:quote, [:a, :test]], [:also]]], ast
|
28
28
|
end
|
29
29
|
|
30
30
|
test "should allow comma quoting of integer literal" do
|
31
|
-
ast = @parser.parse_string
|
31
|
+
ast = @parser.parse_string "[this is '1 [also]]"
|
32
32
|
assert_equal [[:this, :is, [:quote, 1], [:also]]], ast
|
33
33
|
end
|
34
34
|
|
data/test/unit/symbol_test.rb
CHANGED
@@ -67,7 +67,7 @@ class SymbolTest < Test::Unit::TestCase
|
|
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-_
|
70
|
+
ast = @parser.parse_string("[~1!2@3#4$%5^6&7*890-_+=|\)}({poiuytrewqasdfghjklmnbvcxzZXCVBNMLKJHGFDSAQWERTYUIOP:;/?><]")
|
71
71
|
assert_equal [[:"~1!2@3#4$%5^6&7*890-_+=|\)}({poiuytrewqasdfghjklmnbvcxzZXCVBNMLKJHGFDSAQWERTYUIOP:;/?><"]], ast
|
72
72
|
end
|
73
73
|
|
data/test/unit/to_sexp_test.rb
CHANGED
@@ -24,19 +24,19 @@ class ToSexpTest < Test::Unit::TestCase
|
|
24
24
|
assert_equal "[true [false [true false]]]", sexp
|
25
25
|
end
|
26
26
|
|
27
|
-
test "when not passed array to_sexp should print value
|
27
|
+
test "when not passed array to_sexp should print value (integer)" do
|
28
28
|
ast = 1
|
29
29
|
sexp = @parser.to_sexp(ast)
|
30
30
|
assert_equal "1", sexp
|
31
31
|
end
|
32
32
|
|
33
|
-
test "when not passed array to_sexp should print value
|
33
|
+
test "when not passed array to_sexp should print value (string)" do
|
34
34
|
ast = "test"
|
35
35
|
sexp = @parser.to_sexp(ast)
|
36
36
|
assert_equal "test", sexp
|
37
37
|
end
|
38
38
|
|
39
|
-
test "when not passed array to_sexp should print value
|
39
|
+
test "when not passed array to_sexp should print value (symbol)" do
|
40
40
|
ast = :test
|
41
41
|
sexp = @parser.to_sexp(ast)
|
42
42
|
assert_equal "test", sexp
|
metadata
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bracer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Aaron Gough
|
8
|
-
- The Trung
|
7
|
+
- Aaron Gough, The Trung
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2010-10-15 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
|
-
description:
|
15
|
-
|
13
|
+
description: bracer is an easy-to-use S-Expression parser for Ruby. It is fast and
|
14
|
+
has no dependencies.
|
16
15
|
email: aaron@aarongough.com, deulamco@gmail.com
|
17
16
|
executables: []
|
18
17
|
extensions: []
|
@@ -25,10 +24,10 @@ files:
|
|
25
24
|
- README.rdoc
|
26
25
|
- Rakefile
|
27
26
|
- VERSION
|
28
|
-
-
|
29
|
-
- lib/
|
30
|
-
- lib/
|
31
|
-
-
|
27
|
+
- bracer.gemspec
|
28
|
+
- lib/bracer.rb
|
29
|
+
- lib/bracer/bracer.rb
|
30
|
+
- lib/bracer/bracer_parser.rb
|
32
31
|
- test/performance/benchmark_test.rb
|
33
32
|
- test/setup/test_unit_extensions.rb
|
34
33
|
- test/test_helper.rb
|
@@ -40,7 +39,7 @@ files:
|
|
40
39
|
- test/unit/structure_test.rb
|
41
40
|
- test/unit/symbol_test.rb
|
42
41
|
- test/unit/to_sexp_test.rb
|
43
|
-
homepage: http://github.com/thetrung/
|
42
|
+
homepage: http://github.com/thetrung/bracer
|
44
43
|
licenses: []
|
45
44
|
metadata: {}
|
46
45
|
post_install_message:
|
@@ -65,7 +64,7 @@ rubyforge_project:
|
|
65
64
|
rubygems_version: 2.4.5
|
66
65
|
signing_key:
|
67
66
|
specification_version: 3
|
68
|
-
summary: An
|
67
|
+
summary: An S-Expression Parser Library for Ruby
|
69
68
|
test_files:
|
70
69
|
- test/performance/benchmark_test.rb
|
71
70
|
- test/setup/test_unit_extensions.rb
|
data/lib/sexpistol.rb
DELETED