Class: ANTLR3::ChainedToken

Inherits:
Struct
  • Object
show all
Includes:
Token
Defined in:
lib/antlr3/token/linked.rb,
lib/antlr3/token/linked.rb

Constant Summary

Constants included from Constants

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

Instance Attribute Summary

Attributes included from Token

#channel, #column, #index, #input, #line, #start, #stop, #text, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Token

#<=>, #=~, #concrete?, #hidden?, #hide!, #imaginary?, #initialize_copy, #inspect, #name, #pretty_print, #range, #source_name, #source_text, #to_i, #to_s

Constructor Details

#initialize(type = nil, channel = DEFAULT_CHANNEL, text = nil, input = nil, start = nil, stop = nil, index = 0, line = 0, column = -1,, pred = nil, succ = nil) ⇒ ChainedToken


22
23
24
25
26
27
28
29
# File 'lib/antlr3/token/linked.rb', line 22

def initialize( type = nil, channel = DEFAULT_CHANNEL, text = nil,
               input = nil, start = nil, stop = nil, index = 0,
               line = 0, column = -1, pred = nil, succ = nil )
  super
  block_given? and yield( self )
  self.text.nil? && self.start && self.stop and
    self.text = self.input.substring( self.start, self.stop )
end

Class Method Details

.create_eof(tail_token, channel) ⇒ Object


18
19
20
# File 'lib/antlr3/token/linked.rb', line 18

def self.create_eof( tail_token, channel )
  tail_token.connect_to( new( EOF, channel ) )
end

.from_token(general_token, prev = nil) ⇒ Object


11
12
13
14
15
16
# File 'lib/antlr3/token/linked.rb', line 11

def self.from_token( general_token, prev = nil )
  new( token.type, token.channel,
      token.text ? token.text.clone : nil,
      token.input, token.start, token.stop,
      -1, token.line, token.column, prev )
end

Instance Method Details

#<<(general_token) ⇒ Object


53
54
55
56
57
# File 'lib/antlr3/token/linked.rb', line 53

def <<( general_token )
  t = self.class.from_token( general_token, self )
  t.index = index + 1
  self.succ = t
end

#connect_to(token) ⇒ Object


59
60
61
62
63
# File 'lib/antlr3/token/linked.rb', line 59

def connect_to( token )
  token.prev = self
  token.index = index + 1
  self.succ = token
end

#deleteObject


65
66
67
68
69
70
71
# File 'lib/antlr3/token/linked.rb', line 65

def delete
  a, b = self.pred, self.succ
  self.succ = self.pred = nil
  a.succ = b if a
  b.prev = a if b
  return b
end

#eof?Boolean


49
50
51
# File 'lib/antlr3/token/linked.rb', line 49

def eof?
  type == EOF
end

#head?Boolean


73
74
75
# File 'lib/antlr3/token/linked.rb', line 73

def head?
  pred.nil?
end

#tail?Boolean


77
78
79
# File 'lib/antlr3/token/linked.rb', line 77

def tail?
  succ.nil?
end

#walkObject


31
32
33
34
35
36
37
38
# File 'lib/antlr3/token/linked.rb', line 31

def walk
  block_given? or return enum_for( __method__ )
  ptr = self
  begin
    yield( ptr )
    ptr = succ
  end while ptr
end

#walk_backwardObject


40
41
42
43
44
45
46
47
# File 'lib/antlr3/token/linked.rb', line 40

def walk_backward
  block_given? or return enum_for( __method__ )
  ptr = self
  begin
    yield( ptr )
    ptr = pred
  end while ptr
end