Class: TreeParser

Inherits:
ServiceBase show all
Defined in:
lib/rosetta/services/tree_parser.rb

Overview

Parse tokens into AST structure.

Constant Summary collapse

BLOCK_TOKEN_TYPES =
{
  QUOTE: BlockQuote,
  BASIC_LIST_ITEM: BasicList,
  NUMBERED_LIST_ITEM: NumberedList
}.freeze

Instance Method Summary collapse

Methods inherited from ServiceBase

call

Constructor Details

#initialize(tokens) ⇒ TreeParser

Returns a new instance of TreeParser.



30
31
32
33
# File 'lib/rosetta/services/tree_parser.rb', line 30

def initialize(tokens)
  @tokens = tokens
  @counter = 0
end

Instance Method Details

#callObject

TODO: Investigate if this can be done without declaring and mutating the array.



36
37
38
39
40
41
# File 'lib/rosetta/services/tree_parser.rb', line 36

def call
  parsed_tree = []
  parsed_tree << consume_next_block until end_of_file?

  parsed_tree.compact
end