Regex for Function List in User Defined Language (Business Rules!)



  • a little more clarification:

    the function definition will always be on one line. the name ends at the first = or (. the variables passed to it (if any) start at the ( and end at the ) and are comma or semicolon delimited. (variables may include characters: a-z,A-Z,_,$,1-9 and &)

    another kink:

    the function definition line may or may not have the word “library” after the def before the function name. for example:

    examples:

    def library fnsteve
    def fnsteve
    def fnsteve(; x,y)
    DEF LIBRARY FNSTEVE( x; y,e3$)
    Def Fnsteve=13
    Def Fnsteve=x12+rnd
    01020 def library fnsteve
    01030 def fnsteve
    01040 def fnsteve(; x,y)
    01080 DEF LIBRARY FNSTEVE( x; y,e3$)
    01022 Def Fnsteve=13
    41020 Def Fnsteve=x
    12+rnd

    In all of these fnsteve would be the function name. In some of these variables passed are like x, y and e3$.



  • Try this one:
    ([0-9][0-9][0-9][0-9][0-9][ ]|)(def|DEF)( library| LIBRARY|) [\w]+(\(.*\)|=.+|)



  • Closer still!!

    That works beautifully until it encounters a ; then it puts everything on the same line… And also I failed to mention * may be in the variable parameter list… here is a better test list:

    def fnwhatever (x,y,x)
    fnend
    def fn_another
    fnend
    def fnyeah$(nope)
    fnend
    100 def fnyop
    200 fnend
    300 def fnok
    def library fnwhatever (x,y,x)
    fnend
    def library fn_another
    fnend
    def library fnyeah$(nope)
    fnend
    100 def library fnyop
    200 fnend
    300 def library fnok
    def library fnsteve
    def fnsteve

    def fntestastrisk(x$*20,big$*2048)

    def fnsteve(; x,y)
    DEF LIBRARY FNSTEVE( x; y,e3$)
    Def Fnsteve=13
    Def Fnsteve=x12+rnd
    01020 def library fnsteve
    01030 def fnsteve
    01040 def fnsteve(; x,y)
    01080 DEF LIBRARY FNSTEVE( x; y,e3$)



  • oh geeze I forgot the &s. & may preceed any or all variables in the line. it’s allowed.

    i.e.

    def fnwhatever(x; &no,more, &spaceallowed)



  • @John-Bowman said:

    That works beautifully until it encounters a ; then it puts everything on the same line…

    A screenshot will explain everything.



  • Otherwise, you can try this one:
    ([0-9][0-9][0-9][0-9][0-9][ ]|)(def|DEF)( library| LIBRARY|) \w+\$?[ ]*(\(.*\)|=.+|)



  • Alternative:
    (?i)(\d{3,5}[\t ]+)?DEF([\t ]+LIBRARY)?[\t ]+FN\w+\$?[\t ]*(\([^)]*\)|=)?



  • @donho yours was really close but it was adding everything to the end of the first line when it encounterd a $ for some reason.

    @MAPJe71 WORKS GREAT!!!

    I now have all my function lines listed in my Function List! Wonderful - I can double click on them and get right to them! SPECTACULAR!

    So - one follow detail though - Is it possible for me to get the parameters as auto-complete things when typing code?

    Here is what I have right now:

    		<parser id="brs_function" displayName="BR! Source">
    			<function mainExpr="(?i)(\d{3,5}[\t ]+)?DEF([\t ]+LIBRARY)?[\t ]+FN\w+\$?[\t ]*(\([^)]*\)|=)?" displayMode="$className->$functionName">
    			</function>
    		</parser>
    

    I notice most the other parser sections have a <functionName> part too - but I don’t… I’m really REALLY happy with what I have right now - but if I can take it a step farther I don’t want to miss out on all the fun =)



  • The Function List parsers are used to populate the Function List tree view only.
    Auto-Complete has its separate configuration files in the Plugins\APIs sub-folder, but I don’t know if it works for user defined languages. You could try by adding the applicable brs.xml.

    The <functionName> part is used to filter/resolve the function name e.g.

    <functionName>
        <nameExpr expr="(?i)FN\w+\$?[\t ]*(\([^)]*\))?" />
        <!-- comment out the following node to display the method with its parameters -->
        <nameExpr expr="(?i)FN\w+\$?" />
    </functionName>


  • you are correct. and yes, it does work with the UDLs. I have that working, but was only asking if I could use the cool regex syntax detecting settings in functionList.xml to accomplish the same thing. Perhaps I could do it more auto-magically over in there, but that is a subject for another thread. I’m going mark this bad boy solved. THANK YOU!!!


Log in to reply