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

#add_tokens(tokens) ⇒ Object



86
87
88
89
# File 'lib/dbc/preprocessor.rb', line 86

def add_tokens(tokens)
	@macro_tokens =
		CTokenizer::Lexer.new(tokens, @source.file, @source.line).to_a + @macro_tokens
end

#peek_nonspaceObject



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

def peek_nonspace
	@macro_tokens.each do |t|
		return t unless CTokenizer.whitespace?(t)
	end # each
	@source.peek_nonspace
end

#resolve(t) ⇒ Object



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

def resolve(t)
	sym = t[1]
	if t[0] == :IDENTIFIER and macro = @defines[sym] and not resolving?(sym)
		# KLUDGE: if no parameters are given don't expand
		unless macro.takes_args? and peek_nonspace[1] != '('
			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)


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

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