Menu

#657 Code::Blocks syntax highlighting for Nim

Undefined
applied
Patch
2019-10-19
2018-04-05
Artem VL
No

Code::Blocks syntax highlighting for Nim.
Nim[rod] syntax highlighting is absent in the Code::Blocks (at least in 16.01) thought nimrod is present in the sdk/wxscintilla/include/wx/wxscintilla.h. The required lexer files are attached to display Nim entry in the Settings / Editor / Syntax highlighting to be able to adjust the syntax highlighting.
The attached lexer files should be putted to codeblocks/lexers/.

1 Attachments

Discussion

  • Artem VL

    Artem VL - 2018-04-05

    Note for the users: location fo the codeblocks/lexers on Linux Ubuntu is /usr/share/codeblocks/lexers.

     

    Last edit: Artem VL 2018-04-05
  • Teodor Petrov

    Teodor Petrov - 2018-04-29

    I've tried this lexer config and it doesn't seem to be fully functional.
    In current trunk (after the update of scintilla to 3.7.x) most of the colors doesn't affect the correct parts of the text:
    1. the doxygen documentation doesn't affect anything
    2. the comment block is affecting operators

    I don't know or use nim, so I have no idea how to fix those, so an updated version would be welcomed.

     
  • Artem VL

    Artem VL - 2018-04-29

    I have not much experience with the lexers to fix there anything beyond the config file, the provided one works to some extend for me. I just took another CodeBlocks lexer, updated id to refer Nim(rod) and added Nim keywords .
    Nim uses reStructured code docs similar to Python, so Doxygen is not applicable there.

     

    Last edit: Artem VL 2018-04-29
  • Teodor Petrov

    Teodor Petrov - 2018-04-29

    Unfortunately the nimrod lexer doesn't use its own constants, but it seems that reuses others.

    I've done a simple grep in the file for the constants.

    > grep SCE_ sdk/wxscintilla/src/scintilla/lexers/LexNimrod.cxx
        styler.ColourTo(pos-1, SCE_P_WORD);
        styler.ColourTo(pos-1, SCE_P_IDENTIFIER);
      styler.ColourTo(pos-1, SCE_P_NUMBER);
        case SCE_P_TRIPLEDOUBLE:
          styler.ColourTo(pos, SCE_P_TRIPLEDOUBLE);
              styler.ColourTo(pos, SCE_C_COMMENTLINEDOC);
              styler.ColourTo(pos, SCE_P_COMMENTLINE);
              styler.ColourTo(pos, SCE_P_STRING);
              styler.ColourTo(pos, SCE_P_TRIPLEDOUBLE);
              styler.ColourTo(pos, SCE_P_STRING);
            styler.ColourTo(pos, SCE_P_CHARACTER);
              styler.ColourTo(pos, SCE_P_IDENTIFIER);
              styler.ColourTo(pos, SCE_P_OPERATOR);
              styler.ColourTo(pos, SCE_P_DEFAULT);
            return ((style == SCE_P_TRIPLE) || (style == SCE_P_TRIPLEDOUBLE));
            int prev_state = SCE_P_DEFAULT & 31;
            int prevQuote = foldQuotes && ((prev_state == SCE_P_TRIPLE) ||
                                           (prev_state == SCE_P_TRIPLEDOUBLE));
                            quote = foldQuotes && ((style == SCE_P_TRIPLE) || (style == SCE_P_TRIPLEDOUBLE));
    

    Now all you need to do is find the numeric value for these constants and provide an options in the xml. Do some testing. Make sure that changing the colour for any option does something to the sample. When you're ready post the changes again and I'll apply them.

     
  • Teodor Petrov

    Teodor Petrov - 2018-09-10

    Any chance for an updated patch?

     
  • Artem VL

    Artem VL - 2018-09-11

    I used VSCode and Geany (when on battery) for Nim... But CodeBlocks would benefit from the Nim support and it's my favourite C++ IDE! It would be nice to not close this ticket without the fix.
    I will try to devote time for it till the end of this week.

     
  • Teodor Petrov

    Teodor Petrov - 2018-09-11

    There are no plans to close the ticket. If Geany has a syntax highlight for Nim, then you can look how they've defined it and try to copy it to Code::Blocks. The values should be similar, because C::B and Geany use the same editor component underneath - Scintilla.

     
  • Artem VL

    Artem VL - 2019-10-15

    The latest Geany v 1.36 just restyles the Python highlighting for Nim:

    [styling=Python]
    
    [keywords]
    
    primary=addr as asm atomic bind block break case cast const continue converter defer discard distinct div do elif else end enum except export finally for from func generic if import include interface iterator let macro method mixin mod notin object of out proc raise return shl shr static template try type using var when while with without yield seq array tuple ref ptr not and xor in or is isnot new
    
    identifiers=bool byte char int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 float float32 float64 string nil true false result echo assert
    
    [settings]
    
    extension=nim
    comment_single=#
    comment_use_indent=true
    tag_parser=Python
    lexer_filetype=Python
    

    The latest Scintilla has the dedicated Nim Lexer but it seems the Code::Blocks uses an outdated LexNimrod/cxx from wxWidgets , which also support Nim highlighting to some extend.

    I fixed the ids for the greped definitions as you suggested using SciLexer.h from wxWidgets, the updated lexer is attached.

     
  • Teodor Petrov

    Teodor Petrov - 2019-10-19
    • status: open --> applied
    • assigned_to: Teodor Petrov
     
  • Teodor Petrov

    Teodor Petrov - 2019-10-19

    In trunk, thanks for the contribution.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.