Class: XfOOrth::Token

Inherits:
Object show all
Defined in:
lib/fOOrth/compiler/token.rb

Overview

A class used to hold vital info extracted from the source code.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeToken

Set up an empty token



13
14
15
16
# File 'lib/fOOrth/compiler/token.rb', line 13

def initialize
  @code = ''
  @tags = []
end

Instance Attribute Details

#codeObject (readonly)

The code fragment in this token.



10
11
12
# File 'lib/fOOrth/compiler/token.rb', line 10

def code
  @code
end

Instance Method Details

#add(text, tags = nil) ⇒ Object

Append some text/tags to the code_fragment.
Parameters

  • text - A string of code to be appended to this token.

  • tags - An optional array of tags to be added to this token.


Possible tag values:

  • :class - This token contains a class constant..

  • :immediate - The token is executed, even in compile modes.

  • :macro - This token contains an in-line macro.

  • :numeric - This token contains a numeric literal.

  • :procedure - This token contains a procedure literal.

  • :string - This token contains a string literal.

  • :stub - This token contains a stub spec.

  • :temp - This token contains code from a temporary spec.

  • none - Nothing special here. Move along, move along.



32
33
34
35
36
# File 'lib/fOOrth/compiler/token.rb', line 32

def add(text, tags=nil)
  @code << text
  @tags.concat(tags).uniq! if tags
  self
end

#has_tag?(value) ⇒ Boolean

Does this token have the specified tag value?

Returns:

  • (Boolean)


39
40
41
# File 'lib/fOOrth/compiler/token.rb', line 39

def has_tag?(value)
  @tags.include?(value)
end

#to_sObject

As a string for debugging.



44
45
46
# File 'lib/fOOrth/compiler/token.rb', line 44

def to_s
  "Tags=#{@tags.inspect} Code=#{@code.inspect}"
end