Class: Antlr4::Runtime::DFAState

Inherits:
Object
  • Object
show all
Defined in:
lib/antlr4/runtime/dfa_state.rb

Defined Under Namespace

Classes: PredPrediction

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x = nil) ⇒ DFAState

Returns a new instance of DFAState.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/antlr4/runtime/dfa_state.rb', line 19

def initialize(x = nil)
  @is_accept_state = false
  @edges = []
  @state_number = -1
  @_hash = nil

  if x.nil?
    @configs = ATNConfigSet.new
  elsif x.is_a?(ATNConfigSet)
    @configs = x
  else
    @state_number = x
  end
end

Instance Attribute Details

#configsObject

Returns the value of attribute configs.



5
6
7
# File 'lib/antlr4/runtime/dfa_state.rb', line 5

def configs
  @configs
end

#edgesObject

Returns the value of attribute edges.



7
8
9
# File 'lib/antlr4/runtime/dfa_state.rb', line 7

def edges
  @edges
end

#is_accept_stateObject

Returns the value of attribute is_accept_state.



9
10
11
# File 'lib/antlr4/runtime/dfa_state.rb', line 9

def is_accept_state
  @is_accept_state
end

#lexer_action_executorObject

Returns the value of attribute lexer_action_executor.



13
14
15
# File 'lib/antlr4/runtime/dfa_state.rb', line 13

def lexer_action_executor
  @lexer_action_executor
end

#predicatesObject

Returns the value of attribute predicates.



17
18
19
# File 'lib/antlr4/runtime/dfa_state.rb', line 17

def predicates
  @predicates
end

#predictionObject

Returns the value of attribute prediction.



11
12
13
# File 'lib/antlr4/runtime/dfa_state.rb', line 11

def prediction
  @prediction
end

#requires_full_contextObject

Returns the value of attribute requires_full_context.



15
16
17
# File 'lib/antlr4/runtime/dfa_state.rb', line 15

def requires_full_context
  @requires_full_context
end

#state_numberObject

Returns the value of attribute state_number.



3
4
5
# File 'lib/antlr4/runtime/dfa_state.rb', line 3

def state_number
  @state_number
end

Instance Method Details

#alt_setObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/antlr4/runtime/dfa_state.rb', line 56

def alt_set
  alts = Set.new
  unless @configs.nil?
    i = 0
    while i < @configs.length
      c = @configs[i]
      alts.add(c.alt)
      i += 1
    end
  end
  return nil if alts.empty?

  alts
end

#equals?(o) ⇒ Boolean

compare set of ATN configurations in this set with other

Returns:

  • (Boolean)


87
88
89
90
91
92
# File 'lib/antlr4/runtime/dfa_state.rb', line 87

def equals?(o) # compare set of ATN configurations in this set with other
  return true if self == o
  return false unless o.is_a? DFAState

  @configs.eql?(o.configs)
end

#hashObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/antlr4/runtime/dfa_state.rb', line 71

def hash
  return @_hash unless @_hash.nil?

  hash_code = RumourHash.calculate([configs.hash])

  unless @_hash.nil?
    if hash_code == @_hash
      puts 'Same hash_code for DFAState'
    else
      puts 'Different hash_code for DFAState'
    end
  end

  @_hash = hash_code
end

#initialize_configs(configs) ⇒ Object



52
53
54
# File 'lib/antlr4/runtime/dfa_state.rb', line 52

def initialize_configs(configs)
  @configs = configs
end

#initialize_state_number(stateNumber) ⇒ Object



48
49
50
# File 'lib/antlr4/runtime/dfa_state.rb', line 48

def initialize_state_number(stateNumber)
  @state_number = stateNumber
end

#to_sObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/antlr4/runtime/dfa_state.rb', line 94

def to_s
  buf = ''
  buf << @state_number.to_s << ':' << @configs.to_s
  if @is_accept_state
    buf << '=>'
    buf << if !@predicates.nil?
             @predicates.to_s
           else
             @prediction.to_s
           end
  end

  buf.to_s
end