Class: Daimon::Markdown::Parser

Inherits:
Ripper
  • Object
show all
Defined in:
lib/daimon/markdown/parser.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

KEYWORDS =
{
  "nil" => nil,
  "true" => true,
  "false" => false
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src) ⇒ Parser

Returns a new instance of Parser.



18
19
20
21
22
23
24
25
# File 'lib/daimon/markdown/parser.rb', line 18

def initialize(src)
  super
  @name = nil
  @args = []
  @level = 0
  @array = []
  @arrays = {}
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



16
17
18
# File 'lib/daimon/markdown/parser.rb', line 16

def args
  @args
end

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/daimon/markdown/parser.rb', line 16

def name
  @name
end

Instance Method Details

#on_array(args) ⇒ Object



71
72
73
74
75
# File 'lib/daimon/markdown/parser.rb', line 71

def on_array(args)
  if @level == 0
    @args << @arrays[0].first
  end
end

#on_command(name, *args) ⇒ Object



31
32
33
# File 'lib/daimon/markdown/parser.rb', line 31

def on_command(name, *args)
  @name = name
end

#on_const(name) ⇒ Object



63
64
65
# File 'lib/daimon/markdown/parser.rb', line 63

def on_const(name)
  @args << Object.const_get(name)
end

#on_fcall(name) ⇒ Object



35
36
37
# File 'lib/daimon/markdown/parser.rb', line 35

def on_fcall(name)
  @name = name
end

#on_float(value) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/daimon/markdown/parser.rb', line 55

def on_float(value)
  if @level == 0
    @args << value.to_f
  else
    @arrays[@level] << value.to_f
  end
end

#on_int(value) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/daimon/markdown/parser.rb', line 47

def on_int(value)
  if @level == 0
    @args << value.to_i
  else
    @arrays[@level] << value.to_i
  end
end

#on_kw(keyword) ⇒ Object



67
68
69
# File 'lib/daimon/markdown/parser.rb', line 67

def on_kw(keyword)
  @args << KEYWORDS[keyword]
end

#on_lbracket(*args) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/daimon/markdown/parser.rb', line 77

def on_lbracket(*args)
  if @level == 0
    @arrays[0] = []
  end
  @level += 1
  @arrays[@level] = []
end

#on_parse_error(message) ⇒ Object



90
91
92
# File 'lib/daimon/markdown/parser.rb', line 90

def on_parse_error(message)
  compile_error(message)
end

#on_rbracket(*args) ⇒ Object



85
86
87
88
# File 'lib/daimon/markdown/parser.rb', line 85

def on_rbracket(*args)
  @arrays[@level - 1] << @arrays[@level]
  @level -= 1
end

#on_tstring_content(content) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/daimon/markdown/parser.rb', line 39

def on_tstring_content(content)
  if @level == 0
    @args << content
  else
    @arrays[@level] << content
  end
end

#on_vcall(name) ⇒ Object



27
28
29
# File 'lib/daimon/markdown/parser.rb', line 27

def on_vcall(name)
  @name = name
end