Class: CTokenizer::SkipMacros

Inherits:
LexerBase show all
Includes:
Scoped
Defined in:
lib/caphir/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 included from Sourced

#source

Instance Method Summary collapse

Methods included from Scoped

#macro?, #process_scope, #start_of_line?

Methods included from Sourced

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

Methods included from CTokenizer

#collect, #each, #error, error, line_count, #parse_error, #to_a, #token_error, #unmatched_error, #warning

Constructor Details

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

Returns a new instance of SkipMacros.



277
278
279
280
281
282
# File 'lib/caphir/ctokenizer.rb', line 277

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

Instance Method Details

#shiftObject



283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/caphir/ctokenizer.rb', line 283

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