Class: Diml::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/diml/document/parser.rb

Overview

Parser is responsible for converted raw content into a DiML document tree

Instance Method Summary collapse

Constructor Details

#initialize(raw_content) ⇒ Parser

Returns a new instance of Parser.



16
17
18
# File 'lib/diml/document/parser.rb', line 16

def initialize(raw_content)
  @raw_content = raw_content
end

Instance Method Details

#parseObject

Parses the raw content for a DIML document into the internal representation.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/diml/document/parser.rb', line 22

def parse
  basic_tokens = @raw_content.split(";")

  # Create new Content Tree
  ctree = ContentTree.new
  ctree.content = Root.new("")
  ctree.root!

  tree = build_tree(ctree, basic_tokens)

  # Return the root not the last value
  t = tree
  t = t.parent until t.root?
  t
end