473,699 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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*(?:publi c|private){0,1} \s(?:sub|functi on)\s) (?<FunctionName >[\w
\d]+) (?<FunctionArgs >(?:\s*.*_\s$)* (?:\s*.*$) | (?:.*$)) # FUNCTION
HEADER
and
(^\s*(?:end|exi t)\s(?:sub|func tion)).*$ # 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 2011
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.co m

<na*******@gmai l.comwrote in message
news:11******** **************@ m37g2000prh.goo glegroups.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*(?:publi c|private){0,1} \s(?:sub|functi on)\s) (?<FunctionName >[\w
\d]+) (?<FunctionArgs >(?:\s*.*_\s$)* (?:\s*.*$) | (?:.*$)) # FUNCTION
HEADER
and
(^\s*(?:end|exi t)\s(?:sub|func tion)).*$ # 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
6286
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 way to "declare" functions without defining them?
2
7945
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. In those modules I also have function definitions of functions I only use in that module. Is it possible to hide these functions when somebody would use "import
5
7261
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 point promotion on the formal parameters. Is this true? Is it okay for me to set up a new style funciton prototype when calling old style function definitions (for legacy code)? Is this okay?
8
5108
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 constructors (these three I knew about), but also conditional function definitions, as described in http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Defining_Functions ]. An example: function fun() {
15
25722
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 HOW to fix it?? Thanks.. Sorry if this is a noob question.. I AM still a noobcoder. Greetz
1
4708
by: kaygee | last post by:
Hi ppl can anyone tell me what this error means? error C2601: 'meanData' : local function definitions are illegal
9
4007
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 for the cash register and the other for the dispenser), and 2 member function definitions .cpp (one for each). It is a little lengthy, and there are 5 files so I uploaded them to my webspace. If anyone could take a look at my code and possibly fix...
8
1738
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
9180
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 to accept a file location, open the file, search for a phrase, and return a result if the certain phrase is found, otherwise return nothing. Then the result is written to a text file later in the program. Im using visual c++ 2008 and it is...
0
8705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9199
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8899
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7785
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6550
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5884
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4391
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3075
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.