lib/fig/string_tokenizer.rb
# subexpression_matchers is an array of hashes.  Each hash is expected to
# contain two keys: :pattern and :action.
#
# The :pattern value needs to be a regular expression for the substring that
# needs special handling.
#
# The :action value needs to be a block that takes two parameters.
#
# The first parameter is the text that was matched and the second is the
# error block passed to #tokenize().
#
# On success the block returns either a String containing replacement text or
# a Fig::TokenizedString::Token representing the special handling of the
# consumed text.  If there was a problem, then the error block should have
# been invoked and the block should return nil.
#
#
# metacharacters is a regular expression character class for characters that
# need to be escaped when un-single quoting a string.
subexpression_matchers is an array of hashes.  Each hash is expected to
contain two keys: :pattern and :action.

The :pattern value needs to be a regular expression for the substring that
needs special handling.

The :action value needs to be a block that takes two parameters.

The first parameter is the text that was matched and the second is the
error block passed to #tokenize().

On success the block returns either a String containing replacement text or
a Fig::TokenizedString::Token representing the special handling of the
consumed text.  If there was a problem, then the error block should have
been invoked and the block should return nil.

metacharacters is a regular expression character class for characters that
need to be escaped when un-single quoting a string.
subexpression_matchers is an array of hashes . Each hash is expected to contain two keys : : pattern and : action . The : pattern value needs to be a regular expression for the substring that needs special handling . The : action value needs to be a block that takes two parameters . The first parameter is the text that was matched and the second is the error block passed to #tokenize () . On success the block returns either a String containing replacement text or a Fig :: TokenizedString :: Token representing the special handling of the consumed text . If there was a problem then the error block should have been invoked and the block should return nil . metacharacters is a regular expression character class for characters that need to be escaped when un - single quoting a string .
def strip_single_quotes_and_process_escapes()
    return false if @string[0..0] != %q<'> && @string[-1..-1] != %q<'>
    return false if @string =~ %r< # «\'» is legal
      \A ( [^\\']* (?: \\{2} )* \\ ' )* \z
    >x
    if (
      @string.length  == 1                                      ||
      @string[0..0]   != %q<'>                                  ||
      @string[-1..-1] != %q<'>                                  ||
      @string =~ %r< [^\\] (?: \\{2} )* (?: \\ | ' .* ) ' \z >x
    )
      @error_block.call 'has unbalanced single quotes.'
      return
    end
    if @string =~ %r< [^\\] (?: \\{2} )*? \\ ([^\\']) >x
      @error_block.call(
        "contains a bad escape sequence (\\#{$1}) inside single quotes."
      )
      return
    end
    @string.sub!( %r< \A ' (.*) ' \z >xm, '\1')
    return true
  end
def strip_single_quotes_and_process_escapes ( ) return false if @string [ 0 .. 0 ] != %q<'> && @string [ - 1 .. - 1 ] != %q<'> return false if @string =~ %r<  # «\ '»  is legal
       \A  ( [^ \\ ']* (?:  \\ {2} )*  \\  ' )*  \z >x if ( @string . length == 1 || @string [ 0 .. 0 ] != %q<'> || @string [ - 1 .. - 1 ] != %q<'> || @string =~ %r<  [^ \\ ] (?:  \\ {2} )* (?:  \\  | ' .* ) '  \z >x ) @error_block . call 'has unbalanced single quotes.' return end if @string =~ %r<  [^ \\ ] (?:  \\ {2} )*?  \\  ([^ \\ '])  >x @error_block . call ( "contains a bad escape sequence (\\#{$1}) inside single quotes." ) return end @string . sub! ( %r< \A  ' (.*) '  \z >xm , '\1' ) return true end
subexpression_matchers is an array of hashes.
subexpression_matchers is an array of hashes .