module Rugments::Indentation

shared methods for some indentation-sensitive lexers

Public Instance Methods

indentation(indent_str) click to toggle source

handle a single indented line

# File lib/rugments/util.rb, line 80
def indentation(indent_str)
  puts "    indentation #{indent_str.inspect}" if @debug
  puts "    block_indentation: #{@block_indentation.inspect}" if @debug
  @last_indentation = indent_str

  # if it's an indent and we know where to go next,
  # push that state.  otherwise, push content and
  # clear the block state.
  if @block_state &&
     indent_str.start_with?(@block_indentation) &&
     indent_str != @block_indentation

    push @block_state
  else
    @block_state = @block_indentation = nil
    push :content
  end
end
reset!() click to toggle source
Calls superclass method
# File lib/rugments/util.rb, line 66
def reset!
  super
  @block_state = @block_indentation = nil
end
starts_block(block_state) click to toggle source

push a state for the next indented block

# File lib/rugments/util.rb, line 72
def starts_block(block_state)
  @block_state = block_state
  @block_indentation = @last_indentation || ''
  puts "    starts_block #{block_state.inspect}" if @debug
  puts "    block_indentation: #{@block_indentation.inspect}" if @debug
end