Raised This Month: $ Target: $400
 0% 

Regex for identifying functions/variables


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
necavi
Veteran Member
Join Date: Sep 2010
Old 02-13-2012 , 21:31   Regex for identifying functions/variables
Reply With Quote #1

I'm currently trying to create something that will allow me to list all functions, variables and defines in a plugin and the best way to do this seems to be a three small regex functions. All it would have to do is return true if what is passed to it is a function, variable or define (depending on the regex). If anyone would be able to help me do this it would be greatly appreciated!
necavi is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 02-14-2012 , 04:27   Re: Regex for identifying functions/variables
Reply With Quote #2

Please read http://stackoverflow.com/a/1732454 before deciding you want to do this with regular expressions, everything in there applies to what you're trying to do.
__________________

Last edited by asherkin; 02-14-2012 at 04:28.
asherkin is offline
necavi
Veteran Member
Join Date: Sep 2010
Old 02-14-2012 , 04:43   Re: Regex for identifying functions/variables
Reply With Quote #3

Heh, I have read that before (I was trying to do something similar, if I remember correctly) and have decided to instead try implementing it in a different way. My current implementation is absolutely atrocious, but I'll be improving it over time. (It does have some issue with certain types of comments, at the moment).
PHP Code:
def SearchForFunction(string):
    
explosion string.split(" ")
    if(
explosion[0]=="stock"):
        if(
"(" in explosion[1]):
            
explosion[1].split("(")
            
stocks.append(h[0])
        else:
            
variables.append(explosion[1])
    
elif(explosion[0]=="public"):
        if(
"(" in explosion[1]):
            
explosion[1].split("(")
            public.
append(h[0])
    
elif(explosion[0]=="new"):
        
variables.append(explosion[1])
    
elif(explosion[0]=="forward"):
        if(
"(" in explosion[1]):
            
explosion[1].split("(")
            
forwards.append(h[0])
    
elif(explosion[0]=="native"):
        if(
"(" in explosion[1]):
            
explosion[1].split("(")
            
natives.append(h[0])
    
elif("\t" not in explosion[0] and "\n" not in explosion[0] and "}" not in explosion[0] and "//" not in explosion[0]):
        if(
"(" in explosion[0]):
            
explosion[0].split("(")
            private.
append(h[0]) 
Thankfully this isn't meant to be run inside the game, meaning I am able to use something with better string handling than sourcepawn, in this case: python.
necavi is offline
BAILOPAN
Join Date: Jan 2004
Old 02-14-2012 , 14:15   Re: Regex for identifying functions/variables
Reply With Quote #4

If you're trying to parse the source code, the compiler can already do this for you. It's easy to just insert printfs in it to output stuff as it finds it.
__________________
egg
BAILOPAN is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:12.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode