Class: Rattler::Parsers::RuleSet
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Util::Node
#==, [], #attrs, #can_equal?, #child, #children, #each, #empty?, #eql?, #inspect, #method_missing, #name, #respond_to?, #same_contents?, #to_graphviz, #with_attrs!, #with_children
Constructor Details
#initialize(*args) ⇒ RuleSet
Returns a new instance of RuleSet.
18
19
20
21
22
|
# File 'lib/rattler/parsers/rule_set.rb', line 18
def initialize(*args)
super
@by_name = {}
children.each {|rule| @by_name[rule.name] = rule }
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Rattler::Util::Node
Class Method Details
.parsed(results, *_) ⇒ Object
14
15
16
|
# File 'lib/rattler/parsers/rule_set.rb', line 14
def self.parsed(results, *_) self.new(results)
end
|
Instance Method Details
#[](*args) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/rattler/parsers/rule_set.rb', line 34
def [](*args)
if args.length == 1 and args[0].is_a?(Symbol)
rule(args[0])
else
super
end
end
|
#analysis ⇒ Object
58
59
60
|
# File 'lib/rattler/parsers/rule_set.rb', line 58
def analysis
@analysis ||= Rattler::Grammar::Analysis.new(self)
end
|
#map_rules ⇒ Object
50
51
52
|
# File 'lib/rattler/parsers/rule_set.rb', line 50
def map_rules
self.with_rules rules.map {|_| yield _ }
end
|
#rule(name) ⇒ Object
30
31
32
|
# File 'lib/rattler/parsers/rule_set.rb', line 30
def rule(name)
@by_name[name]
end
|
#select_rules ⇒ Object
54
55
56
|
# File 'lib/rattler/parsers/rule_set.rb', line 54
def select_rules
self.with_rules rules.select {|_| yield _ }
end
|
#start_rule ⇒ Object
26
27
28
|
# File 'lib/rattler/parsers/rule_set.rb', line 26
def start_rule
attrs[:start_rule]
end
|
#with_attrs(new_attrs) ⇒ Object
42
43
44
|
# File 'lib/rattler/parsers/rule_set.rb', line 42
def with_attrs(new_attrs)
self.class.new(children, attrs.merge(new_attrs))
end
|
#with_rules(new_rules) ⇒ Object
46
47
48
|
# File 'lib/rattler/parsers/rule_set.rb', line 46
def with_rules(new_rules)
self.class.new(new_rules, attrs)
end
|