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



  • @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?



  • @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.



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



  • Could you supply a code example?



  • @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>



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



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


  • @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
    								)
    							"
    			>
    


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



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



  • I don’t think that worked.



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


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


Log in to reply