lib/sxp/reader/sparql.rb in sxp-0.0.10 vs lib/sxp/reader/sparql.rb in sxp-0.0.11
- old
+ new
@@ -6,10 +6,12 @@
#
# Requires [RDF.rb](http://rdf.rubyforge.org/).
#
# @see http://openjena.org/wiki/SSE
class SPARQL < Extended
+ EXPONENT = /[eE][+-]?[0-9]+/
+ DECIMAL = /^[+-]?(\d*)?\.\d*#{EXPONENT}?$/
BNODE_ID = /^_:([A-Za-z][A-Za-z0-9]*)/ # FIXME
BNODE_NEW = /^_:$/
VAR_ID = /^\?([A-Za-z][A-Za-z0-9]*)/ # FIXME
VAR_GEN = /^\?\?([0-9]+)/
VAR_NEW = '??'
@@ -45,11 +47,11 @@
# @return [RDF::URI]
def read_rdf_uri
buffer = String.new
skip_char # '<'
return :< if (char = peek_char).nil? || char.chr !~ ATOM # FIXME: nasty special case for the '< symbol
- return :<= if peek_char.chr.eql?(?=) && read_char # FIXME: nasty special case for the '<= symbol
+ return :<= if peek_char.chr.eql?(?=.chr) && read_char # FIXME: nasty special case for the '<= symbol
until peek_char == ?>
buffer << read_char # TODO: unescaping
end
skip_char # '>'
RDF::URI(buffer)
@@ -58,10 +60,10 @@
##
# @return [Object]
def read_atom
case buffer = read_literal
when '.' then buffer.to_sym
- when DECIMAL then RDF::Literal(Float(buffer + '0'))
+ when DECIMAL then RDF::Literal(Float(buffer[-1].eql?(?.) ? buffer + '0' : buffer))
when INTEGER then RDF::Literal(Integer(buffer))
when BNODE_ID then RDF::Node($1)
when BNODE_NEW then RDF::Node.new
when VAR_ID then RDF::Query::Variable.new($1)
when VAR_GEN then RDF::Query::Variable.new("?#{$1}") # FIXME?