def enter_object
      @brace_level = 0
      push [:AT,'@']

      case
      when @scanner.scan(Lexer.patterns[:string])
        @mode = @active_object = :string
        push [:STRING, @scanner.matched]
      when @scanner.scan(Lexer.patterns[:preamble])
        @mode = @active_object = :preamble
        push [:PREAMBLE, @scanner.matched]
      when @scanner.scan(Lexer.patterns[:comment])
        @mode = @active_object = :comment
        push [:COMMENT, @scanner.matched]
      when @scanner.scan(Lexer.patterns[:entry])
        @mode = @active_object = :entry
        push [:NAME, @scanner.matched]

        # TODO: DRY - try to parse key
        if @scanner.scan(Lexer.patterns[:lbrace])
          @brace_level += 1
          push([:LBRACE,'{'])
          @mode = :content if @brace_level > 1 || @brace_level == 1 && active?(:comment)

          if @scanner.scan(Lexer.patterns[allow_missing_keys? ? :optional_key : :key])
            push [:KEY, @scanner.matched.chop.strip]
          end
        end

      else
        error_unexpected_object
      end
    end
def enter_object
      @brace_level = 0
      push [:AT,'@']

      case
      when @scanner.scan(Lexer.patterns[:string])
        @mode = @active_object = :string
        push [:STRING, @scanner.matched]
      when @scanner.scan(Lexer.patterns[:preamble])
        @mode = @active_object = :preamble
        push [:PREAMBLE, @scanner.matched]
      when @scanner.scan(Lexer.patterns[:comment])
        @mode = @active_object = :comment
        push [:COMMENT, @scanner.matched]
      when @scanner.scan(Lexer.patterns[:entry])
        @mode = @active_object = :entry
        push [:NAME, @scanner.matched]

        # TODO: DRY - try to parse key
        if @scanner.scan(Lexer.patterns[:lbrace])
          @brace_level += 1
          push([:LBRACE,'{'])
          @mode = :content if @brace_level > 1 || @brace_level == 1 && active?(:comment)

          if @scanner.scan(Lexer.patterns[allow_missing_keys? ? :optional_key : :key])
            push [:KEY, @scanner.matched.chop.strip]
          end
        end

      else
        error_unexpected_object
      end
    end
Called when the lexer encounters a new BibTeX object.