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

CP_RESERVED, C_RESERVED, 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.



295
296
297
298
299
300
# File 'lib/dbc/ctokenizer.rb', line 295

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

Instance Method Details

#shiftObject



301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/dbc/ctokenizer.rb', line 301

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