Class: Daimon::Markdown::Parser
- Inherits:
-
Ripper
- Object
- Ripper
- Daimon::Markdown::Parser
- Defined in:
- lib/daimon/markdown/parser.rb
Constant Summary collapse
- KEYWORDS =
{ "nil" => nil, "true" => true, "false" => false }
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(src) ⇒ Parser
constructor
A new instance of Parser.
- #on_array(args) ⇒ Object
- #on_command(name, *args) ⇒ Object
- #on_const(name) ⇒ Object
- #on_fcall(name) ⇒ Object
- #on_float(value) ⇒ Object
- #on_int(value) ⇒ Object
- #on_kw(keyword) ⇒ Object
- #on_lbracket(*args) ⇒ Object
- #on_rbracket(*args) ⇒ Object
- #on_tstring_content(content) ⇒ Object
- #on_vcall(name) ⇒ Object
Constructor Details
#initialize(src) ⇒ Parser
Returns a new instance of Parser.
15 16 17 18 19 20 21 22 |
# File 'lib/daimon/markdown/parser.rb', line 15 def initialize(src) super @name = nil @args = [] @level = 0 @array = [] @arrays = {} end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
13 14 15 |
# File 'lib/daimon/markdown/parser.rb', line 13 def args @args end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/daimon/markdown/parser.rb', line 13 def name @name end |
Instance Method Details
#on_array(args) ⇒ Object
68 69 70 71 72 |
# File 'lib/daimon/markdown/parser.rb', line 68 def on_array(args) if @level == 0 @args << @arrays[0].first end end |
#on_command(name, *args) ⇒ Object
28 29 30 |
# File 'lib/daimon/markdown/parser.rb', line 28 def on_command(name, *args) @name = name end |
#on_const(name) ⇒ Object
60 61 62 |
# File 'lib/daimon/markdown/parser.rb', line 60 def on_const(name) @args << Object.const_get(name) end |
#on_fcall(name) ⇒ Object
32 33 34 |
# File 'lib/daimon/markdown/parser.rb', line 32 def on_fcall(name) @name = name end |
#on_float(value) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/daimon/markdown/parser.rb', line 52 def on_float(value) if @level == 0 @args << value.to_f else @arrays[@level] << value.to_f end end |
#on_int(value) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/daimon/markdown/parser.rb', line 44 def on_int(value) if @level == 0 @args << value.to_i else @arrays[@level] << value.to_i end end |
#on_kw(keyword) ⇒ Object
64 65 66 |
# File 'lib/daimon/markdown/parser.rb', line 64 def on_kw(keyword) @args << KEYWORDS[keyword] end |
#on_lbracket(*args) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/daimon/markdown/parser.rb', line 74 def on_lbracket(*args) if @level == 0 @arrays[0] = [] end @level += 1 @arrays[@level] = [] end |
#on_rbracket(*args) ⇒ Object
82 83 84 85 |
# File 'lib/daimon/markdown/parser.rb', line 82 def on_rbracket(*args) @arrays[@level - 1] << @arrays[@level] @level -= 1 end |
#on_tstring_content(content) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/daimon/markdown/parser.rb', line 36 def on_tstring_content(content) if @level == 0 @args << content else @arrays[@level] << content end end |
#on_vcall(name) ⇒ Object
24 25 26 |
# File 'lib/daimon/markdown/parser.rb', line 24 def on_vcall(name) @name = name end |