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.



189
190
191
# File 'lib/dbc/ctokenizer.rb', line 189

def scope
  @scope
end

Instance Method Details

#macro?Boolean

Returns:

  • (Boolean)


195
196
197
# File 'lib/dbc/ctokenizer.rb', line 195

def macro?
	@macro
end

#process_scope(t) ⇒ Object



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

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)


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

def start_of_line?
	@start_line
end