Module: CTokenizer::Scoped

Included in:
SkipMacros, Caphir::SimpleCParser, DBC::Parser
Defined in:
lib/caphir/ctokenizer.rb

Overview

provides a way of keeping track of the current scope

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope


191
192
193
# File 'lib/caphir/ctokenizer.rb', line 191

def scope
  @scope
end

Instance Method Details

#macro?Boolean

Returns:

  • (Boolean)

197
198
199
# File 'lib/caphir/ctokenizer.rb', line 197

def macro?
	@macro
end

#process_scope(t) ⇒ Object


201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/caphir/ctokenizer.rb', line 201

def process_scope(t)
	t_sym = t.at(0)
	unless t_sym == :SPACE or t_sym == :COMMENT
		if t_sym == :NEWLINE
			@start_line = true
			@macro = false
		else
			unless @macro
				# these tokens are ignored if inside of a macro
				case t.at(1)
					when '#'
						@macro = @start_line
					when '{'
						@scope += 1
					when '}'
						@scope -= 1
				end
			end
			@start_line = false
		end
	end
	t
end

#start_of_line?Boolean

Returns:

  • (Boolean)

193
194
195
# File 'lib/caphir/ctokenizer.rb', line 193

def start_of_line?
	@start_line
end