Error in generate loop

Please format your code making your code easier for others to read. I have done that for you here.

Generating blocks cannot be placed within procedural code. I attempted to modify your code by relocating the always block within the generate for loop. However, I did not test it since you did not provide a testbench.

module barrel_shifter#(parameter DATA_WIDTH = 32, localparam DW_clog2 = $clog2(DATA_WIDTH))
  ( input [DATA_WIDTH-1:0]  data_in,
    input [DW_clog2-1:0]    shift_amount, // log2(DATA_WIDTH) bits for shift amount
    input                   shift_right,      // 0 for left shift, 1 for right shift
    output [DATA_WIDTH-1:0] data_out
  );

  logic [DATA_WIDTH-1:0] stage_out[DW_clog2+1];

  assign stage_out[0] = data_in;
  for(genvar i=0;i<DW_clog2;i++) 
    always_comb
      if (shift_amount[i] == 1'b1) 
        if (shift_right) 
          stage_out[i+1] = stage_out[i][DATA_WIDTH-1 : (1 << i)];
        else 
          stage_out[i+1] = stage_out[i][DATA_WIDTH-1 - (1 << i) : 0] << ((1 << i) - 1);  
  assign data_out = stage_out[DW_clog2];
  
endmodule