Class: ABNF::Parser::Compiler::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/abnf/parser/compiler/token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, abnf = nil) ⇒ Token

Returns a new instance of Token.



8
9
10
11
# File 'lib/abnf/parser/compiler/token.rb', line 8

def initialize type, abnf=nil
  @abnf = abnf
  @type = type
end

Instance Attribute Details

#abnfObject (readonly)

Returns the value of attribute abnf.



5
6
7
# File 'lib/abnf/parser/compiler/token.rb', line 5

def abnf
  @abnf
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/abnf/parser/compiler/token.rb', line 6

def type
  @type
end

Instance Method Details

#==(other_token) ⇒ Object



13
14
15
16
17
18
# File 'lib/abnf/parser/compiler/token.rb', line 13

def == other_token
  return false unless other_token.respond_to? :abnf
  return false unless other_token.respond_to? :type

  self.abnf == other_token.abnf and self.type == other_token.type
end

#inspectObject



24
25
26
# File 'lib/abnf/parser/compiler/token.rb', line 24

def inspect
  "(#{type} #{abnf.inspect})"
end

#lexemeObject



20
21
22
# File 'lib/abnf/parser/compiler/token.rb', line 20

def lexeme
  abnf
end

#underscore_typeObject



28
29
30
# File 'lib/abnf/parser/compiler/token.rb', line 28

def underscore_type
  @underscore_type ||= type.downcase.gsub('-', '_')
end