Menu

#1431 Support style value larger than 127

Initial
open
5
2024-11-15
2022-02-25
Zufu Liu
No

There only needs three changes in Lexilla:
1. change return type for LexAccessor::StyleAt() and LexAccessor::BufferStyleAt() to unsigned char.
2. in LexerModule::Fold(), change initStyle = static_cast<unsigned char>(styler.StyleAt(startPos - 1));
3. in StyleContext constructor, unsigned char chMask='\377'.

Incomplete changes needed in Scintilla:
1. in LexInterface::Colourise(), change styleStart = pdoc->StyleIndexAt(start - 1);
2. in Editor.cxx case Message::GetStyleAt:, change return pdoc->StyleIndexAt(PositionFromUPtr(wParam));
3. Other changes found by clang-tidy's bugprone-signed-char-misuse check.

As in most compiler configuration char is signed, these changes are need to make retrieved style value large than 127 match what defined in LexicalStyles.iface/SciLexer.h. e,g, currently HTML lexer reserved all values below 128, adding a new block (e.g. for CSS) will not work as expected.

Discussion

  • Zufu Liu

    Zufu Liu - 2022-02-25
    • summary: Support styels value largr than 127 --> Support style value larger than 127
     
  • Neil Hodgson

    Neil Hodgson - 2022-02-26

    int may be a more compatible choice as lexers use int more often and it may avoid signed/unsigned warnings. Grepping for char.*StyleAt shows 5 matches and int.*StyleAt 121.

     
  • Zufu Liu

    Zufu Liu - 2022-02-26

    Changes in Scintilla:
    1. use StyleIndexAt() for LexInterface::Colourise(), Message::GetStyleAt, gtk/ScintillaGTKAccessible, qt/ScintillaEdit/ScintillaDocument.cpp
    2. Removed cast in cocoa/ScintillaView.mm

    Changes for Lexilla added to https://github.com/ScintillaOrg/lexilla/issues/61

    ScintillaCall::UnsignedStyleAt() can be removed or marked as deprecated.

     
  • Neil Hodgson

    Neil Hodgson - 2022-03-05

    This appears too disruptive for the limited potential benefit. See https://github.com/ScintillaOrg/lexilla/issues/61 for more comments.

     
  • Zufu Liu

    Zufu Liu - 2022-03-06

    So can be marked as won't implemented. for HTML lexer it can be split into different lexers based on server side language (VB, C#, Java, PHP, Python) with common code to handle HTML tag, script and CSS.

     
    • Neil Hodgson

      Neil Hodgson - 2022-03-06

      The change to Lex and Fold could be made at the next major release but that's probably a couple of years away.

      The client-side VBScript and Python scripting is almost never used and takes up 21 styles.

      There has long been a desire to modularize the HTML lexer so different server-side and client-side scripting languages can be plugged in as desired. There are also other layers that may be placed over HTML such as template languages like Mustache and stylesheet languages like Less.

       
    • Neil Hodgson

      Neil Hodgson - 2022-03-08

      Its worthwhile adding APIs to allow moving towards better handling of styles over 127.

      Attached is a patch for GetStyleIndexAt.

       

      Last edit: Neil Hodgson 2022-03-08
  • Zufu Liu

    Zufu Liu - 2022-03-11

    It's seems to me direct change GetStyleAt to returns pdoc->StyleIndexAt() does not break existing clients that expecting signed char or what's ever, since they need to cast the result of GetStyleAt to the expected type, the value is still same after the cast.

     
    • Neil Hodgson

      Neil Hodgson - 2022-03-11

      This could fail if the application is using char for related variables, or indexing into a 256 element array with style + 128.

       
  • Neil Hodgson

    Neil Hodgson - 2022-03-15

    Committed GetStyleIndexAt as [98cf6a].

     

    Related

    Commit: [98cf6a]

  • Zufu Liu

    Zufu Liu - 2024-11-15
    • labels: --> Scintilla, lexilla, lexer
     

Log in to post a comment.