class SrcLexer::Lexer::StringIterator
Public Class Methods
new(str)
click to toggle source
# File lib/src_lexer.rb, line 63 def initialize(str) @str = str @current_pos = PosInfo.new @marked_pos = PosInfo.new mark_clear() end
Public Instance Methods
<(index)
click to toggle source
# File lib/src_lexer.rb, line 120 def <(index) @current_pos.index < index end
is(target_string)
click to toggle source
# File lib/src_lexer.rb, line 80 def is(target_string) return false if target_string.length.zero? end_pos = (@current_pos.index + target_string.length - 1) @str[@current_pos.index..end_pos] == target_string end
is_in(target_list)
click to toggle source
# File lib/src_lexer.rb, line 86 def is_in(target_list) target_list.find { |target| is(target) } != nil end
is_white_space()
click to toggle source
# File lib/src_lexer.rb, line 124 def is_white_space /\s/.match(@str[@current_pos.index]) end
mark_clear()
click to toggle source
# File lib/src_lexer.rb, line 70 def mark_clear @marked_pos.index = -1 @marked_pos.line_no = 0 @marked_pos.char_no = 0 end
mark_set()
click to toggle source
# File lib/src_lexer.rb, line 76 def mark_set @marked_pos = @current_pos.clone end
marked?()
click to toggle source
# File lib/src_lexer.rb, line 128 def marked? @marked_pos.index != -1 end
move_next()
click to toggle source
# File lib/src_lexer.rb, line 90 def move_next if /\n/.match @str[@current_pos.index] @current_pos.line_no += 1 @current_pos.char_no = 1 else @current_pos.char_no += 1 end @current_pos.index += 1 end
move_to(target)
click to toggle source
# File lib/src_lexer.rb, line 106 def move_to(target) char_count_to_target = (@str[@current_pos.index..-1] =~ /#{Regexp.escape(target)}/m) + target.length - 1 chopped_string = @str[@current_pos.index..@current_pos.index + char_count_to_target] @current_pos.index += char_count_to_target match = /.*\n(.*)$/m.match(chopped_string) p match[1].length if match if match @current_pos.char_no = match[1].length else @current_pos.char_no += char_count_to_target end @current_pos.line_no += chopped_string.each_char.select{|char| /\n/.match char}.length end
move_to_the_end_of_the_line()
click to toggle source
# File lib/src_lexer.rb, line 100 def move_to_the_end_of_the_line char_count_to_the_end_of_the_line = (@str[@current_pos.index..-1] =~ /$/) - 1 @current_pos.index += char_count_to_the_end_of_the_line @current_pos.char_no += char_count_to_the_end_of_the_line end
shift()
click to toggle source
# File lib/src_lexer.rb, line 132 def shift result = [@str[@marked_pos.index..(@current_pos.index - 1)], @marked_pos.line_no, @marked_pos.char_no] mark_clear() return result end