Class: CodeRay::Scanners::Ruby::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.dup)
	if closing_paren = CLOSING_PAREN[delim]
		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.



196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/coderay/scanners/ruby/patterns.rb', line 196

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



147
148
149
# File 'lib/coderay/scanners/ruby/patterns.rb', line 147

def delim
  @delim
end

#heredocObject

Returns the value of attribute heredoc

Returns:

  • (Object)

    the current value of heredoc



147
148
149
# File 'lib/coderay/scanners/ruby/patterns.rb', line 147

def heredoc
  @heredoc
end

#interpretedObject

Returns the value of attribute interpreted

Returns:

  • (Object)

    the current value of interpreted



147
148
149
# File 'lib/coderay/scanners/ruby/patterns.rb', line 147

def interpreted
  @interpreted
end

#next_stateObject

Returns the value of attribute next_state

Returns:

  • (Object)

    the current value of next_state



147
148
149
# File 'lib/coderay/scanners/ruby/patterns.rb', line 147

def next_state
  @next_state
end

#parenObject

Returns the value of attribute paren

Returns:

  • (Object)

    the current value of paren



147
148
149
# File 'lib/coderay/scanners/ruby/patterns.rb', line 147

def paren
  @paren
end

#paren_depthObject

Returns the value of attribute paren_depth

Returns:

  • (Object)

    the current value of paren_depth



147
148
149
# File 'lib/coderay/scanners/ruby/patterns.rb', line 147

def paren_depth
  @paren_depth
end

#patternObject

Returns the value of attribute pattern

Returns:

  • (Object)

    the current value of pattern



147
148
149
# File 'lib/coderay/scanners/ruby/patterns.rb', line 147

def pattern
  @pattern
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



147
148
149
# File 'lib/coderay/scanners/ruby/patterns.rb', line 147

def type
  @type
end