heredoc highlighting needed

heredoc highlighting needed

7

    Mar 20, 2006#1

    Hi, I've tried to create a heredoc highlight for both Bash and for PHP and for Perl, but no joy. I'm okay with basic Syntax Highlighting but i don't know where to start with this. From what I can muster, it's almost like a multiline comment, syntactically, but i'd like the whole heredoc section to have it's own color.

    the syntax is the same for all three languages:

    e.g., Bash:

    Code: Select all

    cat <<_EOF_
    Here is some text. I won't use highlighting for Bash
    because if I use a heredoc (which i frequently do for HELP
    command line arguments, and I use a contraction, then
    the rest of my code is all blue until i happen to use another
    contraction or have a single apostrophe lower down in the code.
    That is not good.
    _EOF_
    
    the "_EOF_" in the example above can be any word that's not reserved in the language in which you're coding and can obviously use the underscore character, too. :)

    Any help with this would be MOST APPRECIATED!

    Sincerely,

    the snakester

    P.S. - If it can't be done, just let me know. I'll stop worrying about it. If it were easy, it'd already be included! :)

    6,681583
    Grand MasterGrand Master
    6,681583

      Mar 21, 2006#2

      First I have to read something about heredoc. I used the info from PHP: Strings - Manual.

      The problem for the syntax highlighting engine of UltraEdit is that the identifier string can vary as you have also mentioned and it exists twice, at begin and at the end of the heredoc block. The syntax highlighting engine of UE is a simple string compare engine not an interpreter.

      In the PHP manual it is explaind that the heredoc string starts with <<< and it is allowed to add a ; immediatelly after the heredoc end tag. (Is a < missing in your example?) I don't know if this is also true for Bash and Perl and if the ; at the end could have a bad effect on the PHP/Bash/Perl command before the heredoc block.

      If there is no problem with the ; at the end and the heredoc block really always starts with <<< you could use the alternate block comment as follows in the 3 languages:

      Block Comment On Alt = <<< Block Comment Off Alt = ;

      Note: If the string in the heredoc section also contains a ; the highlighting will end at this semicolon and not the real end.

      If the semicolon cannot always be added to end of the heredoc section then I'm afraid of there is no possible solution to highlight it.
      Best regards from an UC/UE/UES for Windows user from Austria

      119
      Power UserPower User
      119

        Mar 21, 2006#3

        Heredocs are multiline strings, not comments. While UE does support multiline strings, it doesn't support multi-character string delimiters, so heredocs don't work (and that's ignoring the fact that you could use anything for the delimiters). You could use multiline strings and escape the literal quotes. You could use a heredoc and live with the screwy highlighting. If you're willing to restrict yourself to the same delimiter, you might be able to use the block comment as Mofi suggested. The following works for a typical Perl case, but it's fragile and won't work everywhere. And of course it highlights as a comment, not as a string, but you could set the color for alternate block comments to match the color for strings.

        Code: Select all

        /Block Comment On Alt = <EOT;
        /Block Comment Off Alt = EOT

        6
        NewbieNewbie
        6

          Jan 08, 2013#4

          I need help with this same issue. The format of the PHP language file seems to be different now. I tried:

          Code: Select all

          /L8"PHP" PHP_LANG Nocase EnableMLS Line Comment = // Line Comment Alt = # Block Comment On = /* Block Comment Off = */ Block Comment On Alt = <<<EOT Block Comment Off Alt = EOT Escape Char = \ String Chars = "' File Extensions = INC PHP3 PHP4 PHP5
          But it doesn't seem to do anything. So how can I get syntax highlighting to work for me, assuming I always use the same <<<EOT to start a heredoc string and EOT to end it?

          8 hours later:

          I contacted tech support. After a little back and forth the following seems to work OK:

          Code: Select all

          /L8"PHP" PHP_LANG Nocase EnableMLS Line Comment = // Line Comment Alt = # Block Comment On = /* Block Comment Off = */ Block Comment On Alt = <<< Block Comment Off Alt = EOT; Escape Char = \ String Chars = "' File Extensions = INC PHP3 PHP4 PHP5
          I'm not sure why it needs the semicolon after EOT to work, but anyway that does it for me. I also changed the color for Alt Block Comment to be the same as strings.

          As noted in the other posts it's not true heredoc support, but it works if you always use the same terminator. I hope they will add real heardoc support soon.