Class: Ramekin::Token

Inherits:
Element show all
Defined in:
lib/ramekin/tokenizer.rb

Instance Attribute Summary collapse

Attributes inherited from Element

#channel, #macro_stack, #start_tick

Instance Method Summary collapse

Methods inherited from Element

make

Constructor Details

#initialize(type, *values) ⇒ Token

Returns a new instance of Token.



50
51
52
53
54
# File 'lib/ramekin/tokenizer.rb', line 50

def initialize(type, *values)
  @type = type
  @values = values
  @meta = {}
end

Instance Attribute Details

#loc_rangeObject

Returns the value of attribute loc_range.



69
70
71
# File 'lib/ramekin/tokenizer.rb', line 69

def loc_range
  @loc_range
end

#metaObject (readonly)

Returns the value of attribute meta.



68
69
70
# File 'lib/ramekin/tokenizer.rb', line 68

def meta
  @meta
end

#typeObject (readonly)

Returns the value of attribute type.



68
69
70
# File 'lib/ramekin/tokenizer.rb', line 68

def type
  @type
end

#valuesObject (readonly)

Returns the value of attribute values.



68
69
70
# File 'lib/ramekin/tokenizer.rb', line 68

def values
  @values
end

Instance Method Details

#componentsObject



56
57
58
# File 'lib/ramekin/tokenizer.rb', line 56

def components
  [self]
end

#dupObject



64
65
66
# File 'lib/ramekin/tokenizer.rb', line 64

def dup
  Token.new(type, *values).tap { |t| t.loc_range = loc_range }
end

#finObject



75
76
77
# File 'lib/ramekin/tokenizer.rb', line 75

def fin
  loc_range.fin
end

#inspectObject



91
92
93
# File 'lib/ramekin/tokenizer.rb', line 91

def inspect
  "t:#{repr}"
end

#reprObject



85
86
87
88
89
# File 'lib/ramekin/tokenizer.rb', line 85

def repr
  return repr_basic if macro_stack.empty?

  "#{repr_basic}[#{macro_stack.map(&:value).join(',')}]"
end

#repr_basicObject



79
80
81
82
83
# File 'lib/ramekin/tokenizer.rb', line 79

def repr_basic
  return @type if @values.empty?

  "#{@type}(#{@values.join(',')})"
end

#startObject



71
72
73
# File 'lib/ramekin/tokenizer.rb', line 71

def start
  loc_range.start
end

#valueObject



60
61
62
# File 'lib/ramekin/tokenizer.rb', line 60

def value
  @values[0]
end