473,326 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Regex to get VB6 function definitions

Hello everyone!

I'm trying to write a regular expression to capture VB6 function
definitions and I'm abit stuck. The rules are:

Function header:
* Must contain the words SUB or FUNCTION
* May contain the words PUBLIC or PRIVATE
* May NOT contain the word DECLARE
* Ends at the first newline that is not preceded by an underscore (_)
followed by a space.

Function footer
* Must contain the words END FUNCTION or END SUB only

Function exit:
* Must contain the words EXIT FUNCTION or EXIT SUB only

The idea is that I want to insert some logging code after each
function header and some logging code before each exit or end. So what
I need is a regex that would capture whole functions with groups for:
* Whole function header
* Function name
* Function parameter list

So far I've come up with
(?:^\s*(?:public|private){0,1}\s(?:sub|function)\s ) (?<FunctionName>[\w
\d]+) (?<FunctionArgs>(?:\s*.*_\s$)*(?:\s*.*$) | (?:.*$)) # FUNCTION
HEADER
and
(^\s*(?:end|exit)\s(?:sub|function)).*$ # FUNCTION FOOTER

but I don't really know how to combine them to get the complete
function back with the exits and ends tagged properly.

Could someone plese help me out with some tips?

Regards,

Aug 10 '07 #1
1 1983
To be honest, I don't know how you would use a regex for this, and I
hope someone else can help you on that front.

Given that you want the task of processing a number of vb files, have
you thought about writing an add-in for the VB6 environment? You can do so
in .NET, and access the specific components of the code files (functions,
properties, etc, etc) through the object model. It might make it a lot
easier than parsing it all apart using regular expressions.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<na*******@gmail.comwrote in message
news:11**********************@m37g2000prh.googlegr oups.com...
Hello everyone!

I'm trying to write a regular expression to capture VB6 function
definitions and I'm abit stuck. The rules are:

Function header:
* Must contain the words SUB or FUNCTION
* May contain the words PUBLIC or PRIVATE
* May NOT contain the word DECLARE
* Ends at the first newline that is not preceded by an underscore (_)
followed by a space.

Function footer
* Must contain the words END FUNCTION or END SUB only

Function exit:
* Must contain the words EXIT FUNCTION or EXIT SUB only

The idea is that I want to insert some logging code after each
function header and some logging code before each exit or end. So what
I need is a regex that would capture whole functions with groups for:
* Whole function header
* Function name
* Function parameter list

So far I've come up with
(?:^\s*(?:public|private){0,1}\s(?:sub|function)\s ) (?<FunctionName>[\w
\d]+) (?<FunctionArgs>(?:\s*.*_\s$)*(?:\s*.*$) | (?:.*$)) # FUNCTION
HEADER
and
(^\s*(?:end|exit)\s(?:sub|function)).*$ # FUNCTION FOOTER

but I don't really know how to combine them to get the complete
function back with the exits and ends tagged properly.

Could someone plese help me out with some tips?

Regards,

Aug 10 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Joerg Schuster | last post by:
Hello, according to http://mail.python.org/pipermail/tutor/2001-July/007246.html the order of function definitions does matter in python. Does anyone know a trick to avoid this? Is there a...
2
by: Raymond Tinsel | last post by:
Hello all, I know this must be a newbie question, but I haven't found the solution in the tutorials I have read. For a dSPACE/Controldesk application I am defining several of my own modules....
5
by: Kobu | last post by:
Does anyone know how old style function definitions differ in "behaviour" to new style function definitions? I heard the old style function definitions caused integeral promotion and floating...
8
by: Olov Johansson | last post by:
I just found out that JavaScript 1.5 (I tested this with Firefox 1.0.7 and Konqueror 3.5) has support not only for standard function definitions, function expressions (lambdas) and Function...
15
by: unknownbomb | last post by:
Hey all i really hope you can help me out. Im compiling a project and im getting 2 errors which are saying local function definitions are illegal. Anyone know what this mean? And especially...
1
by: kaygee | last post by:
Hi ppl can anyone tell me what this error means? error C2601: 'meanData' : local function definitions are illegal
9
by: vpascuzzi | last post by:
Here's the deal: I've been working on this little program forever now, and can't seem to get the final little glitches out of it. I am to build a vending machine, using 2 header .h files (one...
8
by: borophyll | last post by:
I don't understand the difference between these two declarations int foo(char a, char b) { ... } int foo(a, b) char a, b; {
3
by: MrHenry007 | last post by:
Hello! I'm fairly new to c++ but I have been following tutorials and have created functions before, but not one using a string. I can't work out what the problem is here. The function is supposed...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.