module Condenser::ParseHelpers
Attributes
matched[RW]
Public Instance Methods
current_line()
click to toggle source
# File lib/condenser/helpers/parse_helpers.rb, line 45 def current_line start = (@source.rindex(/(\n|\z)/, @old_index) || 0) + 1 uptop = @source.index(/(\n|\z)/, @index) || (@old_index + @matched.length) @source[start..uptop] end
cursor()
click to toggle source
# File lib/condenser/helpers/parse_helpers.rb, line 51 def cursor start = (@source.rindex("\n", @old_index) || 0) + 1 uptop = @source.index("\n", @index) || (@old_index + @matched.length) lineno = @source[0..start].count("\n") + 1 "#{lineno.to_s.rjust(4)}: " + @source[start..uptop] + "\n #{'-'* (@index-1-start)}#{'^'*(@matched.length)}" end
eos?()
click to toggle source
# File lib/condenser/helpers/parse_helpers.rb, line 5 def eos? @index >= @source.size end
forward(by=1)
click to toggle source
# File lib/condenser/helpers/parse_helpers.rb, line 30 def forward(by=1) @index += by end
next_word()
click to toggle source
# File lib/condenser/helpers/parse_helpers.rb, line 40 def next_word nw = @source.match(/\s*(\S+)/, @index) nw.nil? ? nil : nw[1] end
pre_match()
click to toggle source
# File lib/condenser/helpers/parse_helpers.rb, line 22 def pre_match @source[@old_index...(@index-@matched.size)] end
rewind(by=1)
click to toggle source
# File lib/condenser/helpers/parse_helpers.rb, line 26 def rewind(by=1) @index -= by end
scan_until(r)
click to toggle source
# File lib/condenser/helpers/parse_helpers.rb, line 9 def scan_until(r) index = @source.index(r, @index) match = @source.match(r, @index) if match @matched = match.to_s @old_index = @index @index = index + @matched.size else @matched = nil end match end
seek(pos)
click to toggle source
# File lib/condenser/helpers/parse_helpers.rb, line 34 def seek(pos) @old_index = nil @matched = nil @index = pos end