Class: Attentive::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/attentive/token.rb

Direct Known Subclasses

Entity, StringToken, Attentive::Tokens::Regexp

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pos = nil) ⇒ Token

Returns a new instance of Token.



5
6
7
# File 'lib/attentive/token.rb', line 5

def initialize(pos=nil)
  @begin = pos
end

Instance Attribute Details

#beginObject

Returns the value of attribute begin.



3
4
5
# File 'lib/attentive/token.rb', line 3

def begin
  @begin
end

Instance Method Details

#==(other) ⇒ Object



13
14
15
# File 'lib/attentive/token.rb', line 13

def ==(other)
  self.class == other.class
end

#ambiguous?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/attentive/token.rb', line 17

def ambiguous?
  false
end

#endObject



9
10
11
# File 'lib/attentive/token.rb', line 9

def end
  self.begin + to_s.length
end

#entity?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/attentive/token.rb', line 21

def entity?
  false
end

#eof?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/attentive/token.rb', line 33

def eof?
  false
end

#inspectObject



46
47
48
# File 'lib/attentive/token.rb', line 46

def inspect
  "<#{self.class.name ? self.class.name.split("::").last : "Entity"} #{to_s.inspect}#{" #{self.begin}" if self.begin}>"
end

#matches?(cursor) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
# File 'lib/attentive/token.rb', line 37

def matches?(cursor)
  if self == cursor.peek
    cursor.pop
    return true
  end

  false
end

#skippable?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/attentive/token.rb', line 29

def skippable?
  false
end

#whitespace?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/attentive/token.rb', line 25

def whitespace?
  false
end