Function with spaces arround * left to C function name not listed

Syntax highlighting, code folding, brace matching, code indenting, and function list

Function with spaces arround * left to C function name not listed

Postby pwlabod » Thu Oct 18, 2012 8:18 am

Hi this function is not shown in the function list.

Code: Select all
static const char * _Tst (U8 Unit) {
  return ("tst");
}

Here my wordfile

/TGBegin "Function"
/TGFindStr = "%^([a-z_][a-z_0-9^[^]*]++^)[ ^t^p^r^n]++([~)]++)[~;{()]+[^p^r^n ^t]++[~/]++{[~}]"
/TGFindStr = "%[ ^t]++^([a-z_][a-z_0-9]++::[a-z_^~][a-z_0-9]++^)[ ^t^p]++([^p*&:, ^t^[^]/*^-'=:&a-z_0-9./(!]++)[~;{]++{"
/TGFindStr = "%[ ^t]++[a-z_][:a-z_0-9^[^]*&]++[ ^t]+^([a-z_][a-z_0-9]++::[a-z_^~][a-z_0-9]++^)[ ^t^p]++([^p*&:, ^t^[^]/*^-'=:&a-z_0-9./(!]++)[~;]"
/TGFindStr = "%[a-z_][a-z_0-9^[^]:&]++[ ^t*]+[*&]++^([a-z_][a-z_0-9]++^)[ ^t]++([^p*&:, ^t^[^]a-z_0-9\+-./(!]++)[~;]++$"
/TGFindStr = "%[a-z_][:a-z_0-9*&$^[^]/*:m][*]++[ ^t]+[a-z_][:a-z_0-9*&$^[^]]++[ ^t*]+[*&]++^([a-z_][a-z_0-9]++^)[ ^t]++([^p*&:, ^t^[^]a-z_0-9./(!]++)+[~;]"
/TGFindStr = "%[a-z_][:a-z_0-9^[^]*&]++[ ^t]+[a-z_][:a-z_0-9*&^[^]]++[ ^t]+[a-z_][:a-z_0-9*&^[^]]++[ ^t]+[*&]++^([a-z_][a-z_0-9]++^)[ ^t]++([^p*&:, ^t^[^]a-z_0-9./(!]++)[~;]"
/TGFindStr = "%[a-z_][:a-z_0-9^[^]*&]++[ ^t]+[a-z_][:a-z_0-9*&^[^]]++[ ^t]+[a-z_][:a-z_0-9*&^[^]]++[ ^t]+[a-z_][:a-z_0-9*&^[^]]++[ ^t]+[*&]++^([a-z_][a-z_0-9]++^)[ ^t]++([^p*&:, ^t^[^]a-z_0-9./(!]++)[~;]"
pwlabod
Newbie
 
Posts: 1
Joined: Thu Oct 18, 2012 8:06 am

Re: Function with spaces arround * left to C function name not listed

Postby Mofi » Thu Oct 18, 2012 12:32 pm

I have explained once at Newlines in C function definition between function name and round bracket how the regular expressions work to find function names in C/C++ files.

The last but one (6th) function string is for matching function names with 3 words left to function name. This regular expression does not work for your function string because of the spaces characters on both sides of the asterisk. That is very uncommon. Typical is writing the asterisk immediately after type

Code: Select all
static const char* _Tst (U8 Unit) {
  return ("tst");
}

or writing the asterisk at beginning of the function name

Code: Select all
static const char *_Tst (U8 Unit) {
  return ("tst");
}

You can modify the last but one function string to

/TGFindStr = "%[a-z_][:a-z_0-9^[^]*&]++[ ^t]+[a-z_][:a-z_0-9*&^[^]]++[ ^t]+[a-z_][:a-z_0-9*&^[^]]++[ ^t]+[*& ]++^([a-z_][a-z_0-9]++^)[ ^t]++([^p*&:, ^t^[^]a-z_0-9./(!]++)[~;]"

The function name is also found and listed with this additional space character in the optional square bracket before function name. But be aware that this modification might result in listing other strings as functions which are not functions.

So perhaps it is better to use the common variants of type* or *name. The latest C standard ISO/IEC 9899:2011 uses always second variant with *name.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 3936
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Syntax Highlighting