Community
    • Login

    [Help] Function list doesn't support my language.

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    15 Posts 2 Posters 5.7k Views 2 Watching
    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.
    • MAPJe71M Offline
      MAPJe71
      last edited by

      Did you even try to find a Lua parser?

      With a Google-search:

      1. https://notepad-plus-plus.org/community/topic/11351/function-list
      2. https://hristoz.com/2014/04/08/notepad-lua-function-list-with-tables/
      3. http://yohanip.blogspot.nl/2014/01/lua-function-list-on-notepad.html
      4. http://stackoverflow.com/questions/19246077/how-to-add-lua-functions-to-the-notepad-functionlist-xml
      1 Reply Last reply Reply Quote 1
      • SalviaSageS Offline
        SalviaSage
        last edited by

        @Scott-Sumner

        Hi, I added this piece of code to the functionlist.xml that is found in both n++ installation directory and the user directory

        <association langID=“23” id=“lua_function”/>

        <parser id=“lua_function” displayName=“Lua”>
        <function mainExpr=“^[t|locals]functions+[^0-9][_A-Za-z0-9.: ]+s(” displayMode=“$functionName”>
        <functionName>
        <nameExpr expr=“[.:]?sK[^0-9][_A-Za-z0-9]+s(”/>
        <nameExpr expr=“[^0-9][_A-Za-z0-9]+s*(”/>
        <nameExpr expr=“[^0-9][_A-Za-z0-9]+”/>
        </functionName>
        <className>
        <nameExpr expr=“functionsK[^0-9][_A-Za-z0-9.:]+(?=s[.:])”/>
        </className>
        </function>
        </parser>

        I took this code from an over 3 years old post,
        https://hristoz.com/2014/04/08/notepad-lua-function-list-with-tables/

        I think I integrated this code into the functionlist.xml correctly. Does anyone know how I can get it working?

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

          @SalviaSage Why pick that one? And why not try one of the others when it appears not to work?

          Hint: pick the one from the favoured answer on stackoverflow.

          1 Reply Last reply Reply Quote 1
          • SalviaSageS Offline
            SalviaSage
            last edited by

            I tried the one you suggested and it works.

            However, it also finds the word function in comments, obviously these are not functions…

            I guess the code can be made so that it skips these comments using regex or something like that.

            Unfortunately I don’t know regex and this is beyond my coding skill.
            I would be happy if someone could code this into the code that is found here (the code with green checkmark): https://stackoverflow.com/questions/19246077/how-to-add-lua-functions-to-the-notepad-functionlist-xml

            That’s all, thanks if you look into this.

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

              Could you supply a code example?

              1 Reply Last reply Reply Quote 0
              • SalviaSageS Offline
                SalviaSage
                last edited by

                @MAPJe71

                This is my code, already integrated into functionlist and working.

                Just need to parse out the comments, so they dont appear in thefunction list.

                		<!-- Basic lua parser for functionList.xml in Notepad++ 6.5.3 -->
                		<!-- See http://notepad-plus-plus.org/features/function-list.html -->
                		<parser id="lua_function" displayName="Lua" commentExpr="--.*?$">
                			<!-- Basic lua table view, nested lua table not supported -->
                			<classRange
                				mainExpr="[.\w]+[\s]*=[\s]*\{"
                				openSymbole="\{"
                				closeSymbole="\}"
                				displayMode="node">
                				<className>
                					<nameExpr expr="[.\w]+"/>
                				</className>
                				<function
                					mainExpr="[.\w]+[\s]*=[\s]*['&quot;]?[\w]+['&quot;]?">
                					<functionName>
                						<funcNameExpr expr=".*"/>
                					</functionName>
                				</function>
                			</classRange>
                			<!-- Basic lua functions support -->
                			<function
                				mainExpr="(function[\s]+[.\w]+(:[\w]+)?)|([.\w]+[\s]*=[\s]*function)"
                				displayMode="$className->$functionName">
                				<functionName>
                					<nameExpr expr="((?<=function)[\s]+[.:\w]+)|(([.\w]+)(?=([\s]*=[\s]*function)))"/>
                				</functionName>
                				<className>
                					<nameExpr expr="[.\w]+(?=:)"/>
                				</className>
                			</function>
                		</parser>
                
                		<!-- ================================================================= -->
                	</parsers>
                </functionList>
                

                </NotepadPlus>

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

                  @SalviaSage
                  Sigh, a Lua source code example containing function definitions in comment that the parser should not find.

                  1 Reply Last reply Reply Quote 0
                  • SalviaSageS Offline
                    SalviaSage
                    last edited by SalviaSage

                    This one for example:

                    --[[
                    	Resize and hide any unusable bag slots in the frame.
                    		This function needs to know about the size and layout of the frame
                    --]]
                    

                    “needs” here is recognized as a function because it is right after the word “function”

                    and here:
                    

                    –this function is there so that it can be overriden

                    the word "is" is recognized here also.
                    MAPJe71M 1 Reply Last reply Reply Quote 0
                    • MAPJe71M Offline
                      MAPJe71 @SalviaSage
                      last edited by

                      @SalviaSage
                      Change the parsers header from

                              <parser id="lua_function" displayName="Lua" commentExpr="--.*?$">
                      

                      to

                      			<parser
                      				displayName="Lua"
                      				id         ="lua_function"
                      				commentExpr="(?x)                                               # free-spacing (see `RegEx - Pattern Modifiers`)
                      								(?s:                                            # Multi Line Comment
                      									(?&lt;!-)-{2}                               # - start-of-comment indicator with
                      									\x5B(?'MLCLVL'=*)\x5B                       #   ...specific level
                      									.*?                                         # - whatever, until
                      									\x5D\k'MLCLVL'\x5D                          # - end-of-comment indicator of equal level
                      								)
                      							|	(?m-s:-{2}.*$)                                  # Single Line Comment
                      							|	(?s-m:                                          # String Literal
                      									=\s*
                      									\x5B(?'SLLVL'=*)\x5B                        # - start-of-string indicator with specific level
                      									.*?                                         # - whatever, until
                      									\x5D\k'SLLVL'\x5D                           # - end-of-string indicator of equal level
                      								)
                      							"
                      			>
                      
                      1 Reply Last reply Reply Quote 1
                      • SalviaSageS Offline
                        SalviaSage
                        last edited by

                        I just entered this code into the functionlist.xml as such:

                        			</parser>
                        
                        			<!-- Basic lua parser for functionList.xml in Notepad++ 6.5.3 -->
                        			<!-- See http://notepad-plus-plus.org/features/function-list.html -->
                        			<parser
                        				displayName="Lua"
                        				id         ="lua_function"
                        				commentExpr="(?x)                                               # free-spacing (see `RegEx - Pattern Modifiers`)
                        					(?s:                                            # Multi Line Comment
                        						(?&lt;!-)-{2}                               # - start-of-comment indicator with
                        						\x5B(?'MLCLVL'=*)\x5B                       #   ...specific level
                        						.*?                                         # - whatever, until
                        						\x5D\k'MLCLVL'\x5D                          # - end-of-comment indicator of equal level
                        					)
                        				|   (?m-s:-{2}.*$)                                  # Single Line Comment
                        				|   (?s-m:                                          # String Literal
                        						=\s*
                        						\x5B(?'SLLVL'=*)\x5B                        # - start-of-string indicator with specific level
                        						.*?                                         # - whatever, until
                        						\x5D\k'SLLVL'\x5D                           # - end-of-string indicator of equal level
                        					)
                        				"
                        			>
                        
                        				<!-- Basic lua table view, nested lua table not supported -->
                        				<classRange
                        					mainExpr="[.\w]+[\s]*=[\s]*\{"
                        					openSymbole="\{"
                        					closeSymbole="\}"
                        					displayMode="node">
                        					<className>
                        						<nameExpr expr="[.\w]+"/>
                        					</className>
                        					<function
                        						mainExpr="[.\w]+[\s]*=[\s]*['&quot;]?[\w]+['&quot;]?">
                        						<functionName>
                        							<funcNameExpr expr=".*"/>
                        						</functionName>
                        					</function>
                        				</classRange>
                        				<!-- Basic lua functions support -->
                        				<function
                        					mainExpr="(function[\s]+[.\w]+(:[\w]+)?)|([.\w]+[\s]*=[\s]*function)"
                        					displayMode="$className->$functionName">
                        					<functionName>
                        						<nameExpr expr="((?<=function)[\s]+[.:\w]+)|(([.\w]+)(?=([\s]*=[\s]*function)))"/>
                        					</functionName>
                        					<className>
                        						<nameExpr expr="[.\w]+(?=:)"/>
                        					</className>
                        				</function>
                        			</parser>
                        
                        			<!-- ================================================================= -->
                        		</parsers>
                        	</functionList>
                        </NotepadPlus>
                        

                        It didn’t change anything. I think I indented right.
                        It errors on this line <nameExpr expr=“((?<=function)[\s]+[.:\w]+)|(([.\w]+)(?=([\s]*=[\s]*function)))”/>
                        according to the online xml validator.

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

                          Change the ?<= to ?&lt;=.

                          1 Reply Last reply Reply Quote 2
                          • SalviaSageS Offline
                            SalviaSage
                            last edited by

                            I don’t think that worked.

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

                              This one works for me (no classes/tables yet though):

                              			<parser
                              				displayName="Lua w/o Class"
                              				id         ="lua_function"
                              				commentExpr="(?x)                                               # free-spacing (see `RegEx - Pattern Modifiers`)
                              								(?s:                                            # Multi Line Comment
                              									(?&lt;!-)-{2}                               # - start-of-comment indicator with
                              									\x5B(?'MLCLVL'=*)\x5B                       #   ...specific level
                              									.*?                                         # - whatever, until
                              									\x5D\k'MLCLVL'\x5D                          # - end-of-comment indicator of equal level
                              								)
                              							|	(?m-s:-{2}.*$)                                  # Single Line Comment
                              							|	(?s-m:                                          # String Literal
                              									=\s*
                              									\x5B(?'SLLVL'=*)\x5B                        # - start-of-string indicator with specific level
                              									.*?                                         # - whatever, until
                              									\x5D\k'SLLVL'\x5D                           # - end-of-string indicator of equal level
                              								)
                              							"
                              			>
                              				<function
                              					mainExpr="(?x)                                              # free-spacing (see `RegEx - Pattern Modifiers`)
                              							(?m)                                                # ^ and $ match at line-breaks
                              							(?:
                              								^\h*                                            # optional leading white-space at start-of-line
                              								(?-i:local\s+)?
                              								(?-i:function)
                              								\s+[A-Za-z_]\w*
                              								(?:\.[A-Za-z_]\w*)*
                              								(?::[A-Za-z_]\w*)?
                              							|
                              								\s*[A-Za-z_]\w*
                              								(?:\.[A-Za-z_]\w*)*
                              								\s*=
                              								\s*(?-i:function)
                              							)
                              							\s*\([^()]*\)
                              						"
                              				>
                              					<functionName>
                              						<nameExpr expr="(?&lt;=\bfunction\b)\s+[A-Za-z_][\w.:]*\s*\(|[A-Za-z_][\w.]*\s*=" />
                              						<nameExpr expr="[A-Za-z_][\w.:]*" />
                              					</functionName>
                              				</function>
                              			</parser>
                              
                              1 Reply Last reply Reply Quote 1
                              • SalviaSageS Offline
                                SalviaSage
                                last edited by

                                I just tested this new code here, and it doesn’t catch the comments or the strings incorrectly.

                                Thanks a lot for this!

                                I am trying to combine the table support from the code above into this new code.

                                1 Reply Last reply Reply Quote 0

                                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
                                • First post
                                  Last post
                                The Community of users of the Notepad++ text editor.
                                Powered by NodeBB | Contributors