Community
    • 登入

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

    已排程 已置頂 已鎖定 已移動 Help wanted · · · – – – · · ·
    16 貼文 3 Posters 10.0k 瀏覽
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • John BowmanJ
      John Bowman
      最後由 編輯

      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 條回覆 最後回覆 回覆 引用 0
      • donhoD
        donho
        最後由 編輯

        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 條回覆 最後回覆 回覆 引用 0
        • John BowmanJ
          John Bowman
          最後由 編輯

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

          1 條回覆 最後回覆 回覆 引用 0
          • donhoD
            donho
            最後由 編輯

            Oups sorry, I misunderstand you totally.

            Each function takes only one line and whole line?

            1 條回覆 最後回覆 回覆 引用 0
            • donhoD
              donho
              最後由 編輯

              John,

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

              1 條回覆 最後回覆 回覆 引用 0
              • John BowmanJ
                John Bowman
                最後由 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 條回覆 最後回覆 回覆 引用 0
                • John BowmanJ
                  John Bowman
                  最後由 編輯

                  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 條回覆 最後回覆 回覆 引用 0
                  • donhoD
                    donho
                    最後由 編輯

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

                    1 條回覆 最後回覆 回覆 引用 0
                    • John BowmanJ
                      John Bowman
                      最後由 編輯

                      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 條回覆 最後回覆 回覆 引用 0
                      • John BowmanJ
                        John Bowman
                        最後由 編輯

                        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 條回覆 最後回覆 回覆 引用 0
                        • donhoD
                          donho
                          最後由 編輯

                          @John-Bowman said:

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

                          A screenshot will explain everything.

                          1 條回覆 最後回覆 回覆 引用 1
                          • donhoD
                            donho
                            最後由 編輯

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

                            1 條回覆 最後回覆 回覆 引用 0
                            • MAPJe71M
                              MAPJe71
                              最後由 編輯

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

                              1 條回覆 最後回覆 回覆 引用 2
                              • John BowmanJ
                                John Bowman
                                最後由 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 條回覆 最後回覆 回覆 引用 0
                                • MAPJe71M
                                  MAPJe71
                                  最後由 編輯

                                  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 條回覆 最後回覆 回覆 引用 1
                                  • John BowmanJ
                                    John Bowman
                                    最後由 編輯

                                    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 條回覆 最後回覆 回覆 引用 0
                                    • 第一個貼文
                                      最後的貼文
                                    The Community of users of the Notepad++ text editor.
                                    Powered by NodeBB | Contributors