Perl regexp function list for C#

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

Perl regexp function list for C#

Postby Bego » Thu Feb 26, 2009 4:35 pm

Hi guys,

I want to specify a Perl-style function list that works for C#.
I read some articles here and came closer, but I can't get it to work 100%
Best I post a self-explaining example and let the Tim/Mofi/Jo - crew take a minute on it.

Code: Select all
thisNot (private asdasd, asds)

  private override string ThisYes(blubb dada)

   private virtual string ThisYes2(blubb, dada)

protected abstract anythingElse int[] ThisYes3withBlank (blubb dada, lulu sipp) thisnomore {

public abstract object ThisToo4
 
bi bla blubb ThisNot(blubb dada, lulu sipp) sdfsdf wsf sd
bi bla blubb ThisNot2(blubb dada, lulu sipp)


Rule: (private|public|protected) must be the first word in the line.
Match the word before the first ( and mark it till the last ) in the line.
If no (), take the last word.
Any help appreciated. Tim, für dich sicher ne Fingerübung ;-) Greetz nach Ulm

rds Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Perl regexp function list for C#

Postby Mofi » Fri Feb 27, 2009 3:45 am

Hi Bego,

with UE v14.20.1.1008 following worked in the syntax highlighting wordfile for your example:

/Regexp Type = Perl
/Function String = "^[ \t]*(
?:private|protected|public).*[ \t]+([0-9_a-z]+)[ \t]*(?:\(|$)"

This Perl function string creates a function list showing:

ThisToo4
ThisYes
ThisYes2
ThisYes3withBlank

Without ?: in the regular expression the function list shows:

private ThisYes
private ThisYes2
protected ThisYes3withBlank
public ThisToo4

It was really surprising for me to see different strings in the found lines in the function list without showing the entire line. The Perl regular expression engine is really cool.

Sorry, I have just seen that you want to see also the parameters of the functions in the function list.

/Regexp Type = Perl
/Function String = "^[ \t]*(
?:private|protected|public).*[ \t]+([0-9_a-z]+[ \t]*\(.*\))"
/Function String 1 = "^[ \t]*(
?:private|protected|public).*[ \t]+([0-9_a-z]+)[ \t]*$"

or even better

/Regexp Type = Perl
/Function String = "^[ \t]*(
?:private|protected|public).*[ \t]+([0-9_a-z]+)[ \t]*(\(.*\))"
/Function String 1 = "^[ \t]*(
?:private|protected|public).*[ \t]+([0-9_a-z]+)[ \t]*$"

The last one results in having always exactly 1 space between the function name and (...) in the function list.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4062
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Perl regexp function list for C#

Postby Bego » Fri Feb 27, 2009 5:21 am

Hallo Mofi,

A fat Danke towards Austria from me. I made a mistake in my regex, which was just too complicated.... Thanks you!
Yes, Perl regexp is really cool. But when I think I understood everything, after some weeks some rework must be done to get back on track ;-)
Regex-Buddy is also an awesome help btw., I think I mentioned it once before.

rds Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany


Return to Syntax Highlighting