Author Topic: Regular expression for error messages  (Read 840 times)

jorick

  • Senior Community Member
  • Posts: 357
  • Hero Points: 17
Regular expression for error messages
« on: November 14, 2019, 03:45:05 pm »
I use the IAR compiler and it generates error messages like this:

Code: [Select]
     
     I2C__t * const xptI2C = I2C_mkaptI2C [ztDevice];
                             ^
"C:\Projects\CaravanHandpiece\LPC11Uxx\Hardware\I2C.c",298  Error[Pe020]:
          identifier "I2C_mkaptI2C" is undefined
My error parser is this:  ^\"{#0:p}\"\,{#1:i}\h+{#3?+$\R?+}$  which finds the file name, line number, and error message.  Is there any way to extract the column number from the position of the caret on line 2 using a regular expression?

SlickEdit Pro 2019 (v24.0.0.7 64-bit)

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 5253
  • Hero Points: 432
Re: Regular expression for error messages
« Reply #1 on: November 14, 2019, 07:59:20 pm »
Can't do this with a regex. Currently, the error facility only handles single line errors. You defined a multi-line regex which won't work. Didn't work for me. Change the regex to just find the filename and line number while excluding mismatches.

Add a _get_error_info_XXXX hook function to get the rest of the results you need.

There are number of these in error.e:

bool _get_error_info_as(_str &filename,_str &line,_str &col, _str &err_msg)

I wrote one which is pretty close to what you need:

Code: [Select]
bool _get_error_info_cc_IAR(_str &filename,_str &line,_str &col, _str &err_msg)
{
   if (_isWindows()) return false;
   if (filename=='' || line=='') {
      return false;
   }
   get_line(auto cur_line);
   // Verify we are dealing with the right error line
   if (!pos("^:q,:i( +)Error",cur_line,1,'ri')) {
      return false;
   }
   save_pos(auto p);
   up();
   get_line(cur_line);
   restore_pos(p);
   if (cur_line!='^') {
      return false;
   }
   col=pos('^',cur_line);
   if(!down()) {
      get_line(err_msg);
      err_msg=strip(err_msg);
      restore_pos(p);
   }
   return true;
}

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 5253
  • Hero Points: 432
Re: Regular expression for error messages
« Reply #2 on: November 14, 2019, 08:07:03 pm »
Here's a Slick-C macro file you can load (Macro>Load Module...)

jorick

  • Senior Community Member
  • Posts: 357
  • Hero Points: 17
Re: Regular expression for error messages
« Reply #3 on: November 14, 2019, 08:21:19 pm »
Sorry, I posted an older regex that didn't work.  It should read ^\"{#0:p}\"\,{#1:i}\h+{#3?+}$.  I don't need the error message on the second line since it's already displayed in the console window.

Thanks for the error function.  I'll give it a try.