Class: Org::Markup

Inherits:
Object
  • Object
show all
Defined in:
lib/org/markup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file = nil) ⇒ Markup

Returns a new instance of Markup.



5
6
7
# File 'lib/org/markup.rb', line 5

def initialize(file = nil)
  self.string = File.read(file) if file
end

Instance Attribute Details

#stringObject

Returns the value of attribute string.



3
4
5
# File 'lib/org/markup.rb', line 3

def string
  @string
end

Instance Method Details

#apply(string = @string) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/org/markup.rb', line 9

def apply(string = @string)
  self.string = string

  parent = RootToken.new(:root, nil)
  scanner = StringScanner.new(self.string)
  state = State.new(@scope, parent, scanner)

  until scanner.eos?
    pos = scanner.pos
    state.step
    raise("Didn't move: %p" % scanner) if pos == scanner.pos
  end

  return parent
end

#scope(name, options = {}) {|@scope| ... } ⇒ Object

Yields:



25
26
27
28
# File 'lib/org/markup.rb', line 25

def scope(name, options = {}, &block)
  @scope = Scope.new(name, options)
  yield(@scope)
end