Class: Preprocessor::MacroTokens

Inherits:
Object
  • Object
show all
Defined in:
lib/caphir/define.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resolving = [], tokens = []) ⇒ MacroTokens

Returns a new instance of MacroTokens.



131
132
133
134
135
# File 'lib/caphir/define.rb', line 131

def initialize(resolving=[], tokens=[])
	# resolving is immutable
	@resolving = resolving.freeze
	@tokens = tokens
end

Instance Attribute Details

#resolvingObject (readonly)

Returns the value of attribute resolving.



137
138
139
# File 'lib/caphir/define.rb', line 137

def resolving
  @resolving
end

Instance Method Details

#add_function_macro(t_str, source) ⇒ Object

IMPORTANT - source is modified by the add_*_macro() methods



175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/caphir/define.rb', line 175

def add_function_macro(t_str, source)
	# macro should be unresolved, except for parameters
	# we must add t_str to all resolving lists in the macro
	unless source.empty?
		# IMPORTANT - add t_str to each resolving token
		add_tokens( source.collect! do |t|
			t[0] == :RESOLVING ? [:RESOLVING, t[1].dup << t_str] : t
		end )
		# add t_str to current resolving array
		@resolving = (@resolving.dup << t_str).freeze
	end
	self
end

#add_object_macro(t_str, source) ⇒ Object



189
190
191
192
193
194
195
# File 'lib/caphir/define.rb', line 189

def add_object_macro(t_str, source)
	unless source.empty?
		add_tokens(source)
		@resolving = (@resolving.dup << t_str).freeze
	end
	self
end

#args_given?Boolean

Returns:

  • (Boolean)


168
169
170
171
# File 'lib/caphir/define.rb', line 168

def args_given?
	t = self.peek_nonspace
	t and t[1] == '('
end

#empty?Boolean

Returns:

  • (Boolean)


150
151
152
# File 'lib/caphir/define.rb', line 150

def empty?
	@tokens.empty?
end

#peek_filterObject



154
155
156
157
158
159
# File 'lib/caphir/define.rb', line 154

def peek_filter
	@tokens.each do |t|
		return t unless t[0] == :RESOLVING
	end
	nil # is no non-resolving token
end

#peek_nonspaceObject



161
162
163
164
165
166
# File 'lib/caphir/define.rb', line 161

def peek_nonspace
	@tokens.each do |t|
		return t unless t[0] == :SPACE or t[0] == :RESOLVING
	end
	nil # is no non-space token
end

#resolving?(t_str) ⇒ Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/caphir/define.rb', line 139

def resolving?(t_str)
	@resolving.index(t_str)
end

#shiftObject

returns :RESOLVING tokens



144
145
146
147
148
# File 'lib/caphir/define.rb', line 144

def shift
	t = @tokens.shift || CTokenizer::EOF_TOKEN
	@resolving = t[1] if t[0] == :RESOLVING
	t
end