Class: CTokenizer::SkipMacros

Inherits:
LexerBase show all
Includes:
Scoped
Defined in:
lib/dbc/ctokenizer.rb

Overview

Skips macro tokens - NOT lossy - converts macro into a single newline token

Constant Summary

Constants included from CTokenizer

EOF_TOKEN

Instance Attribute Summary

Attributes included from Scoped

#scope

Attributes inherited from LexerBase

#source

Instance Method Summary collapse

Methods included from Scoped

#macro?, #process_scope, #start_of_line?

Methods inherited from LexerBase

#empty?, #file, #line, #match?, #post_match, #scan

Methods included from CTokenizer

check_token, #collect, #each, #error, error, line_count, #parse_error, #to_a, #token_error, #warning, whitespace?

Constructor Details

#initialize(str, file = nil, line = 1) ⇒ SkipMacros

Returns a new instance of SkipMacros.



286
287
288
289
290
291
# File 'lib/dbc/ctokenizer.rb', line 286

def initialize(str, file=nil, line=1)
	super(str, file, line)
	@scope = 0
	@macro = false
	@start_line = true
end

Instance Method Details

#shiftObject



292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/dbc/ctokenizer.rb', line 292

def shift
	t = process_scope(super)
	if macro?
		start = self.line
		token = t[1].dup
		while macro? and not empty?
			t = process_scope(super)
			token << t[1]
		end
		self.error("expecting newline") unless empty? or t[0] == :NEWLINE
		t = [:NEWLINE, token.freeze].freeze
	end
	t
end