This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
LBPHacker's profile picture

Lua function parser for Notepad++

Started by LBPHacker, 17 June 2014 - 05:47 PM
LBPHacker #1
Posted 17 June 2014 - 07:47 PM
Yeah, this is for Notepad++ users only. Don't hate me.

Scrolling, scrolling and more scrolling. That's what you do when you have a big project and the source files keep growing. Notepad++ offers us the Function list, which allows us to jump around from function to function. The only problem is, it doesn't have a clue about Lua's syntax. So no Function list for Lua. What a pity.

Solving that little problem is what this topic is about.

Do it the easy wayDownload this and overwrite %appdata%\Notepad++\functionList.xml with it.
Do it the hard wayOpen your functionList.xml (%appdata%\Notepad++\functionList.xml), insert the node below into NotepadPlus.functionList.associationMap:
<association langid="23" id="lua_function"/>
and the the node below into NotepadPlus.associationMap.parsers:
<parser id="lua_function" displayName="Lua" commentExpr="((--\[=*\[.*?)\]=*\]|(--.*?$))">
    <function
        mainExpr="function\(\s*(([_A-Za-z][\w_]*|\.\.\.)\s*,?\s*)*\)|function\s+([_A-Za-z][\w_]*\.\s*)*([_A-Za-z][\w_]*[\.:]\s*)?[_A-Za-z][\w_]*\s*\("
        displayMode="$className->$functionName">
        <functionName>
            <nameExpr expr="function\(\s*(([_A-Za-z][\w_]*|\.\.\.)\s*,?\s*)*\)|\s([_A-Za-z][\w_]*\.\s*)*([_A-Za-z][\w_]*[\.:]\s*)?[_A-Za-z][\w_]*\s*\("/>
            <nameExpr expr="function\(\s*(([_A-Za-z][\w_]*|\.\.\.)\s*,?\s*)*\)|[_A-Za-z][\w_]*\s*\("/>
            <nameExpr expr="function\(\s*(([_A-Za-z][\w_]*|\.\.\.)\s*,?\s*)*\)|[_A-Za-z][\w_]*"/>
        </functionName>
        <className>
            <nameExpr expr="function\(\s*(([_A-Za-z][\w_]*|\.\.\.)\s*,?\s*)*\)|\s([_A-Za-z][\w_]*\.\s*)*([_A-Za-z][\w_]*[\.:]\s*)?[_A-Za-z][\w_]*\s*\("/>
            <nameExpr expr="function\(\s*(([_A-Za-z][\w_]*|\.\.\.)\s*,?\s*)*\)|\s([_A-Za-z][\w_]*\.\s*)*([_A-Za-z][\w_]*[\.:]\s*)?"/>
            <nameExpr expr="function\(\s*(([_A-Za-z][\w_]*|\.\.\.)\s*,?\s*)*\)|([_A-Za-z][\w_]*\.\s*)*([_A-Za-z][\w_]*[\.:]\s*)?"/>
            <nameExpr expr="function\(\s*(([_A-Za-z][\w_]*|\.\.\.)\s*,?\s*)*\)|([_A-Za-z][\w_]*\.\s*)*[_A-Za-z][\w_]*\s*[\.:]"/>
            <nameExpr expr="function|([_A-Za-z][\w_]*\.\s*)*[_A-Za-z][\w_]*\s*"/>
        </className>
    </function>
</parser>
(The editor on the forum might have messed this up; if it has, well, I'm sorry.)
Edited on 17 June 2014 - 08:16 PM
wieselkatze #2
Posted 17 June 2014 - 07:53 PM
That's pretty handy, indeed.
But it doesn't work with e.g. ["test"] = function(blah). Whatever, still shows it as function() :P/>
Thanks for sharing!
Edited on 17 June 2014 - 05:53 PM
LBPHacker #3
Posted 17 June 2014 - 08:01 PM
Yeah, it shows anonymous functions under the function class. That's intended. I can't just add a class named "Anonymous functions", the name of the class must be a part of the match from mainExpr. That's how Notepad++ processes my regex. It shows the parameters for those anonymous functions though.
wieselkatze #4
Posted 17 June 2014 - 08:22 PM
For the part I posted this is alright, but you can actually define functions in two ways.
You can either write

function blah(hi)

or

blah = function(hi)

whereas both functions would be global for the program.
Edited on 17 June 2014 - 06:22 PM
civilwargeeky #5
Posted 18 June 2014 - 06:23 AM
This is awesome :)/> Nice job
Mine isn't showing parameters for named functions. Did I do something wrong?
Edited on 18 June 2014 - 05:00 AM
LBPHacker #6
Posted 18 June 2014 - 08:18 AM
:D/> It seems the way I implemented the Function list for Lua just doesn't make sense for you all. It doesn't show function parameters for the named functions because that much text would occupy way too much space. Actually, it isn't meant to show the parameters at all, but the anonymous functions would be even harder to identify if it just displayed them as function, hence the parameters are shown.
civilwargeeky #7
Posted 18 June 2014 - 04:37 PM
Oh I see now! That makes sense.