sxp 1.0.0 → 1.2.0

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.
data/lib/sxp/reader.rb CHANGED
@@ -22,9 +22,9 @@ module SXP
22
22
  # @param [Hash{Symbol => Object}] options
23
23
  # See {#read}
24
24
  # @return [Enumerable<Object>]
25
- def self.read_url(url, options = {})
25
+ def self.read_url(url, **options)
26
26
  require 'open-uri'
27
- open(url.to_s, 'rb', nil, options) { |io| read_all(io, options).first }
27
+ open(url.to_s, 'rb', nil, **options) { |io| read_all(io, **options) }
28
28
  end
29
29
 
30
30
  ##
@@ -33,7 +33,7 @@ module SXP
33
33
  # @overload read_files(*filenames)
34
34
  # @param [Enumerable<String>] filenames
35
35
  #
36
- # @overload read_files(*filenames, options)
36
+ # @overload read_files(*filenames, **options)
37
37
  # @param [Enumerable<String>] filenames
38
38
  # @param [Hash{Symbol => Object}] options
39
39
  # See {#read}
@@ -41,7 +41,7 @@ module SXP
41
41
  # @return [Enumerable<Object>]
42
42
  def read_files(*filenames)
43
43
  options = filenames.last.is_a?(Hash) ? filenames.pop : {}
44
- filenames.map { |filename| read_file(filename, options) }.inject { |sxps, sxp| sxps + sxp }
44
+ filenames.map { |filename| read_file(filename, **options) }.inject { |sxps, sxp| sxps + sxp }
45
45
  end
46
46
 
47
47
  ##
@@ -51,8 +51,8 @@ module SXP
51
51
  # @param [Hash{Symbol => Object}] options
52
52
  # See {#read}
53
53
  # @return [Enumerable<Object>]
54
- def self.read_file(filename, options = {})
55
- File.open(filename.to_s, 'rb') { |io| read_all(io, options).first }
54
+ def self.read_file(filename, **options)
55
+ File.open(filename.to_s, 'rb') { |io| read_all(io, **options) }
56
56
  end
57
57
 
58
58
  ##
@@ -62,8 +62,8 @@ module SXP
62
62
  # @param [Hash{Symbol => Object}] options
63
63
  # See {#read}
64
64
  # @return [Enumerable<Object>]
65
- def self.read_all(input, options = {})
66
- self.new(input, options).read_all
65
+ def self.read_all(input, **options)
66
+ self.new(input, **options).read_all
67
67
  end
68
68
 
69
69
  ##
@@ -73,8 +73,8 @@ module SXP
73
73
  # @param [Hash{Symbol => Object}] options
74
74
  # See {#read}
75
75
  # @return [Object]
76
- def self.read(input, options = {})
77
- self.new(input, options).read
76
+ def self.read(input, **options)
77
+ self.new(input, **options).read
78
78
  end
79
79
 
80
80
  ##
@@ -82,7 +82,7 @@ module SXP
82
82
  #
83
83
  # @param [IO, StringIO, String] input
84
84
  # @param [Hash{Symbol => Object}] options
85
- def initialize(input, options = {}, &block)
85
+ def initialize(input, **options, &block)
86
86
  @options = options.dup
87
87
 
88
88
  case
@@ -127,10 +127,10 @@ module SXP
127
127
  # @param [Hash{Symbol => Object}] options
128
128
  # See {#read}
129
129
  # @return [Array]
130
- def read_all(options = {})
130
+ def read_all(**options)
131
131
  list = []
132
132
  catch (:eof) do
133
- list << read(options.merge(eof: :throw)) until eof?
133
+ list << read(eof: :throw, **options) until eof?
134
134
  end
135
135
  list
136
136
  end
@@ -145,19 +145,19 @@ module SXP
145
145
  # Expected list terminator; it's an error
146
146
  # if another terminator is found
147
147
  # @return [Object]
148
- def read(options = {})
148
+ def read(eof: nil, eol: nil, list_term: false, **options)
149
149
  skip_comments
150
150
  token, value = read_token
151
151
  case token
152
152
  when :eof
153
- throw :eof if options[:eof] == :throw
153
+ throw :eof if eof == :throw
154
154
  raise EOF, "unexpected end of input"
155
155
  when :list
156
156
  if ndx = self.class.const_get(:LPARENS).index(value)
157
- list_term = self.class.const_get(:RPARENS)[ndx]
158
- read_list(list_term)
157
+ term = self.class.const_get(:RPARENS)[ndx]
158
+ read_list(term)
159
159
  else
160
- throw :eol if options[:eol] == :throw && value == options[:list_term]
160
+ throw :eol if eol == :throw && value == list_term
161
161
  raise Error, "unexpected list terminator: ?#{value.chr}"
162
162
  end
163
163
  else value
data/lib/sxp.rb CHANGED
@@ -1,23 +1,8 @@
1
1
  require 'rational'
2
2
  require 'stringio'
3
3
 
4
- if RUBY_VERSION < '1.8.7'
5
- # @see http://rubygems.org/gems/backports
6
- begin
7
- require 'backports/1.8.7'
8
- rescue LoadError
9
- begin
10
- require 'rubygems'
11
- require 'backports/1.8.7'
12
- rescue LoadError
13
- abort "SXP.rb requires Ruby 1.8.7 or the Backports gem (hint: `gem install backports')."
14
- end
15
- end
16
- end
17
-
18
4
  require 'sxp/version'
19
5
  require 'sxp/extensions'
20
- require 'sxp/writer'
21
6
 
22
7
  module SXP
23
8
  autoload :Pair, 'sxp/pair'
@@ -32,8 +17,8 @@ module SXP
32
17
  # @param [String, #to_s] url
33
18
  # @param [Hash{Symbol => Object}] options
34
19
  # @return [Enumerable<Object>]
35
- def self.read_url(url, options = {})
36
- Reader::Basic.read_url(url, options)
20
+ def self.read_url(url, **options)
21
+ Reader::Basic.read_url(url, **options)
37
22
  end
38
23
 
39
24
  ##
@@ -42,7 +27,7 @@ module SXP
42
27
  # @overload read_files(*filenames)
43
28
  # @param [Enumerable<String>] filenames
44
29
  #
45
- # @overload read_files(*filenames, options)
30
+ # @overload read_files(*filenames, **options)
46
31
  # @param [Enumerable<String>] filenames
47
32
  # @param [Hash{Symbol => Object}] options
48
33
  #
@@ -57,8 +42,8 @@ module SXP
57
42
  # @param [String, #to_s] filename
58
43
  # @param [Hash{Symbol => Object}] options
59
44
  # @return [Enumerable<Object>]
60
- def self.read_file(filename, options = {})
61
- Reader::Basic.read_file(filename, options)
45
+ def self.read_file(filename, **options)
46
+ Reader::Basic.read_file(filename, **options)
62
47
  end
63
48
 
64
49
  ##
@@ -67,8 +52,8 @@ module SXP
67
52
  # @param [IO, StringIO, String] input
68
53
  # @param [Hash{Symbol => Object}] options
69
54
  # @return [Enumerable<Object>]
70
- def self.read_all(input, options = {})
71
- Reader::Basic.read_all(input, options)
55
+ def self.read_all(input, **options)
56
+ Reader::Basic.read_all(input, **options)
72
57
  end
73
58
 
74
59
  ##
@@ -77,8 +62,8 @@ module SXP
77
62
  # @param [IO, StringIO, String] input
78
63
  # @param [Hash{Symbol => Object}] options
79
64
  # @return [Object]
80
- def self.read(input, options = {})
81
- Reader::Basic.read(input, options)
65
+ def self.read(input, **options)
66
+ Reader::Basic.read(input, **options)
82
67
  end
83
68
 
84
69
  ##
metadata CHANGED
@@ -1,58 +1,86 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sxp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arto Bendiken
8
8
  - Gregg Kellogg
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-10 00:00:00.000000000 Z
12
+ date: 2021-12-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rspec
15
+ name: rdf
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '3.2'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '3.2'
28
+ - !ruby/object:Gem::Dependency
29
+ name: matrix
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: amazing_print
16
44
  requirement: !ruby/object:Gem::Requirement
17
45
  requirements:
18
46
  - - "~>"
19
47
  - !ruby/object:Gem::Version
20
- version: '3.4'
48
+ version: '1.4'
21
49
  type: :development
22
50
  prerelease: false
23
51
  version_requirements: !ruby/object:Gem::Requirement
24
52
  requirements:
25
53
  - - "~>"
26
54
  - !ruby/object:Gem::Version
27
- version: '3.4'
55
+ version: '1.4'
28
56
  - !ruby/object:Gem::Dependency
29
- name: yard
57
+ name: rspec
30
58
  requirement: !ruby/object:Gem::Requirement
31
59
  requirements:
32
60
  - - "~>"
33
61
  - !ruby/object:Gem::Version
34
- version: '0.8'
62
+ version: '3.10'
35
63
  type: :development
36
64
  prerelease: false
37
65
  version_requirements: !ruby/object:Gem::Requirement
38
66
  requirements:
39
67
  - - "~>"
40
68
  - !ruby/object:Gem::Version
41
- version: '0.8'
69
+ version: '3.10'
42
70
  - !ruby/object:Gem::Dependency
43
- name: rdf
71
+ name: yard
44
72
  requirement: !ruby/object:Gem::Requirement
45
73
  requirements:
46
74
  - - "~>"
47
75
  - !ruby/object:Gem::Version
48
- version: '2.0'
49
- type: :runtime
76
+ version: '0.9'
77
+ type: :development
50
78
  prerelease: false
51
79
  version_requirements: !ruby/object:Gem::Requirement
52
80
  requirements:
53
81
  - - "~>"
54
82
  - !ruby/object:Gem::Version
55
- version: '2.0'
83
+ version: '0.9'
56
84
  description: Universal S-expression parser with specific support for Common Lisp,
57
85
  Scheme, and RDF/SPARQL
58
86
  email:
@@ -87,12 +115,11 @@ files:
87
115
  - lib/sxp/reader/scheme.rb
88
116
  - lib/sxp/reader/sparql.rb
89
117
  - lib/sxp/version.rb
90
- - lib/sxp/writer.rb
91
- homepage: http://sxp.rubyforge.org/
118
+ homepage: https://github.com/dryruby/sxp/
92
119
  licenses:
93
120
  - Unlicense
94
121
  metadata: {}
95
- post_install_message:
122
+ post_install_message:
96
123
  rdoc_options: []
97
124
  require_paths:
98
125
  - lib
@@ -100,17 +127,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
127
  requirements:
101
128
  - - ">="
102
129
  - !ruby/object:Gem::Version
103
- version: '2.0'
130
+ version: '2.6'
104
131
  required_rubygems_version: !ruby/object:Gem::Requirement
105
132
  requirements:
106
133
  - - ">="
107
134
  - !ruby/object:Gem::Version
108
135
  version: '0'
109
136
  requirements: []
110
- rubyforge_project: sxp
111
- rubygems_version: 2.4.8
112
- signing_key:
137
+ rubygems_version: 3.3.3
138
+ signing_key:
113
139
  specification_version: 4
114
140
  summary: A pure-Ruby implementation of a universal S-expression parser.
115
141
  test_files: []
116
- has_rdoc: false
data/lib/sxp/writer.rb DELETED
@@ -1,216 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require 'bigdecimal'
3
- require 'time'
4
-
5
- ##
6
- # Extensions for Ruby's `Object` class.
7
- class Object
8
- ##
9
- # Returns the SXP representation of this object.
10
- #
11
- # @return [String]
12
- def to_sxp
13
- to_s.to_json
14
- end
15
- end
16
-
17
- ##
18
- # Extensions for Ruby's `NilClass` class.
19
- class NilClass
20
- ##
21
- # Returns the SXP representation of this object.
22
- #
23
- # @return [String]
24
- def to_sxp
25
- '#n'
26
- end
27
- end
28
-
29
- ##
30
- # Extensions for Ruby's `FalseClass` class.
31
- class FalseClass
32
- ##
33
- # Returns the SXP representation of this object.
34
- #
35
- # @return [String]
36
- def to_sxp
37
- '#f'
38
- end
39
- end
40
-
41
- ##
42
- # Extensions for Ruby's `TrueClass` class.
43
- class TrueClass
44
- ##
45
- # Returns the SXP representation of this object.
46
- #
47
- # @return [String]
48
- def to_sxp
49
- '#t'
50
- end
51
- end
52
-
53
- ##
54
- # Extensions for Ruby's `String` class.
55
- class String
56
- ##
57
- # Returns the SXP representation of this object.
58
- #
59
- # @return [String]
60
- def to_sxp
61
- inspect
62
- end
63
- end
64
-
65
- ##
66
- # Extensions for Ruby's `Symbol` class.
67
- class Symbol
68
- ##
69
- # Returns the SXP representation of this object.
70
- #
71
- # @return [String]
72
- def to_sxp
73
- to_s
74
- end
75
- end
76
-
77
- ##
78
- # Extensions for Ruby's `Integer` class.
79
- class Integer
80
- ##
81
- # Returns the SXP representation of this object.
82
- #
83
- # @return [String]
84
- def to_sxp
85
- to_s
86
- end
87
- end
88
-
89
- ##
90
- # Extensions for Ruby's `BigDecimal` class.
91
- class BigDecimal
92
- ##
93
- # Returns the SXP representation of this object.
94
- #
95
- # @return [String]
96
- def to_sxp
97
- to_f.to_s
98
- end
99
- end
100
-
101
- ##
102
- # Extensions for Ruby's `Float` class.
103
- class Float
104
- ##
105
- # Returns the SXP representation of this object.
106
- #
107
- # @return [String]
108
- def to_sxp
109
- case
110
- when nan? then 'nan.'
111
- when infinite? then (infinite? > 0 ? '+inf.' : '-inf.')
112
- else to_s
113
- end
114
- end
115
- end
116
-
117
- ##
118
- # Extensions for Ruby's `Array` class.
119
- class Array
120
- ##
121
- # Returns the SXP representation of this object.
122
- #
123
- # @return [String]
124
- def to_sxp
125
- '(' << map { |x| x.to_sxp }.join(' ') << ')'
126
- end
127
- end
128
-
129
- ##
130
- # Extensions for Ruby's `Time` class.
131
- class Time
132
- ##
133
- # Returns the SXP representation of this object.
134
- #
135
- # @return [String]
136
- def to_sxp
137
- '#@' << (respond_to?(:xmlschema) ? xmlschema : to_i).to_s
138
- end
139
- end
140
-
141
- ##
142
- # Extensions for Ruby's `Regexp` class.
143
- class Regexp
144
- ##
145
- # Returns the SXP representation of this object.
146
- #
147
- # @return [String]
148
- def to_sxp
149
- '#' << inspect
150
- end
151
- end
152
-
153
- begin
154
- require 'rdf' # For SPARQL
155
-
156
- class RDF::URI
157
- ##
158
- # Returns the SXP representation of this object.
159
- #
160
- # @return [String]
161
- def to_sxp; lexical || "<#{self}>"; end
162
- end
163
-
164
- class RDF::Node
165
- ##
166
- # Returns the SXP representation of this object.
167
- #
168
- # @return [String]
169
- def to_sxp; to_s; end
170
- end
171
-
172
- class RDF::Literal
173
- ##
174
- # Returns the SXP representation of a Literal.
175
- #
176
- # @return [String]
177
- def to_sxp
178
- case datatype
179
- when RDF::XSD.boolean, RDF::XSD.integer, RDF::XSD.double, RDF::XSD.decimal, RDF::XSD.time
180
- # Retain stated lexical form if possible
181
- valid? ? to_s : object.to_sxp
182
- else
183
- text = value.dump
184
- text << "@#{language}" if self.has_language?
185
- text << "^^#{datatype.to_sxp}" if self.has_datatype?
186
- text
187
- end
188
- end
189
- end
190
-
191
- class RDF::Query
192
- # Transform Query into an Array form of an SXP
193
- #
194
- # If Query is named, it's treated as a GroupGraphPattern, otherwise, a BGP
195
- #
196
- # @return [Array]
197
- def to_sxp
198
- res = [:bgp] + patterns
199
- (named? ? [:graph, graph_name, res] : res).to_sxp
200
- end
201
- end
202
-
203
- class RDF::Query::Pattern
204
- # Transform Query Pattern into an SXP
205
- # @return [String]
206
- def to_sxp
207
- [:triple, subject, predicate, object].to_sxp
208
- end
209
- end
210
-
211
- class RDF::Query::Variable
212
- def to_sxp; to_s; end
213
- end
214
- rescue LoadError => e
215
- # Ignore if RDF not loaded
216
- end