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

Instance Attribute Summary

Attributes included from Scoped

#scope

Instance Method Summary collapse

Methods included from Scoped

#macro?, #process_scope, #start_of_line?

Methods inherited from LexerBase

#empty?, #file, #line, #peek_nonspace

Methods included from CTokenizer

check_string, check_token, #collect, create_newlines, #each, error, #error, join, line_count, #parse_error, split, split_token, #to_a, #token_error, #warning, whitespace?

Constructor Details

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

Returns a new instance of SkipMacros.



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

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

Instance Method Details

#shiftObject



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

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