Syntax Highlighting for MATLAB strings

Syntax Highlighting for MATLAB strings

2
NewbieNewbie
2

    Feb 10, 2005#1

    There is a problem in syntax highlighting for MATLAB strings. String char is '. But ' also means data transpose. So both

    a = [1 2]';

    and

    b = '[1 2]';

    are valid. But all following code of the first case is highlighted as string as an open string is detected which is not closed. This makes no sense. A string can not be longer than one line.

    My MATLAB word file starts with:

    /L12"MATLAB M" Nocase Line Comment Num = 2% Block Comment On = %{ Block Comment Off = %} String Chars = ' File Extensions = bi m M
    /Function String = "%[ ^t]++function[ ^t]+*=[ .^t^p]+^([a-z0-9_]+^)"
    /Function String 1 = "%[ ^t]++function[ ^t]+[ .^t^p]+^([a-z0-9_]+^)"
    /Delimiters = ~!@$^&*()-+=|\/{}[]:;"'<> , .?

    Any ideas?

    tbeu

    6
    NewbieNewbie
    6

      Feb 10, 2005#2

      UltraEdit can't currently handle this properly... I have the same problem with a different language. There are two workarounds I can think of.

      The first is to remove the <String Chars = '> from the /L12 line. This will have two effects: it will cause " to start being used as a string delimiter too, but it will also turn off multi-line strings, so in your case with "a = [1 2]", only the ; will be incorrectly highlighted.

      The other is not to define ' as a string delimiter (so you won't get higlighted strings any more, but you also won't have the problem you describe); unfortunately, to do that, I think you'll have to define some other character as a string delimiter... if there's anything in MATLAB that's suitable.

      For a better solution, I suspect your only hope is to contact IDM and see if they're willing to add better MATLAB support.

      2
      NewbieNewbie
      2

        Feb 10, 2005#3

        This happens only with UE 11.00 which allows multi-line strings.

        tbeu

        6,686585
        Grand MasterGrand Master
        6,686585

          Jan 17, 2006#4

          To turn off multi-line string highlighting add DisableMLS at the language definition line.

          /L12"MATLAB M" Nocase Line Comment Num = 2%  Block Comment On = %{ Block Comment Off = %} String Chars = ' DisableMLS File Extensions = bi m M

          Now the setting String Chars = ' will only highlight the rest of the current line if a single ' exists as data transpose. This would be the '; of the first example line of tbeu. It's not the best solution, but better than nothing.

          I don't have any experience with MATLAB so I can't help you to find a better solution for this problem.
          Best regards from an UC/UE/UES for Windows user from Austria

          2
          NewbieNewbie
          2

            Oct 15, 2009#5

            I have downloaded a matlab wordfile from the site:
            http://www.mathworks.com/matlabcentral/ ... hange/1000

            i have changed its extension to uew, put this txt file to
            C:\Documents and Settings\my user name\Application Data\IDMComp\UltraEdit\wordfiles

            i restart ultraedit
            i couldn't find the matlab choice in View/View as menu
            can you help me how to install a wordfile?

            6,686585
            Grand MasterGrand Master
            6,686585

              Oct 15, 2009#6

              First verify in the syntax highlighting configuration dialog if UltraEdit really uses the wordfile directory which contains the modified Matlab.uew.

              After renaming WORDFILE.TXT to Matlab.uew I would also change the first line of this wordfile to:

              /L6"Matlab" Nocase Line Comment = % String Chars = ' DisableMLS File Extensions = M

              I think you did not find the matlab language in the menu because the name was M File. And the file extension is not case sensitive and therefore m M is not necessary, just M is enough. DisableMLS disables multi-line string highlighting. I don't know if Matlab supports multi-line strings or not. Because there is no escape character defined, I guess it does not support it. The default is that multi-line string highlighting is enabled and so I think DisableMLS would be good.

              And I would give the 4 color groups a name. For example

              /C1"Keywords"

              /C2"Functions"

              /C3"Parameters"
              (Hope this is a correct name for the keywords in this color group.)

              /C4"Delimiters"

              Everything else in this wordfile looks good. Keyword surface is not correct sorted in and there are 2 duplicate words: inf Inf and nan NaN. They are duplicate because the language is defined as being not case sensitive.

              I found out that on the Wordfiles page also a Matlab wordfile on IDM's server is referenced and this wordfile is very similar to the one you downloaded. On the server of IDM there is a second Matlab wordfile not referenced on the wordfiles download page. I'm not a Matlab expert and therefore can't evaluate which one is the better. I made my corrections on the referenced file matlab6.uew.

              It would be good if you can further improve this modified wordfile for Matlab by adding appropriate

              /Indent Strings =
              /Unindent Strings =
              /Open Brace Strings =
              /Close Brace Strings =
              /Open Fold Strings =
              /Close Fold Strings =

              settings below the function list lines to the wordfile for using:

              auto indent and unindent if indentations are used in Matlab files,
              auto-brace matching for automatically highlighting matching braces,
              code folding if Matlab files are structured in blocks and therefore code folding could be useful.

              Finally send the further improved wordfile to IDM by email to update existing matlab6.uew.
              matlab6.zip (1.78 KiB)   480
              Corrected and improved matlab6.uew from IDM's server.

              2
              NewbieNewbie
              2

                Oct 15, 2009#7

                Thank you very much for your interest.
                I have found my problem.
                My UltraEdit version is 14, and in this version wordfile adding is not a simple copy and paste the uew file to wordfiles directory.