Pascal file is rendered as a comment (fixed)

Pascal file is rendered as a comment (fixed)

4
NewbieNewbie
4

    Nov 15, 2010#1

    Greetings!
    The following line in the Syntax Highlighting file render all pascal program file as a comment, may you advice why?

    /L20"BPW" Nocase Line Comment = { Block Comment On = { Block Comment Off = } Block Comment On Alt = (* Block Comment Off Alt = *) NestBlockComments Escape Char = "' String Chars = ' EnableMLS File Extensions = PAS INC DEF *

    best regards

    reuven

    6,604548
    Grand MasterGrand Master
    6,604548

      Nov 15, 2010#2

      First, Block Comment On = { Block Comment Off = } is a senseless block comment definition because the line comment definition Line Comment = { always "wins" here. Line and block comment starting strings must be different. If Pascal interprets { as line comment as well as block comment starting string UltraEdit will not be able to highlight block comments using { } correct.

      After reading briefly some webpages about Pascal syntax I think the block comment definition is correct and the line comment definition is wrong because I could not read on any of those pages that Pascal supports line comments at all. Interesting is that the Pascal wordfile from wordfiles page submitted by a user has a different first line than you posted and than another user posted at pascal string highlighting problem


      Second, Escape Char = "' String Chars = ' is definitely not correct. I think it should be just String Chars = '". It is possible to define 2 characters for string start/end, but only 1 character can be defined as escape character for the string character inside strings. This could be the reason why your Pascal files are highlighted completely as strings. EnableMLS enables multi-line string highlighting which I think is correct for Pascal. But with wrong string characters and escape character definition it can happen very easily that UltraEdit highlights everything as string starting from first string with an escaped string character inside.

      The Wikipedia page String literal explains that in Pascal the string start/end character must be used doubled to escape it. For correct highlighting such strings it is better to define no escape character. Then UE would read double quoted strings with double " or single quoted strings with double ' inside as 3 or more strings, but that does not matter for syntax highlighting or spell checking.

      Perhaps UE uses an internal default for an escape character if a wordfile does not contain Escape Char = and therefore it is necessary to overwrite this internal definition by a definition in the wordfile using a character as escape character which usually does not exist in strings. That would be an explanation why Escape Char = · was used by the other user for Delphi as posted at pascal string highlighting problem.


      BTW: You can use the language marker PASCAL_LANG on the first line of your wordfile after /L20"BPW". This language marker string is defined in UltraEdit as documented on help page Syntax Highlighting. But I don't know which effect this language marker string has if it has one at all.

      4
      NewbieNewbie
      4

        Nov 15, 2010#3

        Thank you Mofi.

        When I removed NestBlockComments there is no errors with the syntax highlighting.

        /L20"BPW" Nocase Block Comment On = { Block Comment Off = } Block Comment On Alt = (* Block Comment Off Alt = *) Escape Char = ' String Chars = '" EnableMLS File Extensions = PAS INC DEF *

        When I add NestBlockComments as below:

        /L20"BPW" Nocase Block Comment On = { Block Comment Off = } Block Comment On Alt = (* Block Comment Off Alt = *) NestBlockComments Escape Char = ' String Chars = '" EnableMLS File Extensions = PAS INC DEF *

        the entire file was rendered as comment.

        The question why NestBlockComments effecting the syntax highlighting?

        Best regards

        6,604548
        Grand MasterGrand Master
        6,604548

          Nov 16, 2010#4

          What happens if you use following language definition:

          /L20"BPW" PASCAL_LANG Nocase Block Comment On = { Block Comment Off = } Block Comment On Alt = (* Block Comment Off Alt = *) NestBlockComments Escape Char = · String Chars = '" EnableMLS File Extensions = PAS INC DEF *

          Does this wrong comment highlighting also happen if you change the file extension of the Pascal file from PAS to INC?

          It looks like there are built-in syntax highlighting definitions in uedit32.exe for files with file extension P PAS DEF PFC resulting in highlighting such files as PASCAL with ignoring partly the definitions in the wordfile resulting in perhaps wrong highlighting *.pas files.
          Best regards from an UC/UE/UES for Windows user from Austria

          4
          NewbieNewbie
          4

            Nov 16, 2010#5

            Greetings Mofi
            When I changed the header as you recommended the same result. Also changed the file to be .INC, still the same result.

            Attached is the file I am speaking about.

            Thank you Mofi for your assistance.

            Best Regards

            Reuven
            Example.zip (5.86 KiB)   408
            Example Pascal file

            6,604548
            Grand MasterGrand Master
            6,604548

              Nov 16, 2010#6

              Okay, I downloaded and opened your Pascal file and downloaded and used the Pascal wordfile. I changed only the first line of the Pascal file first to following:

              /L20"Pascal" PASCAL_LANG Nocase Block Comment On = { Block Comment Off = } Block Comment On Alt = (* Block Comment Off Alt = *) String Chars = '" File Extensions = PAS INC DEF

              With that wordfile the syntax highlighting of your example Pascal file is correct, nothing highlighted wrong. Your Pascal file contains nested block comments because some block comments using { } are inside block comments defined by (* *). But for such block comment nesting there is no need to use NestBlockComments. The feature for nesting block comments is only needed when block comments exist within block comments of the same type, i.e. a block with { } inside a block with { }, or a block with (* *) inside a block with (* *).

              I exchanged the 2 block comment definitions in the wordfile and used it next with following as first line:

              /L20"Pascal" PASCAL_LANG Nocase Block Comment On = (* Block Comment Off = *) Block Comment On Alt = { Block Comment Off Alt = } String Chars = '" File Extensions = PAS INC DEF

              Again the syntax highlighting was 100% correct. So the block comment definition order does not matter.

              Next I inserted keyword NestBlockComments and so tried

              /L20"Pascal" PASCAL_LANG Nocase Block Comment On = (* Block Comment Off = *) Block Comment On Alt = { Block Comment Off Alt = } NestBlockComments String Chars = '" File Extensions = PAS INC DEF

              and later also

              /L20"Pascal" PASCAL_LANG Nocase Block Comment On = (* Block Comment Off = *) Block Comment On Alt = { Block Comment Off Alt = } NestBlockComments String Chars = '" File Extensions = PAS INC DEF

              And you are absolutely correct. With NestBlockComments added to the wordfile the entire example Pascal file is highlighted as comment. This is independent of the file extension, but definitely dependent of file content.

              While playing with your example Pascal file and the wordfile I had opened one of my C files with file extension changed to PAS. So my C file was highlighted with the Pascal wordfile. My C file was always highlighted with the Pascal syntax highlighted as I expected it. The multiple nested { } blocks of my C file were highlighted as block comment wrong without NestBlockComments as expected and correct with NestBlockComments as also expected. But your example Pascal file is at the same time highlighted wrong with using NestBlockComments. Strange, very strange. Inserting one } at top of your example Pascal file solves the wrong highlighting which lets me think there is a buffer overlow problem inside uedit32.exe. I will report this issue to IDM by email.

              In the meantime don't use NestBlockComments as it is not necessary.

              Update: This syntax highlighting issue was fixed with UE v17.30.0.1002.
              Best regards from an UC/UE/UES for Windows user from Austria

              4
              NewbieNewbie
              4

                Nov 17, 2010#7

                Mofi thank you very much.
                IDM support was acknowledged about this issue.

                2362
                MasterMaster
                2362

                  May 01, 2012#8

                  Just a note for future users that may be trying to enable NestBlockComments in a Pascal (or Delphi) wordfile.

                  The Pascal language definition does not allow for Nested Block Comments. They are not legal in the official language. I would encourage you not to use them in your programs if you are currently using a compiler that actually allows for it, because it is not standard and will not produce portable code.

                  This is the reason that you are having trouble with NestBlockComments when you have it defined as a PASCAL_LANG.