Class: Preprocessor::Tokens

Inherits:
Object
  • Object
show all
Includes:
CTokenizer
Defined in:
lib/dbc/preprocessor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(source) ⇒ Tokens

Returns a new instance of Tokens.



22
23
24
25
# File 'lib/dbc/preprocessor.rb', line 22

def initialize(source)
	@tokens = []
	self.add_source(source)
end

Instance Attribute Details

#start_lineObject (readonly)

Returns the value of attribute start_line.



27
28
29
# File 'lib/dbc/preprocessor.rb', line 27

def start_line
  @start_line
end

Instance Method Details

#add_source(source) ⇒ Object



29
30
31
32
# File 'lib/dbc/preprocessor.rb', line 29

def add_source(source)
	@tokens.push(source)
	@start_line = true # begining of file
end

#base?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/dbc/preprocessor.rb', line 34

def base?
	@tokens.length == 1
end

#empty?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/dbc/preprocessor.rb', line 38

def empty?
	@tokens.length == 1 and @tokens.last.empty?
end

#fileObject



42
43
44
# File 'lib/dbc/preprocessor.rb', line 42

def file
	@tokens.last.file
end

#lineObject



46
47
48
# File 'lib/dbc/preprocessor.rb', line 46

def line
	@tokens.last.line
end

#peek_nonspaceObject



50
51
52
53
54
55
56
57
# File 'lib/dbc/preprocessor.rb', line 50

def peek_nonspace
	t = nil
	@tokens.reverse_each do |tkns|
		t = tkns.peek_nonspace
		return t if t[0]
	end
	t
end

#shiftObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/dbc/preprocessor.rb', line 59

def shift
	t = @tokens.last.shift
	while !t[0] and @tokens.length > 1
		# we are done with the current file
		@tokens.pop
		t = @tokens.last.shift
	end # while
	case t[0]
		when :NEWLINE
			@start_line = true
		when :SPACE, :COMMENT, false
			# do nothing, keeping @start_line the same
		else
			@start_line = false;
	end # case
	t
end