Class: CTokenizer::Lexer

Inherits:
Object
  • Object
show all
Includes:
CTokenizer
Defined in:
lib/dbc/ctokenizer.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(str, file = nil, line = 1) ⇒ Lexer

Returns a new instance of Lexer.



162
163
164
165
166
167
# File 'lib/dbc/ctokenizer.rb', line 162

def initialize(str, file=nil, line=1)
	CTokenizer.check_string(str)
	@rest = str
	@file = file
	@line = line
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



169
170
171
# File 'lib/dbc/ctokenizer.rb', line 169

def file
  @file
end

#lineObject (readonly)

Returns the value of attribute line.



169
170
171
# File 'lib/dbc/ctokenizer.rb', line 169

def line
  @line
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


181
182
183
# File 'lib/dbc/ctokenizer.rb', line 181

def empty?
	@rest.empty?
end

#peek_nonspaceObject



171
172
173
174
175
176
177
178
179
# File 'lib/dbc/ctokenizer.rb', line 171

def peek_nonspace
	t = nil
	tmp_rest = @rest # @rest is unchanged
	loop do
		t, tmp_rest = CTokenizer.split_token(tmp_rest)
		break unless CTokenizer.whitespace?(t)
	end
	t
end

#shiftObject



185
186
187
188
189
# File 'lib/dbc/ctokenizer.rb', line 185

def shift
	t, @rest = CTokenizer.split_token(@rest)
	@line += CTokenizer.line_count(t[1])
	t
end