Module: CTokenizer::Scoped

Included in:
SkipMacros, DBC::Parser
Defined in:
lib/dbc/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.



180
181
182
# File 'lib/dbc/ctokenizer.rb', line 180

def scope
  @scope
end

Instance Method Details

#macro?Boolean

Returns:

  • (Boolean)


186
187
188
# File 'lib/dbc/ctokenizer.rb', line 186

def macro?
	@macro
end

#process_scope(t) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/dbc/ctokenizer.rb', line 190

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

#start_of_line?Boolean

Returns:

  • (Boolean)


182
183
184
# File 'lib/dbc/ctokenizer.rb', line 182

def start_of_line?
	@start_line
end