Class: Wool::LexicalAnalysis::Token

Inherits:
Struct
  • Object
show all
Defined in:
lib/wool/analysis/lexical_analysis.rb

Overview

This is a wrapper class around the tokens returned by Ripper. Since the tokens are just arrays, this class lets us use nice mnemonics with almost zero runtime overhead.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Token

Unpacks the token from Ripper and breaks it into its separate components.

Parameters:

  • token (Array<Array<Integer, Integer>, Symbol, String>)

    the token from Ripper that we’re wrapping



14
15
16
17
# File 'lib/wool/analysis/lexical_analysis.rb', line 14

def initialize(token)
  pos, self.type, self.body = token
  self.line, self.col = pos
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



9
10
11
# File 'lib/wool/analysis/lexical_analysis.rb', line 9

def body
  @body
end

#colObject

Returns the value of attribute col

Returns:

  • (Object)

    the current value of col



9
10
11
# File 'lib/wool/analysis/lexical_analysis.rb', line 9

def col
  @col
end

#lineObject

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



9
10
11
# File 'lib/wool/analysis/lexical_analysis.rb', line 9

def line
  @line
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



9
10
11
# File 'lib/wool/analysis/lexical_analysis.rb', line 9

def type
  @type
end