Recent

Author Topic: [SOLVED] Expanded syntax highlighting...  (Read 1748 times)

GypsyPrince

  • New Member
  • *
  • Posts: 35
[SOLVED] Expanded syntax highlighting...
« on: June 09, 2020, 05:54:48 pm »
Currently, when setting the syntax highlight display colors for various elements, such as variable names, constant names, parameters, calls to procedures/functions, keyword "True", keyword "False", most data type names (boolean, int64, string, etc.), and a couple others all fall under the 'Identifiers' element.

Would it be much trouble to divide all of these out in the next release - allowing each element to have its own syntax color?

Of course, the True/False keywords should probably use the same color as (and fall under) the 'Reserved word' element. I thought it would be nice to be able to differentiate variables, constants, and parameters from each other.  Likewise, I thought it would be a nice option to be able to assign the same color to the procedure and function names used in calls to them as the color assigned to the 'Procedure header name' element (procedure/function declaration and definition).

Code: Pascal  [Select][+][-]
  1. //The name "FeatureHold" in this declaration should be the same color as in the call below.
  2. Procedure FeatureHold(AppTitle: String; Locale: Int64; IsNew: Boolean = True);
  3. Begin
  4.   Try
  5.  
  6.       ShowMessage('Sorry! The requested procedure, function, or other feature is not yet available.');
  7.  
  8.   Except On errRntm: Exception Do
  9.     Begin
  10.         //Handle any error here.
  11.     End;
  12.   End;
  13. End;
  14.  
  15. Procedure TMainForm.mnuPrntClick(Sender: TObject);
  16. Begin
  17.   Try
  18.  
  19.       //The name "FeatureHold" in this call should be the same color as in the declaration above.
  20.       FeatureHold(AppName, AppLCID, True);
  21.  
  22.   Except On errRntm: Exception Do
  23.     Begin
  24.         //Handle any error here.
  25.     End;
  26.   End;
  27. End;
  28.  

If extending this feature would prove to be more trouble than it's worth, then don't worry about fooling with it.
« Last Edit: June 09, 2020, 06:58:07 pm by GypsyPrince »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9855
  • Debugger - SynEdit - and more
    • wiki
Re: Expanded syntax highlighting...
« Reply #1 on: June 09, 2020, 06:27:46 pm »
Unfortunately its not that easy.
The highlighter does a basic search, based on the simple syntax rules of the language. It only looks at one line/statement at a time. It only keeps basic state info, like being in a var block.

So in
Code: Pascal  [Select][+][-]
  1. var
  2.   Foo: TMyClass;
  3.   FooClass: class of TMyClass;
It would know "Foo" is a variable (because it is before the ":"), and "TMyClass" is a type.

However in the procedure body that is not always the case:
Code: Pascal  [Select][+][-]
  1. FooClass := TMyClass;
without any context, you can not tell what TMyClass is. It could be another variable, it could be a type, or a function, or constant, or param....

To know what it is, the highlighter would need to keep track of the entire codebase (like codetools does).
Changes in another unit could change the highlight (because if TMyClass is from another unit, it could change from a variable to a function).

Or "FeatureHold" in your example. Seems easy at first, but if there is
Code: Pascal  [Select][+][-]
  1. with RecordThatHasFieldFeatureHold do begin
  2.   a := FeatureHold;  // field of the record
  3. end;
Again codetools does that already, but  codetools on the other hand only recomputes occasionally.

And Highlight means every keystroke would require a lot of re-computing.

Well modern PC can handle this, but its a lot of code that needs to be implemented. (and that is not on the Todo list at the moment).

---
You can highlight fixed keywords. Such as True, False, break, exit, continue...  by using "user defined markup" in the Tools > Options > Editor.
(Though that will highlight them in strings and comments too)

GypsyPrince

  • New Member
  • *
  • Posts: 35
Re: Expanded syntax highlighting...
« Reply #2 on: June 09, 2020, 06:57:47 pm »
Okee dokee. No worries!  :D

 

TinyPortal © 2005-2018