Class: Antlr4ruby::RuleContext
- Inherits:
-
Object
- Object
- Antlr4ruby::RuleContext
- Defined in:
- lib/antlr4ruby/rule_context.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#invoking_state ⇒ Object
Returns the value of attribute invoking_state.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #depth ⇒ Object
- #enter_rule(listener) ⇒ Object
- #exit_rule(listener) ⇒ Object
- #get_alt_number ⇒ Object
- #get_child(i) ⇒ Object
- #get_child_count ⇒ Object
- #get_parent ⇒ Object
- #get_payload ⇒ Object
- #get_rule_context ⇒ Object
- #get_rule_index ⇒ Object
- #get_source_interval ⇒ Object
- #get_text ⇒ Object
-
#initialize(parent = nil, invoking_state = -1)) ⇒ RuleContext
constructor
A new instance of RuleContext.
- #is_empty? ⇒ Boolean
- #set_alt_number(alt_number) ⇒ Object
- #set_parent(parent) ⇒ Object
- #to_s(recognizer: nil, rule_names: [], stop: nil) ⇒ Object
- #to_string_tree(recognizer: nil, rule_names: []) ⇒ Object
Constructor Details
#initialize(parent = nil, invoking_state = -1)) ⇒ RuleContext
Returns a new instance of RuleContext.
7 8 9 10 |
# File 'lib/antlr4ruby/rule_context.rb', line 7 def initialize(parent = nil, invoking_state = -1) super() @parent, @invoking_state = parent, invoking_state end |
Instance Attribute Details
#invoking_state ⇒ Object
Returns the value of attribute invoking_state.
5 6 7 |
# File 'lib/antlr4ruby/rule_context.rb', line 5 def invoking_state @invoking_state end |
#parent ⇒ Object
Returns the value of attribute parent.
5 6 7 |
# File 'lib/antlr4ruby/rule_context.rb', line 5 def parent @parent end |
Instance Method Details
#accept(visitor) ⇒ Object
82 83 84 |
# File 'lib/antlr4ruby/rule_context.rb', line 82 def accept(visitor) visitor.visit_children(self) end |
#depth ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/antlr4ruby/rule_context.rb', line 12 def depth n = 0 p = self while p p = p.parent n += 1 end n end |
#enter_rule(listener) ⇒ Object
104 |
# File 'lib/antlr4ruby/rule_context.rb', line 104 def enter_rule(listener) end |
#exit_rule(listener) ⇒ Object
106 |
# File 'lib/antlr4ruby/rule_context.rb', line 106 def exit_rule(listener) end |
#get_alt_number ⇒ Object
62 63 64 |
# File 'lib/antlr4ruby/rule_context.rb', line 62 def get_alt_number ATN.INVALID_ALT_NUMBER end |
#get_child(i) ⇒ Object
74 |
# File 'lib/antlr4ruby/rule_context.rb', line 74 def get_child(i) nil; end |
#get_child_count ⇒ Object
77 78 79 |
# File 'lib/antlr4ruby/rule_context.rb', line 77 def get_child_count 0 end |
#get_parent ⇒ Object
37 38 39 |
# File 'lib/antlr4ruby/rule_context.rb', line 37 def get_parent @parent end |
#get_payload ⇒ Object
42 43 44 |
# File 'lib/antlr4ruby/rule_context.rb', line 42 def get_payload self end |
#get_rule_context ⇒ Object
32 33 34 |
# File 'lib/antlr4ruby/rule_context.rb', line 32 def get_rule_context self end |
#get_rule_index ⇒ Object
58 59 60 |
# File 'lib/antlr4ruby/rule_context.rb', line 58 def get_rule_index -1 end |
#get_source_interval ⇒ Object
27 28 29 |
# File 'lib/antlr4ruby/rule_context.rb', line 27 def get_source_interval (-1)..(-2) end |
#get_text ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/antlr4ruby/rule_context.rb', line 47 def get_text return '' if get_child_count == 0 result = '' get_child_count.times do |i| child = get_child(i) result += child.get_text if child end result end |
#is_empty? ⇒ Boolean
22 23 24 |
# File 'lib/antlr4ruby/rule_context.rb', line 22 def is_empty? @invoking_state == -1 end |
#set_alt_number(alt_number) ⇒ Object
66 |
# File 'lib/antlr4ruby/rule_context.rb', line 66 def set_alt_number(alt_number) end |
#set_parent(parent) ⇒ Object
69 70 71 |
# File 'lib/antlr4ruby/rule_context.rb', line 69 def set_parent(parent) @parent = parent end |
#to_s(recognizer: nil, rule_names: [], stop: nil) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/antlr4ruby/rule_context.rb', line 90 def to_s(recognizer:nil , rule_names:[], stop:nil ) # 多余的形式舍弃掉 rule_names = recognizer.get_rule_names if recognizer p = self result = '' while p && !p.equal?(stop) rule_index = p.get_rule_index rule_name = rule_names[rule_index] || rule_index.to_s result += rule_name + ' ' p = p.parent end result end |
#to_string_tree(recognizer: nil, rule_names: []) ⇒ Object
86 87 88 |
# File 'lib/antlr4ruby/rule_context.rb', line 86 def to_string_tree(recognizer:nil, rule_names: []) Trees.to_string_tree(self, recognizer:recognizer, rule_names: rule_names) end |