Class: CodeRay::Scanners::Ruby::Patterns::StringState

Inherits:
Struct
  • Object
show all
Defined in:
lib/coderay/scanners/ruby/patterns.rb

Constant Summary collapse

CLOSING_PAREN =
OPENING_PAREN =
CLOSING_PAREN.invert
STRING_PATTERN =
Hash.new { |h, k|
  delim, interpreted = *k
  delim_pattern = Regexp.escape(delim)
  if closing_paren = CLOSING_PAREN[delim]
    delim_pattern = delim_pattern[0..-1] if defined? JRUBY_VERSION  # JRuby fix
    delim_pattern << Regexp.escape(closing_paren)
  end


  special_escapes =
    case interpreted
    when :regexp_symbols
      '| ' + REGEXP_SYMBOLS.source
    when :words
      '| \s'
    end

  h[k] =
    if interpreted and not delim == '#'
      / (?= [#{delim_pattern}\\] | \# [{$@] #{special_escapes} ) /mx
    else
      / (?= [#{delim_pattern}\\] #{special_escapes} ) /mx
    end
}
HEREDOC_PATTERN =
Hash.new { |h, k|
  delim, interpreted, indented = *k
  delim_pattern = Regexp.escape(delim.dup)
  delim_pattern = / \n #{ '(?>[\ \t]*)' if indented } #{ Regexp.new delim_pattern } $ /x
  h[k] =
    if interpreted
      / (?= #{delim_pattern}() | \\ | \# [{$@] ) /mx  # $1 set == end of heredoc
    else
      / (?= #{delim_pattern}() | \\ ) /mx
    end
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind, interpreted, delim, heredoc = false) ⇒ StringState

Returns a new instance of StringState.



214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/coderay/scanners/ruby/patterns.rb', line 214

def initialize kind, interpreted, delim, heredoc = false
  if heredoc
    pattern = HEREDOC_PATTERN[ [delim, interpreted, heredoc == :indented] ]
    delim  = nil
  else
    pattern = STRING_PATTERN[ [delim, interpreted] ]
    if paren = CLOSING_PAREN[delim]
      delim, paren = paren, delim
      paren_depth = 1
    end
  end
  super kind, interpreted, delim, heredoc, paren, paren_depth, pattern, :initial
end

Instance Attribute Details

#delimObject

Returns the value of attribute delim

Returns:

  • (Object)

    the current value of delim



164
165
166
# File 'lib/coderay/scanners/ruby/patterns.rb', line 164

def delim
  @delim
end

#heredocObject

Returns the value of attribute heredoc

Returns:

  • (Object)

    the current value of heredoc



164
165
166
# File 'lib/coderay/scanners/ruby/patterns.rb', line 164

def heredoc
  @heredoc
end

#interpretedObject

Returns the value of attribute interpreted

Returns:

  • (Object)

    the current value of interpreted



164
165
166
# File 'lib/coderay/scanners/ruby/patterns.rb', line 164

def interpreted
  @interpreted
end

#next_stateObject

Returns the value of attribute next_state

Returns:

  • (Object)

    the current value of next_state



164
165
166
# File 'lib/coderay/scanners/ruby/patterns.rb', line 164

def next_state
  @next_state
end

#parenObject

Returns the value of attribute paren

Returns:

  • (Object)

    the current value of paren



164
165
166
# File 'lib/coderay/scanners/ruby/patterns.rb', line 164

def paren
  @paren
end

#paren_depthObject

Returns the value of attribute paren_depth

Returns:

  • (Object)

    the current value of paren_depth



164
165
166
# File 'lib/coderay/scanners/ruby/patterns.rb', line 164

def paren_depth
  @paren_depth
end

#patternObject

Returns the value of attribute pattern

Returns:

  • (Object)

    the current value of pattern



164
165
166
# File 'lib/coderay/scanners/ruby/patterns.rb', line 164

def pattern
  @pattern
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



164
165
166
# File 'lib/coderay/scanners/ruby/patterns.rb', line 164

def type
  @type
end