Class: SyntaxTree::JSON::Parser
- Inherits:
-
Object
- Object
- SyntaxTree::JSON::Parser
- Defined in:
- lib/syntax_tree/json/parser.rb
Overview
This class is responsible for converting from a plain string input into an AST.
Defined Under Namespace
Classes: ParseError, Token
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#initialize(source) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(source) ⇒ Parser
Returns a new instance of Parser.
13 14 15 |
# File 'lib/syntax_tree/json/parser.rb', line 13 def initialize(source) @source = source end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
11 12 13 |
# File 'lib/syntax_tree/json/parser.rb', line 11 def source @source end |
Instance Method Details
#parse ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/syntax_tree/json/parser.rb', line 17 def parse if parse_item(make_tokens) in [value, []] AST::Root.new(value: value) else raise ParseError, "unexpected tokens after value" end end |