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 check_and_strip_double_quotes()
    return false if @string =~ %r< \A \\ . \z >xm
    if @string[0..0] == %q<">
      if @string.length == 1 || @string[-1..-1] != %q<">
        @error_block.call 'has unbalanced double quotes.'
        return
      end
      if @string =~ %r< [^\\] (?: \\{2} )*? \\ " \z >xm
        @error_block.call \
          'has unbalanced double quotes; the trailing double quote is escaped.'
        return
      end
      @string.sub!( %r< \A " (.*) " \z >xm, '\1' )
      return true
    elsif @string =~ %r< (?: \A | [^\\] ) (?: \\{2} )* " \z >xm
      @error_block.call \
        %q<has unbalanced double quotes; it ends in a double quote when it didn't start with one.>
      return
    end
    return false
  end
def check_and_strip_double_quotes ( ) return false if @string =~ %r< \A \\  .  \z >xm if @string [ 0 .. 0 ] == %q<"> if @string . length == 1 || @string [ - 1 .. - 1 ] != %q<"> @error_block . call 'has unbalanced double quotes.' return end if @string =~ %r<  [^ \\ ] (?:  \\ {2} )*?  \\  "  \z >xm @error_block . call 'has unbalanced double quotes; the trailing double quote is escaped.' return end @string . sub! ( %r< \A  " (.*) "  \z >xm , '\1' ) return true elsif @string =~ %r<  (?:  \A  | [^ \\ ] ) (?:  \\ {2} )* "  \z >xm @error_block . call %q<has unbalanced double quotes; it ends in a double quote when it didn't start with one.> return end return false end
subexpression_matchers is an array of hashes.
subexpression_matchers is an array of hashes .
# We accept any unquoted single character at this point.  Later validation # will catch bad characters.