Class: Treetop::Runtime::SyntaxNode
- Inherits:
-
Object
- Object
- Treetop::Runtime::SyntaxNode
show all
- Defined in:
- lib/logstash/config/config_ast.rb,
lib/logstash/config/config_ast.rb more...
Overview
Monkeypatch Treetop::Runtime::SyntaxNode’s inspect method to skip any Whitespace or SyntaxNodes with no children.
Instance Method Summary
collapse
Instance Method Details
permalink
#_inspect(indent = "") ⇒ Object
[View source]
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
|
# File 'lib/logstash/config/config_ast.rb', line 562
def _inspect(indent="")
em = extension_modules
interesting_methods = methods-[em.last ? em.last.methods : nil]-self.class.instance_methods
im = interesting_methods.size > 0 ? " (#{interesting_methods.join(",")})" : ""
tv = text_value
tv = "...#{tv[-20..-1]}" if tv.size > 20
indent +
self.class.to_s.sub(/.*:/,'') +
em.map{|m| "+"+m.to_s.sub(/.*:/,'')}*"" +
" offset=#{interval.first}" +
", #{tv.inspect}" +
im +
(elements && elements.size > 0 ?
":" +
(elements.select { |e| !e.is_a?(LogStash::Config::AST::Whitespace) && e.elements && e.elements.size > 0 }||[]).map{|e|
begin
"\n"+e.inspect(indent+" ")
rescue "\n"+indent+" "+e.inspect
end
}.join("") :
""
)
end
|
[View source]
8
9
10
11
|
# File 'lib/logstash/config/config_ast.rb', line 8
def compile
return "" if elements.nil?
return elements.collect(&:compile).reject(&:empty?).join("")
end
|
[View source]
13
14
15
16
17
18
|
# File 'lib/logstash/config/config_ast.rb', line 13
def get_meta(key)
@ast_metadata ||= {}
return @ast_metadata[key] if @ast_metadata[key]
return self.parent.get_meta(key) if self.parent
nil
end
|
permalink
#recurse(e, depth = 0, &block) ⇒ Object
Traverse the syntax tree recursively. The order should respect the order of the configuration file as it is read and written by humans (and the order in which it is parsed).
[View source]
28
29
30
31
32
|
# File 'lib/logstash/config/config_ast.rb', line 28
def recurse(e, depth=0, &block)
r = block.call(e, depth)
e.elements.each { |e| recurse(e, depth + 1, &block) } if r && e.elements
nil
end
|
permalink
#recursive_inject(results = [], &block) ⇒ Object
[View source]
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/logstash/config/config_ast.rb', line 34
def recursive_inject(results=[], &block)
if !elements.nil?
elements.each do |element|
if block.call(element)
results << element
else
element.recursive_inject(results, &block)
end
end
end
return results
end
|
permalink
#recursive_inject_parent(results = [], &block) ⇒ Object
[View source]
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/logstash/config/config_ast.rb', line 57
def recursive_inject_parent(results=[], &block)
if !parent.nil?
if block.call(parent)
results << parent
else
parent.recursive_inject_parent(results, &block)
end
end
return results
end
|
permalink
#recursive_select(klass) ⇒ Object
When Treetop parses the configuration file it will generate a tree, the generated tree will contain a few ‘Empty` nodes to represent the actual space/tab or newline in the file. Some of theses node will point to our concrete class. To fetch a specific types of object we need to follow each branch and ignore the empty nodes.
[View source]
53
54
55
|
# File 'lib/logstash/config/config_ast.rb', line 53
def recursive_select(klass)
return recursive_inject { |e| e.is_a?(klass) }
end
|
permalink
#recursive_select_parent(results = [], klass) ⇒ Object
[View source]
68
69
70
|
# File 'lib/logstash/config/config_ast.rb', line 68
def recursive_select_parent(results=[], klass)
return recursive_inject_parent(results) { |e| e.is_a?(klass) }
end
|
[View source]
20
21
22
23
|
# File 'lib/logstash/config/config_ast.rb', line 20
def set_meta(key, value)
@ast_metadata ||= {}
@ast_metadata[key] = value
end
|