class Tailor::Lexer::Token

Helper methods for tokens that are parsed by {Tailor::Lexer}.

Public Class Methods

new(the_token, options={}) click to toggle source

@param [String] the_token @param [Hash] options

Calls superclass method
# File lib/tailor/lexer/token.rb, line 15
def initialize(the_token, options={})
  super(the_token)
  @options = options
end

Public Instance Methods

contains_capital_letter?() click to toggle source

@return [Boolean]

# File lib/tailor/lexer/token.rb, line 52
def contains_capital_letter?
  self =~ /[A-Z]/
end
contains_hard_tab?() click to toggle source

@return [Boolean]

# File lib/tailor/lexer/token.rb, line 57
def contains_hard_tab?
  self =~ /\t/
end
continuation_keyword?() click to toggle source

Checks if self is in +{CONTINUATION_KEYWORDS}+.

@return [Boolean]

# File lib/tailor/lexer/token.rb, line 30
def continuation_keyword?
  CONTINUATION_KEYWORDS.include? self
end
do_is_for_a_loop?() click to toggle source

Checks if self is “do” and +@options is true.

@return [Boolean]

# File lib/tailor/lexer/token.rb, line 42
def do_is_for_a_loop?
  self == 'do' && @options[:loop_with_do]
end
ends_with_newline?() click to toggle source

@return [Boolean]

# File lib/tailor/lexer/token.rb, line 35
def ends_with_newline?
  self =~ /\n$/
end
fake_backslash_line_end?() click to toggle source

@return [Boolean]

# File lib/tailor/lexer/token.rb, line 105
def fake_backslash_line_end?
  self =~ /^# TAILOR REMOVED BACKSLASH\n?$/
end
keyword_to_indent?() click to toggle source

Checks if self is in +{KEYWORDS_TO_INDENT}+.

@return [Boolean]

# File lib/tailor/lexer/token.rb, line 23
def keyword_to_indent?
  KEYWORDS_TO_INDENT.include? self
end
modifier_keyword?() click to toggle source

Checks the current line to see if self is being used as a modifier.

@return [Boolean] True if there's a modifier in the current line that

is the same type as +token+.
# File lib/tailor/lexer/token.rb, line 65
def modifier_keyword?
  return false unless keyword_to_indent?

  line_of_text = @options[:full_line_of_text]
  log "Line of text: #{line_of_text}"

  catch(:result) do
    sexp_line = Ripper.sexp(line_of_text)

    if sexp_line.nil?
      msg = 'sexp line was nil.  '
      msg << 'Perhaps that line is part of a multi-line statement?'
      log msg
      log 'Trying again with the last char removed from the line...'
      line_of_text.chop!
      sexp_line = Ripper.sexp(line_of_text)
    end

    if sexp_line.nil?
      log 'sexp line was nil again.'
      log 'Trying 1 more time with the last char removed from the line...'
      line_of_text.chop!
      sexp_line = Ripper.sexp(line_of_text)
    end

    if sexp_line.is_a? Array
      log "sexp_line.flatten: #{sexp_line.flatten}"
      log "sexp_line.last.first: #{sexp_line.last.first}"

      begin
        throw(:result, sexp_line.flatten.compact.any? do |s|
          s == MODIFIERS[self]
        end)
      rescue NoMethodError
      end
    end
  end
end
screaming_snake_case?() click to toggle source

@return [Boolean]

# File lib/tailor/lexer/token.rb, line 47
def screaming_snake_case?
  self =~ /[A-Z].*_/
end