[Help] Function list doesn't support my language.
-
@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-xmlThat’s all, thanks if you look into this.
-
Could you supply a code example?
-
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]*['"]?[\w]+['"]?"> <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 (?<!-)-{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 (?<!-)-{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]*['"]?[\w]+['"]?"> <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?<=
. -
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 (?<!-)-{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="(?<=\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.