Community
    • Login

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

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    16 Posts 3 Posters 9.7k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • John BowmanJ
      John Bowman
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • donhoD
        donho
        last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • John BowmanJ
          John Bowman
          last edited by

          Oh - I’m not trying to colorize it. I’m trying to make them appear in the functionlist side bar. :)

          1 Reply Last reply Reply Quote 0
          • donhoD
            donho
            last edited by

            Oups sorry, I misunderstand you totally.

            Each function takes only one line and whole line?

            1 Reply Last reply Reply Quote 0
            • donhoD
              donho
              last edited by

              John,

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

              1 Reply Last reply Reply Quote 0
              • John BowmanJ
                John Bowman
                last edited by John Bowman

                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.

                1 Reply Last reply Reply Quote 0
                • John BowmanJ
                  John Bowman
                  last edited by

                  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$.

                  1 Reply Last reply Reply Quote 0
                  • donhoD
                    donho
                    last edited by

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

                    1 Reply Last reply Reply Quote 0
                    • John BowmanJ
                      John Bowman
                      last edited by

                      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$)

                      1 Reply Last reply Reply Quote 0
                      • John BowmanJ
                        John Bowman
                        last edited by

                        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)

                        1 Reply Last reply Reply Quote 0
                        • donhoD
                          donho
                          last edited by

                          @John-Bowman said:

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

                          A screenshot will explain everything.

                          1 Reply Last reply Reply Quote 1
                          • donhoD
                            donho
                            last edited by

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

                            1 Reply Last reply Reply Quote 0
                            • MAPJe71M
                              MAPJe71
                              last edited by

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

                              1 Reply Last reply Reply Quote 2
                              • John BowmanJ
                                John Bowman
                                last edited by John Bowman

                                @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 =)

                                1 Reply Last reply Reply Quote 0
                                • MAPJe71M
                                  MAPJe71
                                  last edited by

                                  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>
                                  
                                  1 Reply Last reply Reply Quote 1
                                  • John BowmanJ
                                    John Bowman
                                    last edited by

                                    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!!!

                                    1 Reply Last reply Reply Quote 0
                                    • First post
                                      Last post
                                    The Community of users of the Notepad++ text editor.
                                    Powered by NodeBB | Contributors