Class: ANTLR3::RecognizerSharedState

Inherits:
Struct
  • Object
show all
Defined in:
lib/antlr3/recognizers.rb,
lib/antlr3/recognizers.rb

Overview

A big Struct-based class containing most of the data that makes up a recognizer's state. These attributes are externalized from the recognizer itself so that recognizer delegation (which occurs when you import other grammars into your grammar) can function; multiple recognizers can share a common state.

Structure Attributes

following

a stack that tracks follow sets for error recovery

error_recovery

a flag indicating whether or not the recognizer is in error recovery mode

last_error_index

the index in the input stream of the last error

backtracking

tracks the backtracking depth

rule_memory

if a grammar is compiled with the memoization option, this will be set to a hash mapping previously parsed rules to cached indices

syntax_errors

tracks the number of syntax errors seen so far

token

holds newly constructed tokens for lexer rules

token_start_position

the input stream index at which the token starts

token_start_line

the input stream line number at which the token starts

token_start_column

the input stream column at which the token starts

channel

the channel value of the target token

type

the type value of the target token

text

the text of the target token

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRecognizerSharedState

Returns a new instance of RecognizerSharedState


94
95
96
97
98
99
100
101
102
103
# File 'lib/antlr3/recognizers.rb', line 94

def initialize
  super( [], false, -1, 0, nil, 0, nil, -1 )
  # ^-- same as this --v 
  # self.following = []
  # self.error_recovery = false
  # self.last_error_index = -1
  # self.backtracking = 0
  # self.syntax_errors = 0
  # self.token_start_position = -1
end

Instance Attribute Details

#backtrackingObject

Returns the value of attribute backtracking

Returns:

  • (Object)

    the current value of backtracking


38
39
40
# File 'lib/antlr3/recognizers.rb', line 38

def backtracking
  @backtracking
end

#channelObject

Returns the value of attribute channel

Returns:

  • (Object)

    the current value of channel


38
39
40
# File 'lib/antlr3/recognizers.rb', line 38

def channel
  @channel
end

#error_recoveryObject

Returns the value of attribute error_recovery

Returns:

  • (Object)

    the current value of error_recovery


38
39
40
# File 'lib/antlr3/recognizers.rb', line 38

def error_recovery
  @error_recovery
end

#followingObject

Returns the value of attribute following

Returns:

  • (Object)

    the current value of following


38
39
40
# File 'lib/antlr3/recognizers.rb', line 38

def following
  @following
end

#last_error_indexObject

Returns the value of attribute last_error_index

Returns:

  • (Object)

    the current value of last_error_index


38
39
40
# File 'lib/antlr3/recognizers.rb', line 38

def last_error_index
  @last_error_index
end

#rule_memoryObject

Returns the value of attribute rule_memory

Returns:

  • (Object)

    the current value of rule_memory


38
39
40
# File 'lib/antlr3/recognizers.rb', line 38

def rule_memory
  @rule_memory
end

#syntax_errorsObject

Returns the value of attribute syntax_errors

Returns:

  • (Object)

    the current value of syntax_errors


38
39
40
# File 'lib/antlr3/recognizers.rb', line 38

def syntax_errors
  @syntax_errors
end

#textObject

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text


38
39
40
# File 'lib/antlr3/recognizers.rb', line 38

def text
  @text
end

#tokenObject

Returns the value of attribute token

Returns:

  • (Object)

    the current value of token


38
39
40
# File 'lib/antlr3/recognizers.rb', line 38

def token
  @token
end

#token_start_columnObject

Returns the value of attribute token_start_column

Returns:

  • (Object)

    the current value of token_start_column


38
39
40
# File 'lib/antlr3/recognizers.rb', line 38

def token_start_column
  @token_start_column
end

#token_start_lineObject

Returns the value of attribute token_start_line

Returns:

  • (Object)

    the current value of token_start_line


38
39
40
# File 'lib/antlr3/recognizers.rb', line 38

def token_start_line
  @token_start_line
end

#token_start_positionObject

Returns the value of attribute token_start_position

Returns:

  • (Object)

    the current value of token_start_position


38
39
40
# File 'lib/antlr3/recognizers.rb', line 38

def token_start_position
  @token_start_position
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type


38
39
40
# File 'lib/antlr3/recognizers.rb', line 38

def type
  @type
end

Instance Method Details

#reset!Object

restores all of the state variables to their respective initial default values


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/antlr3/recognizers.rb', line 108

def reset!
  self.following.clear
  self.error_recovery = false
  self.last_error_index = -1
  self.backtracking = 0
  self.rule_memory and rule_memory.clear
  self.syntax_errors = 0
  self.token = nil
  self.token_start_position = -1
  self.token_start_line = nil
  self.token_start_column = nil
  self.channel = nil
  self.type = nil
  self.text = nil
end