Method: OkJson#valparse

Defined in:
lib/okjson.rb

#valparse(ts) ⇒ Object

Parses a “value” in the sense of RFC 4627. Returns the parsed value and any trailing tokens.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/okjson.rb', line 73

def valparse(ts)
  if ts.length < 0
    raise Error, 'empty'
  end

  typ, _, val = ts[0]
  case typ
  when '{' then objparse(ts)
  when '[' then arrparse(ts)
  when :val,:str then [val, ts[1..-1]]
  else
    raise Error, "unexpected #{val.inspect}"
  end
end