Menu

#359 Matlab syntax highlighting is broken

v1.1.x
fixed
None
v1.1.1
Bug Fix
2018-11-17
2018-07-23
Erik Hänel
No

The syntax highlighting of MATLAB files is sometimes broken. In these cases the ends are not identified correctly and the autoformatting feature is indenting everything. If one types a letter, the bug disappears.
It happens to be related to declarations like

 var = {'string1', ...
     'string2', ...
     'string3'};

Analysis:

It seems that this is related to the length of the file. The lexer doesn't always start from the very first position therefore sometimes not everything is styled incorrectly. A possible solution would be to modify the following line in wxWidgets-3.0.2\src\stc\scintilla\lexers\LexMatlab.cxx:

static void ColouriseMatlabOctaveDoc(
        unsigned int startPos, int length, int initStyle,
        WordList *keywordlists[], Accessor &styler,
        bool (*IsCommentChar)(int)) {

    WordList &keywords = *keywordlists[0];
    WordList &keywords2 = *keywordlists[1];

    // make startPos = 0
    styler.StartAt(startPos);

    bool transpose = false;

    StyleContext sc(startPos, length, initStyle, styler);
    int nParens = 0;

Implementation:

  • Implementation: The fix was done as proposed by the analysis. Additionally, the first argument of the StyleContext class was changed to 0. To apply this fix, you have to copy the lexer file to the source directory of wxStyledTextCtrl and rebuild the library.
  • Revision: [r366]
  • Implementation test: Typical erroneous files were tested. No deviations detected

Documentation:

  • ChangesLog: updated
  • Comments: External library
  • Documentation articles: Not needed - Bug fix
  • Language files: Not needed - Bug fix

Tests:

This fix was tested manually. No deviation occured.

Related

Commit: [r366]

Discussion

  • Erik Hänel

    Erik Hänel - 2018-07-23
    • status: open --> accepted
     
  • Erik Hänel

    Erik Hänel - 2018-07-23
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -4,3 +4,19 @@
          var = {'string1', ...
              'string2', ...
              'string3'};
    
    +         
    + ###Analysis:
    +(*Describe, what's the issue and which changes have to be made*)
    +
    +###Implementation:
    +* Implementation: (*Describe, what you've changed*)
    +* Implementation test: (*Describe the type of test, which you performed, and if it was succesful*)
    +
    +###Documentation:
    +* ChangesLog: (*Have you updated the changes log?*)
    +* Comments: (*Have you written comments in the code, which describe your change?*)
    +* Documentation articles: (*Have you updated the documentation articles?*)
    +* Language files: (*Have you updated the language files?*)
    +
    +###Tests:
    +(*Describe, which tests you performed and their outcome*)
    
    • status: accepted --> analyzing
     
  • Erik Hänel

    Erik Hänel - 2018-07-23
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -5,8 +5,27 @@
              'string2', ...
              'string3'};
    
    
    - ###Analysis:
    -(*Describe, what's the issue and which changes have to be made*)
    +
    +###Analysis:
    +It seems that this is related to the length of the file. The lexer doesn't always start from the very first position therefore sometimes not everything is styled incorrectly. A possible solution would be to modify the following line in wxWidgets-3.0.2\src\stc\scintilla\lexers\LexMatlab.cxx:
    +
    +    :::C++
    +    static void ColouriseMatlabOctaveDoc(
    +            unsigned int startPos, int length, int initStyle,
    +            WordList *keywordlists[], Accessor &styler,
    +            bool (*IsCommentChar)(int)) {
    +
    +        WordList &keywords = *keywordlists[0];
    +        WordList &keywords2 = *keywordlists[1];
    +        
    +        // make startPos = 0
    +        styler.StartAt(startPos);
    +
    +        bool transpose = false;
    +
    +        StyleContext sc(startPos, length, initStyle, styler);
    +        int nParens = 0;
    +
    
     ###Implementation:
    
     * Implementation: (*Describe, what you've changed*)
    
     
  • Erik Hänel

    Erik Hänel - 2018-07-27
    • status: analyzing --> implementing
     
  • Erik Hänel

    Erik Hänel - 2018-07-27
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -28,14 +28,15 @@
    
    
     ###Implementation:
    -* Implementation: (*Describe, what you've changed*)
    -* Implementation test: (*Describe the type of test, which you performed, and if it was succesful*)
    +* Implementation: The fix was done as proposed by the analysis. Additionally, the first argument of the `StyleContext` class was changed to `0`. To apply this fix, you have to copy the lexer file to the source directory of `wxStyledTextCtrl` and rebuild the library.
    +* Revision: [r366]
    +* Implementation test: Typical erroneous files were tested. No deviations detected
    
     ###Documentation:
    -* ChangesLog: (*Have you updated the changes log?*)
    -* Comments: (*Have you written comments in the code, which describe your change?*)
    -* Documentation articles: (*Have you updated the documentation articles?*)
    -* Language files: (*Have you updated the language files?*)
    +* ChangesLog: updated
    +* Comments: External library
    +* Documentation articles: Not needed - Bug fix
    +* Language files: Not needed - Bug fix
    
     ###Tests:
     (*Describe, which tests you performed and their outcome*)
    
    • status: implementing --> testing
     

    Related

    Commit: [r366]

  • Erik Hänel

    Erik Hänel - 2018-11-17
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -39,4 +39,4 @@
    
     * Language files: Not needed - Bug fix
    
     ###Tests:
    -(*Describe, which tests you performed and their outcome*)
    +This fix was tested manually. No deviation occured.
    
    • status: testing --> fixed
     

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB