Class: ANTLR3::AST::CommonErrorNode

Inherits:
CommonTree show all
Includes:
Constants, Error
Defined in:
lib/antlr3/tree.rb

Overview

Represents a series of erroneous tokens from a token stream input

Constant Summary

Constants included from Constants

Constants::BUILT_IN_TOKEN_NAMES, Constants::DEFAULT, Constants::DOWN, Constants::EOF, Constants::EOF_TOKEN, Constants::EOR_TOKEN_TYPE, Constants::HIDDEN, Constants::INVALID, Constants::INVALID_TOKEN, Constants::MEMO_RULE_FAILED, Constants::MEMO_RULE_UNKNOWN, Constants::MIN_TOKEN_TYPE, Constants::SKIP_TOKEN, Constants::UP

Instance Attribute Summary collapse

Attributes inherited from BaseTree

#parent

Attributes included from Tree

#child_index, #column, #line, #start_index, #stop_index, #token

Instance Method Summary collapse

Methods included from Error

EarlyExit, FailedPredicate, MismatchedNotSet, MismatchedRange, MismatchedSet, MismatchedToken, MismatchedTreeNode, MissingToken, NoViableAlternative, RewriteCardinalityError, RewriteEarlyExit, RewriteEmptyStream, UnwantedToken

Methods inherited from CommonTree

#column, #copy_node, #infer_boundaries, #initialize_copy, #line, #name, #pretty_print, #source_range, #start_index, #stop_index, #token_range, #unknown_boundaries?

Methods inherited from BaseTree

#add_child, #children, #delete_child, #detach, #first_with_type, #freshen, #inspect, #prune, #replace_children, #root?, #sanity_check, #set_child, #walk

Methods included from Tree

#ancestors, #depth, #each_ancestor, #has_child?, #leaf?, #root, #root?, #siblings, #walk

Methods inherited from Array

#pad, #pad!

Constructor Details

#initialize(input, start, stop, error) ⇒ CommonErrorNode

Returns a new instance of CommonErrorNode.


612
613
614
615
616
617
618
619
620
# File 'lib/antlr3/tree.rb', line 612

def initialize( input, start, stop, error )
  super( nil )
  stop = start if stop.nil? or
    ( stop.token_index < start.token_index and stop.type != EOF )
  @input = input
  @start = start
  @stop = stop
  @error = error
end

Instance Attribute Details

#errorObject

Returns the value of attribute error


610
611
612
# File 'lib/antlr3/tree.rb', line 610

def error
  @error
end

#inputObject

Returns the value of attribute input


610
611
612
# File 'lib/antlr3/tree.rb', line 610

def input
  @input
end

#startObject

Returns the value of attribute start


610
611
612
# File 'lib/antlr3/tree.rb', line 610

def start
  @start
end

#stopObject

Returns the value of attribute stop


610
611
612
# File 'lib/antlr3/tree.rb', line 610

def stop
  @stop
end

Instance Method Details

#flat_list?Boolean

Returns:

  • (Boolean)

622
623
624
# File 'lib/antlr3/tree.rb', line 622

def flat_list?
  return false
end

#textObject


630
631
632
633
634
635
636
637
638
639
640
641
# File 'lib/antlr3/tree.rb', line 630

def text
  case @start
  when Token
    i = @start.token_index
    j = ( @stop.type == EOF ) ? @input.size : @stop.token_index
    @input.to_s( i, j )            # <- the bad text
  when Tree
    @input.to_s( @start, @stop )   # <- the bad text
  else
    "<unknown>"
  end
end

#to_sObject


643
644
645
646
647
648
649
650
651
652
653
654
655
# File 'lib/antlr3/tree.rb', line 643

def to_s
  case @error
  when MissingToken
    "<missing type: #{ @error.missing_type }>"
  when UnwantedToken
    "<extraneous: #{ @error.token.inspect }, resync = #{ text }>"
  when MismatchedToken
    "<mismatched token: #{ @error.token.inspect }, resync = #{ text }>"
  when NoViableAlternative
    "<unexpected: #{ @error.token.inspect }, resync = #{ text }>"
  else "<error: #{ text }>"
  end
end

#typeObject


626
627
628
# File 'lib/antlr3/tree.rb', line 626

def type
  INVALID_TOKEN_TYPE
end