Module: RubyJsonParser::Evaluator
- Extended by:
- T::Sig
- Defined in:
- lib/ruby_json_parser/evaluator.rb
Overview
An evaluator for JSON. Creates Ruby structures based on an JSON AST.
Defined Under Namespace
Classes: Error
Class Method Summary collapse
Class Method Details
.eval(source) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/ruby_json_parser/evaluator.rb', line 17 def eval(source) result = RubyJsonParser.parse(source) raise SyntaxError.new(result.errors) if result.err? eval_node(result.ast) end |
.eval_node(node) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ruby_json_parser/evaluator.rb', line 25 def eval_node(node) case node when AST::NullLiteralNode nil when AST::FalseLiteralNode false when AST::TrueLiteralNode true when AST::StringLiteralNode eval_string(node) when AST::NumberLiteralNode eval_number(node) when AST::ArrayLiteralNode eval_array(node) when AST::ObjectLiteralNode eval_object(node) else raise Error, "invalid AST node: #{node.class}" end end |