Tapatalk

pascal string highlighting problem

pascal string highlighting problem

3
NewbieNewbie
3

    Jun 11, 2005#1

    Starting with version 11.10 pascal string highlighting gets confused when a string embeds comment braces. For example these lines are ok

    raise InvalidCastException.Create(System.string.Format('Interface: {0} ',[A]));
    raise InvalidCastException.Create(System.string.Format('Interface: {0} ArrayIndex: {1} ',[A,B]));

    but these are not ( note the char sequence }' )

    raise InvalidCastException.Create(System.string.Format('Interface: {0}',[A]));
    raise InvalidCastException.Create(System.string.Format('Interface: {0} ArrayIndex: {1}',[A,B]));

    After them all the text is highlighted as a string (red in my case). I found no solution but to remove String Chars = ' from WORDFILE.TXT
    Any suggestion?

    6,685587
    Grand MasterGrand Master
    6,685587

      Jun 25, 2005#2

      I have tried your example lines with the pascal wordfile from the download area with V10.10c and V11.10a+3. In both versions all 4 strings in the 4 lines are highlighted completely as strings. The embedded block comments {0} did not have any influence on the string highlighting.

      Could you post your language definition line and the delimiters definition from your wordfile and colorize your example lines. Use the preview button before submit your post.
      Best regards from an UC/UE/UES for Windows user from Austria

      3
      NewbieNewbie
      3

        Jun 30, 2005#3

        Thank you for your answer.

        This is my language definition:

        /L6"Delphi" Nocase Line Comment = // Block Comment On = { Block Comment On Alt = (* Block Comment Off = } Block Comment Off Alt = *) Escape Char = · String Chars = ' File Extensions = pas dpr dpk
        /Delimiters = #$&()*+,-./;<>@[]^{}tab'
        /Function String = "%^{procedure^}^{function^}"
        /Indent Strings = "begin" "const" "then" "else" "private" "protected" "public" "published" "type" "record" "var" "asm"
        /Unindent Strings = "end" "until"
        /Open Brace Strings =  "{" "(" "["
        /Close Brace Strings = "}" ")" "]"
        /Open Fold Strings = "begin"
        /Close Fold Strings = "end"
        /C1"Keywords"
        array as asm
        begin
        case class const constructor
        destructor dispinterface do downto
        else end except
        file finalization finally for function
        goto
        helper
        if implementation in inherited initialization inline interface is
        label library
        nil
        object of on out
        packed procedure program property
        raise record repeat resourcestring
        set string
        then threadvar to try type
        unit until uses
        var
        while with
        /C2"Directives"
        add at absolute abstract assembler automated
        cdecl contains
        default dispid dynamic
        exports external
        far final forward
        implements index
        message
        near nodefault
        overload override
        package pascal private protected public published
        read readonly register reintroduce remove requires resident
        safecall sealed static stdcall stored strict
        virtual
        write writeonly
        /C3"Operators"
        and as
        div
        in is
        mod
        not
        or
        shl shr
        xor
        /C4"Special symbols"
        *
        +
        -
        /
        < <= <>
        =
        > >=
        @
        #
        $
        &
        (
        (.
        )
        ,
        .
        .)
        ..
        :
        :=
        ;
        [
        ]
        ^

        This is more complete sample of a file where the problem appears. I use red for strings and I have colorized in red what appears in that color in my editor

        unit Commons.AbstractFactory;

        interface

        uses
          System.Collections;

        type
          TAbstractFactoryKey = class abstract (TObject)
          protected
            function StringKey: string; virtual; abstract;
          end;
          TAbstractFactory = class (TObject)
          public type
            EAbstractFactory = class(Exception);
            EMissingFactory = class(EAbstractFactory);
            EFactoryWrongClass = class(EAbstractFactory);
          strict private
            class var
              FactoryClassList: HashTable;
          strict private
            &Class: TClass;
          strict private
            class function FactoryList: HashTable;
            class constructor Create;
          public
            class function ClassFromKey(Key: string; RequiredClass: TClass): TClass; overload;
            class function ClassFromKey(Key: TAbstractFactoryKey; RequiredClass: TClass): TClass; overload;
          public
            constructor Create(&Class: TClass); overload;
            constructor Create(Key: string; &Class: TClass); overload;
            constructor Create(Key: TAbstractFactoryKey; &Class: TClass); overload;
          end;

        {$region 'Esempio di derivazione'}{

        // Data una classe TMyClass, origine di una gerarchia di classi, vogliamo una factory per esse.
        // TMyClass deve avere un costruttore virtuale, non ci sono vincoli sulla sua lista di parametri.

          TMyClass = class (...)
            .
            .
            constructor Create(<create args list>); virtual;
          end;

        // La factory deve derivare da TAbstractFactory e implementare una o ambedue le forme di Produce che,
        // dopo il parametro Key, devono ripetere la lista di parametri del costruttore virtuale di TMyClass.

          TMyClassFactory = class(TAbstractFactory)
          public
            class function Produce(Key: string; <create args list>): TMyClass; overload;
            class function Produce(Key: TAbstractFactoryKey; <create args list>): TMyClass; overload;
          end;

        // Una volta definita la factory per ognuna delle classi T derivate da TMyClass occorre creare la factory
        // corrispondente utilizzando nella initialization della unit uno dei constructor

          // In questo caso la chiave per T e' il suo class name.
          TMyClassFactory.Create(T);

          // In questo caso la chiave per T e' 'Key for T'.
          TMyClassFactory.Create('Key for T',T);

          // In questo caso la chiave per T e' ottenuta dai valori passati al constructor della chiave.
          TMyClassFactory.Create(TMyClassFactoryKey.Create(<key parameters>),T);

        // Per una stessa classe e' anche possibile creare piu' factory con chiavi diverse.
        // Per utilizzare la factory per creare una classe T derivata da TMyClass in base ad una chiave
        // si usa una delle forme di Produce

          O := TMyClassFactory.Produce(Key,<create args list>);

        // dove Key e' una stringa (case insensitive) o una istanza di TMyClassFactoryKey.

        }{$endregion}

        {$region 'Utilizzo di TAbstractFactoryKey'}{

        // Quando come chiave per la factory si voglia usare un insieme di informazioni invece di una
        // semplice stringa e' conviente derivare TAbstractFactoryKey

          TMyClassFactoryKey = class(TAbstractFactoryKey)
          protected
            function StringKey: string; override;
          public
            Info1: string;
            .
            .
            constructor Create(Info1: string; ...);
          end;

        // La funzione StringKey deve combinare tutti i campi pubblici ottenendone una stringa (case insensitive)
        // dipendente solo dal loro valore. Il constructor, opzionale, serve a inizializzare in una sola linea
        // tutti i campi pubblici.

        }{$endregion}

        implementation

        { TAbstractFactory }

        class function TAbstractFactory.FactoryList: HashTable;
        begin
          Result := FactoryClassList[TObject(Self)] as HashTable;
          if not Assigned(Result) then begin
            Result := HashTable.Create(CaseInsensitiveHashCodeProvider.Create,CaseInsensitiveComparer.Create);
            FactoryClassList.Add(TObject(Self),Result);
          end;
        end;

        class constructor TAbstractFactory.Create;
        begin
          FactoryClassList := HashTable.Create;
        end;

        class function TAbstractFactory.ClassFromKey(Key: TAbstractFactoryKey; RequiredClass: TClass): TClass;
        begin
          Result := ClassFromKey(Key.StringKey,RequiredClass);
        end;

        class function TAbstractFactory.ClassFromKey(Key: string; RequiredClass: TClass): TClass;
        var
          Factory: TAbstractFactory;
        begin
          Factory := TAbstractFactory(FactoryList[Key]);
          if Assigned(Factory) then begin
            Result := Factory.&Class;
            if not Result.InheritsFrom(RequiredClass) then
              raise EFactoryWrongClass.Create(System.string.Format('Factory for class {0} produces wrong class ({1})',[RequiredClass.ClassName,Result.ClassName]));
          end
          else
            raise EMissingFactory.Create(System.string.Format('No factory found for key {0}',[Key]));
        end;

        constructor TAbstractFactory.Create(&Class: TClass);
        begin
          Create(&Class.ClassName,&Class);
        end;

        constructor TAbstractFactory.Create(Key: string; &Class: TClass);
        begin
          inherited Create;
          Self.&Class := &Class;
          FactoryList.Add(Key,Self);
        end;

        constructor TAbstractFactory.Create(Key: TAbstractFactoryKey; &Class: TClass);
        begin
          Create(Key.StringKey,&Class);
        end;

        {$region '
        Esempio di derivazione'}{

        // Le Produce devono avere questa forma in cui compare il nome della classe base TMyClass,
        // la dichiarazione della sua metaclasse TMyClassClass, e i parametri passati invariati al costruttore.

        class function TMyClassFactory.Produce(Key: string; <create args list>): TMyClass;
        type
          TMyClassClass = class of TMyClass;
        begin
          Result := TMyClassClass(ClassFromKey(Key,TMyClass)).Create(<create args values>);
        end;

        class function TMyClassFactory.Produce(Key: TAbstractFactoryKey; <create args list>): TMyClass;
        type
          TMyClassClass = class of TMyClass;
        begin
          Result := TMyClassClass(ClassFromKey(Key,TMyClass)).Create(<create args values>);
        end;

        }{$endregion}

        end.

        6,685587
        Grand MasterGrand Master
        6,685587

          Jul 01, 2005#4

          I think, you have found a bug in UE's syntax highlighting code. It's really highlighted wrong with your correct definition. You should write a bug report email to IDM's support with explaining the problem and attaching your sample file and your wordfile. Interesting is that this wrong highlighting occurs only for files with extension PAS, but not for files with extension DPR or DPK. It looks like there are built-in syntax highlighting definitions for PAS (and P DEF PFC) which are not working correct (UE v11.xx) and which can't be overwritten with a syntax highlighting language definition in the wordfile.
          Best regards from an UC/UE/UES for Windows user from Austria

          3
          NewbieNewbie
          3

            Jul 01, 2005#5

            Thank you wery much for your help.
            I will notify IDM for the bug ASAP.