tags:

views:

231

answers:

3

I'm very new to Ada, and I'm trying to do some simple work with some text. All I want to do is read in a file, and strip out anything that isn't a letter, space, or new line. so removing all the punctuation and numbers. In other languages I would just create a simple [^a-zA-Z] regular expression, look at each character and delete it if it fit the RegEx, but I can't seem to find any documentation on RegEx's in Ada. So, are there RegEx's in Ada? If not, what's the best way for me to go about simple text editing like this.

thanks much, -jb

A: 

You may want to go through this example, and just look for the characters you want to ignore and don't put them into the new string.

Which version of Ada are you using?

http://www.adaic.com/docs/95style/html/sec_8/8-4-7.html

James Black
oh, sorry, I'm using Ada 95.
jb
+5  A: 

if you are using the GNAT compiler, there are a set of packages called GNAT.RegExp, GNAT.RegPat and GNAT.Spitbol made for this task.

beware that it is not standard regexp ala perl but is based on SNOBOL4. however, it should not be very difficult to convert from one type of regular expression to another.

Adrien Plisson
+1 - I have never heard of regular expressions for Ada. :)
James Black
I saw something about the GNAT RegEx's, but i need my program to run on Windows and Linux, and I was thinking that GNAT is windows only.
jb
booooo ! gnat is based on gcc, it is obviously supported on linux and unix platforms !! and the gnat library has been written expressly to be portable between the 2 systems.
Adrien Plisson
oooh, ok, thanks for setting me straight. as i said, I'm very new to Ada :) In that case, i'll go look up those GNAT packages.
jb
since you are new, you may not be aware of all the good stuff you can find there: http://libre.adacore.com/libre/ enjoy !
Adrien Plisson
Tutorial on Snobol4 pattern matching: http://burks.bton.ac.uk/burks/language/snobol/catspaw/tutorial/ch4.htm
Nate C-K
+1  A: 

I'd probably look at the Gnat snobol stuff in your shoes.

However, there is a project available for general lexical analysis (somewhat like Boot's Spirit) called OpenToken. For slighly more complex tasks, you may find it useful.

I haven't worked with the modern incarnation, but back when I was the lead on it the project was compiler-agnostic.

T.E.D.