Module: Preprocessor::Resolve

Included in:
Parser
Defined in:
lib/dbc/preprocessor.rb

Overview

this is a pretty ugly mix in - but it prevents some code duplication at the moment. uses @source, @macro_tokens, @resolving instance variables :(

Instance Method Summary collapse

Instance Method Details

#args_given?Boolean

Returns:

  • (Boolean)


93
94
95
96
97
98
99
# File 'lib/dbc/preprocessor.rb', line 93

def args_given?
	if @macro_tokens.empty?
		@source
	else
		@macro_tokens
	end .match?(/\s*\(/)
end

#resolve(t) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/dbc/preprocessor.rb', line 101

def resolve(t)
	sym = t[1]
	if t[0] == :IDENTIFIER and macro = @defines[sym] and not resolving?(sym)
		# if no parameters are given don't expand
		unless macro.takes_args? and not args_given?
			if @macro_tokens.empty?
				# don't resolve macro function parameters on the first pass
				add_tokens(macro.value(@source))
			else
				add_tokens(macro.value(self))
			end
			@resolving[sym] = true
			t = self.shift
			@resolving.delete(sym)
		end
	end
	t
end

#resolving?(t) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/dbc/preprocessor.rb', line 89

def resolving?(t)
	@resolving.member?(t)
end