Class: Antlr4::Runtime::DFA

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(atn_start_state, decision = 0) ⇒ DFA

Returns a new instance of DFA



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/antlr4/runtime/dfa.rb', line 10

def initialize(atn_start_state, decision = 0)
  @atn_start_state = atn_start_state
  @decision = decision
  @states = {}

  @precedence_dfa = false
  if atn_start_state.is_a? StarLoopEntryState
    if atn_start_state.is_precedence_pecision
      @precedence_dfa = true
      precedence_state = DFAState.new(ATNConfigSet.new)
      precedence_state.edges = []
      precedence_state.is_accept_state = false
      precedence_state.requires_full_context = false
      @s0 = precedence_state
    end
  end

end

Instance Attribute Details

#atn_start_stateObject (readonly)

Returns the value of attribute atn_start_state



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

def atn_start_state
  @atn_start_state
end

#decisionObject (readonly)

Returns the value of attribute decision



6
7
8
# File 'lib/antlr4/runtime/dfa.rb', line 6

def decision
  @decision
end

#precedence_dfa(precedence_dfa) ⇒ Object (readonly)

Returns the value of attribute precedence_dfa



8
9
10
# File 'lib/antlr4/runtime/dfa.rb', line 8

def precedence_dfa
  @precedence_dfa
end

#s0Object

Returns the value of attribute s0



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

def s0
  @s0
end

#statesObject

Returns the value of attribute states



4
5
6
# File 'lib/antlr4/runtime/dfa.rb', line 4

def states
  @states
end

Instance Method Details

#get_statesObject



60
61
62
63
64
65
# File 'lib/antlr4/runtime/dfa.rb', line 60

def get_states
  result = @states.keys
  result.sort! {|i, j| i.state_number - j.state_number}

  result
end

#precedence_dfa?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/antlr4/runtime/dfa.rb', line 29

def precedence_dfa?
  @precedence_dfa
end

#precedence_start_state(precedence) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/antlr4/runtime/dfa.rb', line 33

def precedence_start_state(precedence)
  unless @precedence_dfa
    raise IllegalStateException, 'Only precedence DFAs may contain a precedence start state.'
  end

  # s0.edges is never nil for a precedence DFA
  return nil if precedence < 0 || precedence >= @s0.edges.length

  @s0.edges[precedence]
end

#precedence_start_state2(precedence, start_state) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/antlr4/runtime/dfa.rb', line 44

def precedence_start_state2(precedence, start_state)
  unless @precedence_dfa
    raise IllegalStateException, 'Only precedence DFAs may contain a precedence start state.'
  end

  return if precedence < 0

  @s0.edges[precedence] = start_state
end

#to_lexer_stringObject



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

def to_lexer_string
  return '' if @s0.nil?

  serializer = LexerDFASerializer.new(self)
  serializer.to_s
end

#to_sObject



67
68
69
# File 'lib/antlr4/runtime/dfa.rb', line 67

def to_s
  to_s2(VocabularyImpl.EMPTY_VOCABULARY)
end

#to_s1(token_names) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/antlr4/runtime/dfa.rb', line 71

def to_s1(token_names)
  return '' if @s0.nil?

  serializer = DFASerializer.new
  serializer.init_from_token_names(self, token_names)
  serializer.to_s
end

#to_s2(vocabulary) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/antlr4/runtime/dfa.rb', line 79

def to_s2(vocabulary)
  return '' if @s0.nil?

  serializer = DFASerializer.new
  serializer.init_from_vocabulary(self, vocabulary)
  serializer.to_s
end