class Antlr4::Runtime::ParserRuleContext

Constants

EMPTY

Attributes

children[RW]
exception[RW]
start[RW]
stop[RW]

Public Class Methods

new(parent = nil, invoking_state_number = nil) click to toggle source
Calls superclass method
# File lib/antlr4/runtime/parser_rule_context.rb, line 31
def initialize(parent = nil, invoking_state_number = nil)
  super(parent, invoking_state_number)
  @children = []
end

Public Instance Methods

add_any_child(t) click to toggle source
# File lib/antlr4/runtime/parser_rule_context.rb, line 42
def add_any_child(t)
  @children = [] if @children.nil?
  @children << t
  t
end
add_child_rule_invocation(rule_invocation) click to toggle source
# File lib/antlr4/runtime/parser_rule_context.rb, line 48
def add_child_rule_invocation(rule_invocation)
  add_any_child(rule_invocation)
end
add_child_terminal_node(t) click to toggle source
# File lib/antlr4/runtime/parser_rule_context.rb, line 52
def add_child_terminal_node(t)
  t.parent = self
  add_any_child(t)
end
add_error_node(error_node) click to toggle source
# File lib/antlr4/runtime/parser_rule_context.rb, line 57
def add_error_node(error_node)
  error_node.parent = self
  add_any_child(error_node)
end
child(ctxType, i) click to toggle source
# File lib/antlr4/runtime/parser_rule_context.rb, line 70
def child(ctxType, i)
  return nil if @children.nil? || i < 0 || i >= @children.length

  j = -1 # what element have we found with ctx_type?
  k = 0
  while k < @children.length
    o = @children[k]
    unless o.class.name.end_with? ctxType
      k += 1
      next
    end

    j += 1
    return o if j == i
    k += 1
  end
  nil
end
child_at(i) click to toggle source
# File lib/antlr4/runtime/parser_rule_context.rb, line 66
def child_at(i)
  !@children.nil? && i >= 0 && i < @children.length ? @children[i] : nil
end
child_count() click to toggle source
# File lib/antlr4/runtime/parser_rule_context.rb, line 165
def child_count
  !@children.nil? ? @children.length : 0
end
copy_from(ctx) click to toggle source
# File lib/antlr4/runtime/parser_rule_context.rb, line 11
def copy_from(ctx)
  @parent = ctx.parent
  @invoking_state = ctx.invoking_state

  @start = ctx.start
  @stop = ctx.stop

  # copy any error nodes to alt label node
  unless ctx.children.nil?
    @children = []
    # reset parent pointer for any error nodes
    i = 0
    while i < ctx.children.length
      child = ctx.children[i]
      add_child_terminal_node(child) if child.is_a? ErrorNode
      i += 1
    end
  end
end
enter_rule(_listener) click to toggle source
# File lib/antlr4/runtime/parser_rule_context.rb, line 36
def enter_rule(_listener)
end
exit_rule(_listener) click to toggle source
# File lib/antlr4/runtime/parser_rule_context.rb, line 39
def exit_rule(_listener)
end
remove_last_child() click to toggle source
# File lib/antlr4/runtime/parser_rule_context.rb, line 62
def remove_last_child
  @children.delete_at(-1) unless @children.nil?
end
rule_context(ctx_type, i) click to toggle source
# File lib/antlr4/runtime/parser_rule_context.rb, line 139
def rule_context(ctx_type, i)
  child(ctx_type, i)
end
rule_contexts(ctxType) click to toggle source
# File lib/antlr4/runtime/parser_rule_context.rb, line 143
def rule_contexts(ctxType)
  return [] if @children.nil?

  contexts = nil
  i = 0
  while i < @children.length
    o = @children[i]
    unless o.class.name.end_with? ctxType
      i += 1
      next
    end

    contexts = [] if contexts.nil?
    contexts << o
    i += 1
  end

  return [] if contexts.nil?

  contexts
end
source_interval() click to toggle source
# File lib/antlr4/runtime/parser_rule_context.rb, line 169
def source_interval
  return Interval.invalid if @start.nil?
  if @stop.nil? || @stop.token_index < @start.token_index
    return Interval.of(@start.token_index, @start.token_index - 1) # empty
  end

  Interval.of(@start.token_index, @stop.token_index)
end
to_info_string(recognizer) click to toggle source
# File lib/antlr4/runtime/parser_rule_context.rb, line 178
def to_info_string(recognizer)
  rules = recognizer.rule_invocation_stack2(self)
  rules.reverse!
  'ParserRuleContext' + rules + '' + 'start=' + @start + ', stop=' + @stop + 'end'
end
token(ttype, i) click to toggle source
# File lib/antlr4/runtime/parser_rule_context.rb, line 89
def token(ttype, i)
  return nil if @children.nil? || i < 0 || i >= @children.length

  j = -1 # what token with ttype have we found?
  k = 0
  while k < @children.length
    o = @children[k]
    unless o.is_a? TerminalNode
      k += 1
      next
    end

    tnode = o
    symbol = tnode.symbol
    if !symbol.nil? && symbol.type == ttype
      j += 1
      return tnode if j == i
    end
    k += 1
  end

  nil
end
tokens(ttype) click to toggle source
# File lib/antlr4/runtime/parser_rule_context.rb, line 113
def tokens(ttype)
  return [] if @children.nil?

  tokens = nil
  i = 0
  while i < @children.length
    o = @children[i]
    unless o.is_a? TerminalNode
      i += 1
      next
    end

    tnode = o
    symbol = tnode.symbol
    if symbol.type == ttype
      tokens = [] if tokens.nil?
      tokens << tnode
    end
    i += 1
  end

  return [] if tokens.nil?

  tokens
end