Regex for Function List in User Defined Language (Business Rules!)
-
I am trying to set up functionList.xml for my user defined language. I need help with the regular expressions. I would be very grateful if someone could assist me. Here are some details and examples:
Functions are defined with the (always case insensitive) word “def” and may or may not be preceeded by a 5 digit number. all function names must start with “fn”
If a function has parameters they are included in parenthesis after the function name. Parameters will be separated by commas. However one semi-colon may seperate all the optional parameters from the required ones (instead of a comma). Spaces may appear in many places within the syntax, but not in the function name and can pretty much be ignored.Examples
def fnwhat3ver
00100 def fnAnotherExample
DEF FNwithParameters(arg_number,arg_string$)
def fnX
00200 Def FnWithOptional(par_12;par_option_3)
00200 Def FnWithOptional(par_12, arg_xyz, another_parameter ; par_option_3)I really appreciate any help on this matter. I am a long time user and lover of Notepad++ and hope to implement this feature for myself and to win over some new n++ users whom also use this Business Rules! language.
-John
-
Hi John,
User Defined Language doesn’t support (yet) regex.
So in your cas, you can only colourise def (or DEF).I’ll do a feature request to Loreia (the person who develops and maintains UDL), but it will not be soon even the FR is accepted.
-
Oh - I’m not trying to colorize it. I’m trying to make them appear in the functionlist side bar. :)
-
Oups sorry, I misunderstand you totally.
Each function takes only one line and whole line?
-
John,
Try this one:
([0-9][0-9][0-9][0-9][0-9][ ]|)(def|DEF) [\w]+(\(.*\)|) -
oh it’s getting really close! I don’t fully understand everything I am doing. But here’s what I’ve got so far. I’va added these lines:
<association userDefinedLangName="BR! Source" id="brs_function"/>and
<parser id="brs_function" displayName="BR! Source"> <function mainExpr="([0-9][0-9][0-9][0-9][0-9][ ]|)(def|DEF) [\w]+(\(.*\)|)" displayMode="$className->$functionName"> </function> </parser>It encounters the first function in the program then and doesn’t stop… it thinks the rest of the program is a function. I need it to stop at the first “)”, “!” or CRLF (whichever of the three comes first) … I might have formatted my parser stuff wrong too… I didn’t know what to do with the <functionName> section so i just took it out… may have been a bad idea.
-
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=x12+rndIn 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 fnstevedef 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 thePlugins\APIssub-folder, but I don’t know if it works for user defined languages. You could try by adding the applicablebrs.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!!!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login