Class: CodeRay::Scanners::Ruby::StringState
- Inherits:
-
Struct
- Object
- Struct
- CodeRay::Scanners::Ruby::StringState
- Defined in:
- lib/coderay/scanners/ruby/string_state.rb
Constant Summary collapse
- CLOSING_PAREN =
Hash[ *%w[ ( ) [ ] < > { } ] ].each { |k,v| k.freeze; v.freeze }
- STRING_PATTERN =
Hash.new do |h, k| delim, interpreted = *k delim_pattern = Regexp.escape(delim) if closing_paren = CLOSING_PAREN[delim] delim_pattern << Regexp.escape(closing_paren) end delim_pattern << '\\\\' unless delim == '\\' # special_escapes = # case interpreted # when :regexp_symbols # '| [|?*+(){}\[\].^$]' # end if interpreted && delim != '#' / (?= [#{delim_pattern}] | \# [{$@] ) /mx else / (?= [#{delim_pattern}] ) /mx end.tap do |pattern| h[k] = pattern if (delim.respond_to?(:ord) ? delim.ord : delim[0]) < 256 end end
Instance Attribute Summary collapse
-
#delim ⇒ Object
Returns the value of attribute delim.
-
#heredoc ⇒ Object
Returns the value of attribute heredoc.
-
#interpreted ⇒ Object
Returns the value of attribute interpreted.
-
#next_state ⇒ Object
Returns the value of attribute next_state.
-
#opening_paren ⇒ Object
Returns the value of attribute opening_paren.
-
#paren_depth ⇒ Object
Returns the value of attribute paren_depth.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #heredoc_pattern(delim, interpreted, indented) ⇒ Object
-
#initialize(kind, interpreted, delim, heredoc = false) ⇒ StringState
constructor
A new instance of StringState.
Constructor Details
#initialize(kind, interpreted, delim, heredoc = false) ⇒ StringState
Returns a new instance of StringState.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/coderay/scanners/ruby/string_state.rb', line 48 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 closing_paren = CLOSING_PAREN[delim] opening_paren = delim delim = closing_paren paren_depth = 1 end end super kind, interpreted, delim, heredoc, opening_paren, paren_depth, pattern, :initial end |
Instance Attribute Details
#delim ⇒ Object
Returns the value of attribute delim
7 8 9 |
# File 'lib/coderay/scanners/ruby/string_state.rb', line 7 def delim @delim end |
#heredoc ⇒ Object
Returns the value of attribute heredoc
7 8 9 |
# File 'lib/coderay/scanners/ruby/string_state.rb', line 7 def heredoc @heredoc end |
#interpreted ⇒ Object
Returns the value of attribute interpreted
7 8 9 |
# File 'lib/coderay/scanners/ruby/string_state.rb', line 7 def interpreted @interpreted end |
#next_state ⇒ Object
Returns the value of attribute next_state
7 8 9 |
# File 'lib/coderay/scanners/ruby/string_state.rb', line 7 def next_state @next_state end |
#opening_paren ⇒ Object
Returns the value of attribute opening_paren
7 8 9 |
# File 'lib/coderay/scanners/ruby/string_state.rb', line 7 def opening_paren @opening_paren end |
#paren_depth ⇒ Object
Returns the value of attribute paren_depth
7 8 9 |
# File 'lib/coderay/scanners/ruby/string_state.rb', line 7 def paren_depth @paren_depth end |
#pattern ⇒ Object
Returns the value of attribute pattern
7 8 9 |
# File 'lib/coderay/scanners/ruby/string_state.rb', line 7 def pattern @pattern end |
#type ⇒ Object
Returns the value of attribute type
7 8 9 |
# File 'lib/coderay/scanners/ruby/string_state.rb', line 7 def type @type end |
Class Method Details
.simple_key_pattern(delim) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/coderay/scanners/ruby/string_state.rb', line 40 def self.simple_key_pattern delim if delim == "'" / (?> (?: [^\\']+ | \\. )* ) ' : /mx else / (?> (?: [^\\"\#]+ | \\. | \#\$[\\"] | \#\{[^\{\}]+\} | \#(?!\{) )* ) " : /mx end end |
Instance Method Details
#heredoc_pattern(delim, interpreted, indented) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/coderay/scanners/ruby/string_state.rb', line 63 def heredoc_pattern delim, interpreted, indented # delim = delim.dup # workaround for old Ruby delim_pattern = Regexp.escape(delim) delim_pattern = / (?:\A|\n) #{ '(?>[ \t]*)' if indented } #{ Regexp.new delim_pattern } $ /x if interpreted / (?= #{delim_pattern}() | \\ | \# [{$@] ) /mx # $1 set == end of heredoc else / (?= #{delim_pattern}() | \\ ) /mx end end |