Class: Preprocessor::SourceTokens

Inherits:
Object
  • Object
show all
Includes:
CTokenizer
Defined in:
lib/caphir/define.rb

Constant Summary

Constants included from CTokenizer

CTokenizer::CP_RESERVED, CTokenizer::C_RESERVED, CTokenizer::EOF_TOKEN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CTokenizer

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

Constructor Details

#initialize(source) ⇒ SourceTokens

Returns a new instance of SourceTokens.



69
70
71
72
# File 'lib/caphir/define.rb', line 69

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

Instance Attribute Details

#start_lineObject (readonly)

Returns the value of attribute start_line.



74
75
76
# File 'lib/caphir/define.rb', line 74

def start_line
  @start_line
end

Instance Method Details

#add_source(source) ⇒ Object



76
77
78
79
# File 'lib/caphir/define.rb', line 76

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

#base?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/caphir/define.rb', line 89

def base?
	@tokens.length == 1
end

#empty?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/caphir/define.rb', line 93

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

#fileObject



97
98
99
# File 'lib/caphir/define.rb', line 97

def file
	@tokens.last.file
end

#file=(val) ⇒ Object



100
101
102
# File 'lib/caphir/define.rb', line 100

def file=(val)
	@tokens.last.file = val
end

#lineObject



104
105
106
# File 'lib/caphir/define.rb', line 104

def line
	@tokens.last.line
end

#line=(val) ⇒ Object



107
108
109
# File 'lib/caphir/define.rb', line 107

def line=(val)
	@tokens.last.line = val
end

#match?(regexp) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/caphir/define.rb', line 85

def match?(regexp)
	@tokens.last.match?(regexp)
end

#scan(regexp) ⇒ Object



81
82
83
# File 'lib/caphir/define.rb', line 81

def scan(regexp)
	@tokens.last.scan(regexp)
end

#shiftObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/caphir/define.rb', line 111

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
	t_sym = t[0]
	unless t_sym == :SPACE or t_sym == :COMMENT
		# spaces and comments don't effect @start_line
		@start_line = (t_sym == :NEWLINE)
	end
	t
end