Class: Yap::Shell::Parser::Lexer::Token

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/yap/shell/parser/lexer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, value, lineno:, attrs: {}) ⇒ Token

Returns a new instance of Token.



15
16
17
18
19
20
# File 'lib/yap/shell/parser/lexer.rb', line 15

def initialize(tag, value, lineno:,attrs:{})
  @tag = tag
  @value = value
  @lineno = lineno
  @attrs = attrs
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



13
14
15
# File 'lib/yap/shell/parser/lexer.rb', line 13

def attrs
  @attrs
end

#linenoObject (readonly)

Returns the value of attribute lineno.



13
14
15
# File 'lib/yap/shell/parser/lexer.rb', line 13

def lineno
  @lineno
end

#tagObject (readonly)

Returns the value of attribute tag.



13
14
15
# File 'lib/yap/shell/parser/lexer.rb', line 13

def tag
  @tag
end

#valueObject (readonly)

Returns the value of attribute value.



13
14
15
# File 'lib/yap/shell/parser/lexer.rb', line 13

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



22
23
24
25
26
# File 'lib/yap/shell/parser/lexer.rb', line 22

def <=>(other)
  return -1 if self.class != other.class
  return 0 if [tag, value, lineno, attrs] == [other.tag, other.value, other.lineno, other.attrs]
  -1
end

#inspectObject



28
29
30
# File 'lib/yap/shell/parser/lexer.rb', line 28

def inspect
  "#{tag.inspect} '#{value}' #{attrs.inspect}"
end

#lengthObject



36
37
38
# File 'lib/yap/shell/parser/lexer.rb', line 36

def length
  to_s.length
end

#to_sObject



32
33
34
# File 'lib/yap/shell/parser/lexer.rb', line 32

def to_s
  "Token(#{tag.inspect} #{value.inspect} on #{lineno} with #{attrs.inspect})"
end