lib/sxp/reader/basic.rb in sxp-1.3.0 vs lib/sxp/reader/basic.rb in sxp-2.0.0
- old
+ new
@@ -13,11 +13,11 @@
##
# @return [Object]
def read_token
case peek_char
when ?(, ?) then [:list, read_char]
- when ?" then [:atom, read_string] #"
+ when ?", ?' then [:atom, read_string] #" or '
else super
end
end
##
@@ -34,19 +34,21 @@
##
# @return [String]
def read_string
buffer = ""
- skip_char # '"'
- until peek_char == ?" #"
+ quote_char = read_char
+ until peek_char == quote_char # " or '
buffer <<
case char = read_char
when ?\\ then read_character
else char
end
end
- skip_char # '"'
- buffer
+ skip_char # " or '
+
+ # Return string, annotating it with the quotation style used
+ buffer.tap {|s| s.quote_style = (quote_char == '"' ? :dquote : :squote)}
end
##
# @return [String]
def read_character