Class: Antlr4ruby::RuleContext

Inherits:
Object
  • Object
show all
Defined in:
lib/antlr4ruby/rule_context.rb

Direct Known Subclasses

ParserRuleContext

Instance Attribute Summary collapse

Instance Method Summary collapse

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_stateObject

Returns the value of attribute invoking_state.



5
6
7
# File 'lib/antlr4ruby/rule_context.rb', line 5

def invoking_state
  @invoking_state
end

#parentObject

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

#depthObject



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_numberObject



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_countObject



77
78
79
# File 'lib/antlr4ruby/rule_context.rb', line 77

def get_child_count
  0
end

#get_parentObject



37
38
39
# File 'lib/antlr4ruby/rule_context.rb', line 37

def get_parent
  @parent
end

#get_payloadObject



42
43
44
# File 'lib/antlr4ruby/rule_context.rb', line 42

def get_payload
  self
end

#get_rule_contextObject



32
33
34
# File 'lib/antlr4ruby/rule_context.rb', line 32

def get_rule_context
  self
end

#get_rule_indexObject



58
59
60
# File 'lib/antlr4ruby/rule_context.rb', line 58

def get_rule_index
  -1
end

#get_source_intervalObject



27
28
29
# File 'lib/antlr4ruby/rule_context.rb', line 27

def get_source_interval
  (-1)..(-2)
end

#get_textObject



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

Returns:

  • (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