C++ function strings troubles with namespaces

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

C++ function strings troubles with namespaces

Postby haron » Fri Sep 24, 2004 4:30 am

Currently the best solution (provided by toddm):
// Handles the case where Class:: is the type
// type function name ( parameters or none
/Function String = "[a-zA-Z_0-9*&]+[:]+^([a-zA-Z_0-9*&=<^~]+[ ^t]++[(]+[~;{]++)[~;{:]++^)[{=]+"
//
// Handles the case where type on same line as function
// type function name ( parameters or none
/Function String 2 = "%[~(){} ^t^p#/]+[a-zA-Z_0-9*&<>: ^t]+[ ^t]+^([a-zA-Z_0-9*&=<>^~]+[ ^t]++([~(=;]+)[~()=;{]+^)[{=]+"
//
// Handles the case where type on different line as function
// type function name ( parameters or none
/Function String 3 = "[a-zA-Z_0-9*&<>]+[ ^t]++[^p]+^([a-zA-Z_0-9*&=<^~]+[ ^t]++[(]+[a-zA-Z_0-9<>&* ^t,^p:/^[^]]++[)]+[ ^t^pa-zA-Z/]++^)[{=]+"
//


------------------ the question --------------------------

Hallo All,

Using UltraEdit 10.00c i have found, that C++ functions which uses namespace-decorated arguments or return values are not displayed correctly in function list.

void a(x::x_s *p)
{ return; }

void b(y::y_s *p)
{ return; }

x::x_s *aptr(void)
{ return 0; }

y::y_s *bptr(void)
{ return 0; }


First, i was intended to write my own new "/Function string", but unfortunately all 6 possible was already busy with predefined functon strings for C++:

/Function String = "%^([a-zA-Z_0-9^[^]*]+^)[ ^t]+([^p*&, ^t^[^]a-zA-Z_0-9.!]++)[~;]"
/Function String 1 = "%[a-zA-Z_0-9*]*::^([a-zA-Z_0-9^~]+^)[ ^t^p]++([^p*&, ^t^[^]/*=:&a-zA-Z_0-9./(!]++)[~;]"
/Function String 2 = "%[a-zA-Z_0-9^][a-zA-Z_0-9^[^]]+[ ^t*]+^([a-zA-Z_0-9]+^)[ ^t]++([^p*&, ^t^[^]a-zA-Z_0-9./(!]++)[~;]"
/Function String 3 = "%[a-zA-Z_0-9*&$^[^]*]+[ ^t]+[a-zA-Z_0-9*&$^[^]]+[ ^t*]+^([a-zA-Z_0-9]+^)[ ^t]++([^p*&, ^t^[^]a-zA-Z_0-9./(!]++)[~;]"
/Function String 4 = "%[a-z_0-9^[^]*]++ [a-z_0-9*^[^]]+[ ^t]++[a-z_0-9*^[^]]+[ ^t]++^([*a-z_0-9]+^)[ ^t]++([^p*&, ^t^[^]a-z_0-9./(!]++)[~;]"
/Function String 5 = "%^([a-zA-Z_0-9^[^]*]+^)[ ^t]++([^p*&, ^t^[^]a-zA-Z_0-9./()!]++)[~;]"

Modification of existing strings is relatively hard for me, because i'm not very familiar with regular expressions. Therefore i have tryed to use pattern like this:

/Function String 5 = "%^([~(]+^)(*++^$FORCE_ULTRAEDIT_FUNCTION^$"

to find any function wich is not compliant with predefined regular expressions (of course, in place of one of the existing patterns, so i probably loose some function recognition which was o.k before). But this task is more complicated, as i thought

May be some regular expression Guru can say me which way is easier ? Modification of one of existing pattern to match my syntax or writting universal handler (and always use manual marker like $FORCE_ULTRAEDIT_FUNCTION$ for functions not displayed correctly) ? Some another ways to see functions a(), b(), aptr(), bptr() ?

Thanks a lot for any help
User avatar
haron
Newbie
 
Posts: 2
Joined: Thu Sep 23, 2004 11:00 pm

Re: C++ function strings troubles with namespaces

Postby Manni » Sat Sep 25, 2004 5:53 am

Here are my function strings. They work for your functions a() and b(), but not for aptr() and bptr().

I guess if you really invest some time in this, you could make them display all the functions. But I admit that this is not an easy job and it can be quite frustrating. One problem is that you never know which of your strings caught a specific function.
Code: Select all
/Function String =   "%[0-9a-zA-Z_^[^]^*&:<>]+[ ^t]+^([0-9a-zA-Z_]+[ ^t]++([0-9a-zA-Z_,:^[^]^*&/ <>]++)^)[~;]"
/Function String 1 = "%[0-9a-zA-Z_]+[ ^t]++([0-9a-zA-Z_,^[^]^*&/ ]++)[~;]"
/Function String 2 = "%[0-9a-zA-Z_^[^]^*&:]+[ ^t]+[0-9a-zA-Z_]+::^([0-9a-zA-Z_^[^]^+^-^*=/<>]+[ ^t]++([0-9a-zA-Z_,^*=&/:.^[^] ]++)^)[~;]"
/Function String 3 = "%[0-9a-zA-Z_^[^]^*&]+::^([^~0-9a-zA-Z_]+[ ^t]++([0-9a-zA-Z_,^*&^:/ ]++)^)[~;]"
/Function String 4 = "%[0-9a-zA-Z_^[^]^*&]+::^([^~0-9a-zA-Z_]+[ ^t]++([0-9a-zA-Z_,^*&^:/ ]++)^)[~;]"


Manni
User avatar
Manni
Advanced User
Advanced User
 
Posts: 58
Joined: Thu Jul 15, 2004 11:00 pm
Location: Europe

Re: C++ function strings troubles with namespaces

Postby toddm » Tue Sep 28, 2004 5:40 pm

I've been messing with the function strings off and on for a while and I believe the following are the best yet. I don't think every possible function can be caught with a simple expression, but these handle most including the functions in the first post.

Code: Select all
// Handles the case where Class:: is the type
//                  type                 function name              (  parameters or none               
/Function String = "[a-zA-Z_0-9*&]+[:]+^([a-zA-Z_0-9*&=<^~]+[ ^t]++[(]+[~;{]++)[~;{:]++^)[{=]+"
//
// Handles the case where type on same line as function
//                                    type                         function name              ( parameters or none             
/Function String 2 = "%[~(){} ^t^p#/]+[a-zA-Z_0-9*&<>: ^t]+[ ^t]+^([a-zA-Z_0-9*&=<>^~]+[ ^t]++([~(=;]+)[~()=;{]+^)[{=]+"
//
// Handles the case where type on different line as function
//                    type                           function name              (  parameters or none             
/Function String 3 = "[a-zA-Z_0-9*&<>]+[ ^t]++[^p]+^([a-zA-Z_0-9*&=<^~]+[ ^t]++[(]+[a-zA-Z_0-9<>&* ^t,^p:/^[^]]++[)]+[ ^t^pa-zA-Z/]++^)[{=]+"
//
User avatar
toddm
Advanced User
Advanced User
 
Posts: 83
Joined: Wed Jul 28, 2004 11:00 pm

Re: C++ function strings troubles with namespaces

Postby toddm » Tue Sep 28, 2004 5:41 pm

Note that anytime you see a ^t in the above post there should be a space before it. Word wrapping messed it up.
User avatar
toddm
Advanced User
Advanced User
 
Posts: 83
Joined: Wed Jul 28, 2004 11:00 pm

Re: C++ function strings troubles with namespaces

Postby haron » Wed Sep 29, 2004 2:31 am

I have tryed both versions - from Manni and from toddm.
Strings from toddm are very well (at least for my coding style). They matches practically all my functions (thanks a lot !) - so i decide to place them in the first post of topic.

What is interesting, that operators -, +, -=, += are not working, but >, >=, <, <= are matched very good:

void a(x::x_s *p)
{ /*ok*/ return; }

void b(y::y_s *p)
{ /*ok*/ return; }

x::x_s *aptr(void)
{ /*ok*/ return 0; }

y::y_s *bptr(void)
{ /*ok*/ return 0; }

void c(y_s *p)
{ /*ok*/ return; }

void d(x_s *p)
{ /*ok*/ return; }

const x::x_s operator - (const x::x_s &left, const x::x_s &right)
{ return x::x_s (); }

const x::x_s operator + (const x::x_s &left, const x::x_s &right)
{ return x::x_s (); }

const x::x_s operator -= (const x::x_s &left, const x::x_s &right)
{ return x::x_s (); }

const x::x_s operator += (const x::x_s &left, const x::x_s &right)
{ return x::x_s (); }

bool operator == (const x::x_s &left, const x::x_s &right)
{ /*ok*/ return true; }

bool operator > (const x::x_s &left, const x::x_s &right)
{ /*ok*/ return true; }

bool operator >= (const x::x_s &left, const x::x_s &right)
{ /*ok*/ return true; }

bool operator < (const x::x_s &left, const x::x_s &right)
{ /*ok*/ return true; }

bool operator <= (const x::x_s &left, const x::x_s &right)
{ /*ok*/ return true; }


Hopefully, i will find time to analyse what can be adjusted to match operators -, +, -=, +=. But even if not - im starting to use this function strings, because they are already pretty good.

I have suggestion to all C++ programmers - to test function strings from toddm and report here all cases they not handle correctly.
User avatar
haron
Newbie
 
Posts: 2
Joined: Thu Sep 23, 2004 11:00 pm

Re: C++ function strings troubles with namespaces

Postby toddm » Wed Sep 29, 2004 8:32 am

Here's an update. Both of these new strings handle haron's new code. I'd try the first update first because it should handle more stuff.

Code: Select all
/Function String 2 = "%[~(){} ^t^p#/]+[a-zA-Z_0-9*&<>: ^t]+[ ^t]+^([a-zA-Z_0-9*&=<>^~^-^+]+[ ^t]++([~(=;]+)[~()=;{]+^)[{=]+"


Code: Select all
/Function String 2 = "%[~(){} ^t^p#/]+[a-zA-Z_0-9*&<>: ^t]+[ ^t]+^([~(){} ^t^p]+[ ^t]++([~(=;]+)[~()=;{]+^)[{=]+"


I did find out something interesting about my function strings. if statements are reported as functions if they are left justified and I believe functions must be left justified. The only time this doesn't work for me is if a function is defined in a header file. My if statements always seem to be indented so I never noticed this before.

Ultraedit really needs a say to omit keywords from the function strings, but I can't figure out how to make this work.
User avatar
toddm
Advanced User
Advanced User
 
Posts: 83
Joined: Wed Jul 28, 2004 11:00 pm


Return to Syntax Highlighting