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



77
78
79
80
# File 'lib/dbc/preprocessor.rb', line 77

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

#resolve(t) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/dbc/preprocessor.rb', line 84

def resolve(t)
	sym = t[1]
	if t[0] == :IDENTIFIER and macro = @defines[sym] and not resolving?(sym)
		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
	t
end

#resolving?(t) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/dbc/preprocessor.rb', line 81

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