class ElasticAPM::Sql::Tokenizer

def scan_dollar_sign

rubocop:disable Metrics/CyclomaticComplexity
def scan_dollar_sign
  while (peek = peek_char)
    case peek
    when DIGIT
      next_char while peek_char =~ DIGIT
    when '$', '_', ALPHA, SPACE
      # PostgreSQL supports dollar-quoted string literal syntax,
      # like $foo$...$foo$. The tag (foo in this case) is optional,
      # and if present follows identifier rules.
      while (char = next_char)
        case char
        when '$'
          # This marks the end of the initial $foo$.
          snap = text
          slice = input.slice(scanner.pos, input.length)
          index = slice.index(snap)
          next unless index && index >= 0
          delta = index + snap.bytesize
          @byte_end += delta
          scanner.pos += delta
          return STRING
        when SPACE
          # Unknown token starting with $, consume chars until space.
          @byte_end -= char.bytesize
          return OTHER
        end
      end
    else break
    end
  end
  OTHER
end