Class: RubyJsonParser::Parser

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/ruby_json_parser/parser.rb

Overview

JSON parser

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Parser

Returns a new instance of Parser.



21
22
23
24
25
26
27
# File 'lib/ruby_json_parser/parser.rb', line 21

def initialize(source)
  # Lexer/Tokenizer that produces tokens
  @lexer = T.let(Lexer.new(source), Lexer)
  # Next token used for predicting productions
  @lookahead = T.let(Token.new(Token::NONE), Token)
  @errors = T.let([], T::Array[String])
end

Class Method Details

.parse(source) ⇒ Object



13
14
15
# File 'lib/ruby_json_parser/parser.rb', line 13

def parse(source)
  new(source).parse
end

Instance Method Details

#parseObject



30
31
32
33
34
# File 'lib/ruby_json_parser/parser.rb', line 30

def parse
  advance # populate @lookahead
  ast = parse_value
  Result.new(ast, @errors)
end