Take the 2-minute tour ×

i'm trying to get values from a set of files which contains enums and functions but i got some problems getting them. Since the users should be able to add their own files there to read from it shouldn't be defined from other sources an example of how the files look

info info info  
enum MyEnum  
    Myvalue = 1,  

more info  
public MyFunction();

I need to get MyEnum's name and the values without " = 1," and "," etc i also need the info and MyFunction without ";" any ideas how to do it?

edit: This is not for compiled files, its from files that can be treated as txt

share|improve this question
I'm simply compelled to ask why. Why? –  Grant Thomas Feb 14 '11 at 20:57
Uhm, are those files text files or are they compiled assemblies (*.dll)? –  Albin Sunnanbo Feb 14 '11 at 20:58
And this is already compiled? If not that will be step 1, after that things might get easier –  rene Feb 14 '11 at 21:00
Oh, yea forgot to say this but its NOT compiled files, its for autocompletion and syntax highlighting –  Cookies.net Feb 15 '11 at 8:54
@Cookies.net: what have you tried so far? If this is for things like syntax highlighting, the easiest way might be to actually compile the code and then reflect over what comes out. –  Dan Puzey Feb 15 '11 at 9:03
show 2 more comments

3 Answers

Considering these aren't compiled and are script files this question will point you in the right direction.

My solution to simplify the task is to use one of the many language parsers out there. The one I prefer with .NET is Gold Parser - download it, grab the C# language file, open the grammar file in the tool and just click the bottom right arrow button 4 times until you get a prompt to save a CGT file.

After that, follow these instructions for using the CGT file to interpret the C#s script file using the Calitha engine. The example uses search query syntax, but you can easily adapt it:

private void _lalrParser_OnTokenRead(LALRParser parser, TokenReadEventArgs e)
     // See if the token's name is enum, next time round grab the names/values
share|improve this answer
add comment

I would take a look at http://www.antlr.org/ which is the parser used by nhibernate.

share|improve this answer
add comment
up vote 0 down vote accepted

Alright, needs some cleaning and some fixing but i got it working. Not sure why i didn't thought about it before but heres what i do. I read the files 1 line at a time check if its enum, public etc and then do the stuff i want. enum is abit tricky and its not quite working yet, a few bugs. in enum i check if its an enum, if it is then until a line stats with "}" i add the values i find. But thanks for your answers anyways, if i didn't get it to work! ;)

share|improve this answer
add comment

Your Answer


