From: Alin Pilkington (AlinP@AOL.COM)
Date: 14 Sep 98, 15:09 EST
From: Alin Pilkington <AlinP@AOL.COM>
Subject: Re: Parsing for C function
I tried the simpler expression but it still croaked when using Wish 8.03.
My test case is the good old "Hello World" as shown:
#include <stdio.h>
void main(void) {
printf("Hello World\n") ;
}
which is saved in a file called hello.c
I did the following in Tcl using Wish...
set fileID [open hello.c r]
set contents [read $fileID]
and then tried various forms of the simple expression:
regexp "^[^ \t#\r/@][^\r]*\([^\r]*\)$" $contents
- Here (above) Wish complained about "invalid command" for the pattern
regexp "^\[^\ \t#\r/@\]\[^\r\]*\(\[^\r\]*\)$" $contents
- Here (above) I added the backslashes and got no complaints but no match
either
set pat2 {^[^ \t#\r/@][^\r]*\([^\r]*\)$}
regexp [subst -nocommands $pat2] $contents
- Here (above) I tried to put the pattern in braces and have the subst
command parse it. Got no complaints but no match either
Also, I did buy the book "Mastering Regular Expressions" today and I
looked thru it to find out what the /@ is doing in the pattern but I
could find no reference to it. What is it?
Thanks to all how are taking an interest in this!
Alin :)
>On 13.09.1998 at 14:47, AlinP@aol.com wrote:
>
>> I'm trying to parse a C file and extract the *names* of the functions
>> which are defined in the file. I am using as a starting point the regular
>> expression pattern that is the default in the wonderful text editor
>> Alpha. The pattern is:
>>
>> ^([^ \t\(#\r/@].*[ \t]+)?\*?([A-Za-z0-9~_]+(<[^>]*>)?::[-A-Za-z0-9~_+=
>> <>\|\*/]+|[A-Za-z0-9~_]+)[ \t\r]*\(
>
>Try this much simpler regex: ^[^ \t#\r/@][^\r]*\([^\r]*\)$
>I have it from BBedit-Find dialog.
>
>> I'm going to post this to two mail lists and go running off to Borders
>> book store to try and find a good book on regular expressions so I can
>
>"Mastering regular expressions" Author: Jeffrey E.F.Friedl
>ISBN 3-930673-62-2 is a good book.
>I have the German translation of it.
>
>
>Cheers Dirk
>
>>> Dirk Haase <<
>>> d_haase@sitec.de <<
>>> Landshut, Germany <<