Class: DaimonMarkdown::Parser
- Inherits:
-
Ripper
- Object
- Ripper
- DaimonMarkdown::Parser
- 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
-
#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_parse_error(message) ⇒ 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.
17 18 19 20 21 22 23 24 |
# File 'lib/daimon_markdown/parser.rb', line 17 def initialize(src) super @name = nil @args = [] @level = 0 @array = [] @arrays = {} end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
15 16 17 |
# File 'lib/daimon_markdown/parser.rb', line 15 def args @args end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/daimon_markdown/parser.rb', line 15 def name @name end |
Instance Method Details
#on_array(args) ⇒ Object
70 71 72 73 74 |
# File 'lib/daimon_markdown/parser.rb', line 70 def on_array(args) if @level == 0 @args << @arrays[0].first end end |
#on_command(name, *args) ⇒ Object
30 31 32 |
# File 'lib/daimon_markdown/parser.rb', line 30 def on_command(name, *args) @name = name end |
#on_const(name) ⇒ Object
62 63 64 |
# File 'lib/daimon_markdown/parser.rb', line 62 def on_const(name) @args << Object.const_get(name) end |
#on_fcall(name) ⇒ Object
34 35 36 |
# File 'lib/daimon_markdown/parser.rb', line 34 def on_fcall(name) @name = name end |
#on_float(value) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/daimon_markdown/parser.rb', line 54 def on_float(value) if @level == 0 @args << value.to_f else @arrays[@level] << value.to_f end end |
#on_int(value) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/daimon_markdown/parser.rb', line 46 def on_int(value) if @level == 0 @args << value.to_i else @arrays[@level] << value.to_i end end |
#on_kw(keyword) ⇒ Object
66 67 68 |
# File 'lib/daimon_markdown/parser.rb', line 66 def on_kw(keyword) @args << KEYWORDS[keyword] end |
#on_lbracket(*args) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/daimon_markdown/parser.rb', line 76 def on_lbracket(*args) if @level == 0 @arrays[0] = [] end @level += 1 @arrays[@level] = [] end |
#on_parse_error(message) ⇒ Object
89 90 91 |
# File 'lib/daimon_markdown/parser.rb', line 89 def on_parse_error() compile_error() end |
#on_rbracket(*args) ⇒ Object
84 85 86 87 |
# File 'lib/daimon_markdown/parser.rb', line 84 def on_rbracket(*args) @arrays[@level - 1] << @arrays[@level] @level -= 1 end |
#on_tstring_content(content) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/daimon_markdown/parser.rb', line 38 def on_tstring_content(content) if @level == 0 @args << content else @arrays[@level] << content end end |
#on_vcall(name) ⇒ Object
26 27 28 |
# File 'lib/daimon_markdown/parser.rb', line 26 def on_vcall(name) @name = name end |