Menu

Lexer plugin using .NET

Anonymous
2015-04-14
2015-04-27
  • Anonymous

    Anonymous - 2015-04-14

    Hi all,

    I just wanted to ask, if anyone of you have some idea on how to go about implementing a lexer dll based on the Notepad++ npp template.

    I've written a CPP lexer which works pretty well :

    https://github.com/sanastasiou/RTextNpp/tree/master/RTextLexer

    however, the lexer is just a part of a larger plugin which is currently in development. I've decided to use the "official" way of installing plugins via the plugin manager, so that would mean that the user would have to install two .dlls ( one just to get folding, syntax highlighting ) and one to get all the other features.

    I have managed to export all the functions that are required from the lexer directly from .net

        [DllExport(CallingConvention = CallingConvention.StdCall)]
        static void GetLexerName(uint index, StringBuilder name, int bufLength)
        {
            name.Append("&RTextLexer");
        }
    
        [DllExport(CallingConvention = CallingConvention.StdCall)]
        static void GetLexerStatusText(uint index, [MarshalAs(UnmanagedType.LPWStr, SizeConst = 32)]StringBuilder desc, int bufLength)
        {
            desc.Append("RText file.");
        }
    
        [DllExport(CallingConvention = CallingConvention.StdCall)]
        static int GetLexerCount()
        {
            return 1;
        }
    
        static RTextLexerCliWrapper _lexerWrapper = new RTextLexerCliWrapper();
    
        [DllExport(CallingConvention = CallingConvention.StdCall)]
        static IntPtr GetLexerFactory(uint index)
        {            
            return (index == 0) ? _lexerWrapper.GetLexerFactory() : IntPtr.Zero;
        }
    

    I can debug and see the function being called, I can see the lexer name and file status on notepad++ but the text is not getting highlighted, which means that something is going wrong with the lexer factory.

    Maybe some of you can point out where I can debug for this? I have compiled the Notepad++ and Scintilla sources and can debug. There is no exception being thrown etc. And folding works. I assume that somehow some "default" lexer is being used instead of mine.

    I could provide more information if needed. Project is open source and can be found there

    https://github.com/sanastasiou/RTextNpp/

    Best Regards

     

    Last edit: Anonymous 2015-04-14
  • Anonymous

    Anonymous - 2015-04-18

    Some success. My lexer gets instantiated and my Lex and Fold functions are called. While folding works perfectly, the Lex function, although called appears to have no effect i.e. the text remains not highlighted.

    I believe therefore this to be some problem with the .xml file of the lexer. Maybe wrong name or something..

    Have anyone had such a problem already? That although the lex function is called the text remains without highlighting?

    Regards

     

    Last edit: Anonymous 2015-04-18
  • Anonymous

    Anonymous - 2015-04-18

    I have solved my problem. I now have a .NET dll which has lexer capabilities. I believe this is world's first attempt to do this :).

    I'll try to contact the Npp.NET template author and provide a template with basic support for Lexers.

    Cheers

     
  • UFO

    UFO - 2015-04-21

    Hi,

    great work! If you've got anything useful for the template to add, then you could, for instance, also post it over here: https://bitbucket.org/uph0/npppluginnet/issues

    Regards

     
  • Anonymous

    Anonymous - 2015-04-27

    Hi UFO,

    ok. I am currently under a lot of stress at work :) but once I have some free time I'll post it there.

     
  • Anonymous

    Anonymous - 2015-04-27

    Should I just create an issue with my snippets?