Recent

Author Topic: Extending the Pascal highlighter with new elements  (Read 1103 times)

furious programming

  • Hero Member
  • *****
  • Posts: 858
Extending the Pascal highlighter with new elements
« on: March 13, 2023, 12:56:10 pm »
The current highlighter supports the separate coloring of a large number of elements of the language syntax, but compared to, for example, Visual Studio Code, some meaningful elements coloring are missing. I don't know exactly how the highlighter works and what information it has access to, but I would love to be able to set a new style for the following elements:

  • data type identifier — wherever it occurs, e.g. declaration in the type block, local constants and variables declaration, routine parameters, casting inside the code block, etc.
  • structure members — identifiers after the dot operator, of any level of nesting. In this case, the main (first) identifier would have the same style as the identifiers currently have, while all subsequent identifiers after the dot operators would have a separate style.
  • routine calls — separate style for routine calls inside code blocks. This style should also override the members style so that method calls after the dot operator are also colored.

What do you think? Is it possible to add separate styles for the above-mentioned elements?
Lazarus 3.2 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an acrade, action/adventure game in retro style (pixelart), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9910
  • Debugger - SynEdit - and more
    • wiki
Re: Extending the Pascal highlighter with new elements
« Reply #1 on: March 13, 2023, 01:17:23 pm »
For type names
https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/22711

In general all fine ideas,  but not likely very soon.

Well the "structure members" might be an easy one. That is, if they can be detected by the following rule.
- Inside a code block. Though that depends on what is wanted
- any identifier that follows after a dot.
- no other rules

The code block depends.
Obviously this should not count? "bar" is a member, but....
Code: Pascal  [Select][+][-]
  1. procudure TFoo.bar();

But what about. Note that however the HL does not know if TFoo is a class or a unit.
Code: Pascal  [Select][+][-]
  1. type MyBarForward = TFooClass.TBar // TBar is "public type"




In general the HL at current works on the basis of a one-pass concept. It determines all decisions based on what was before. It does not look ahead. (Though eventually that will in a very extremely limited way become a necessity)

The HL also is not codetools. It does not know if a specific identifier has been seen before. If it sees "TFoo" it doesn't know, if at anytime there was a "type TFoo =". (same for function names). And since the HL also never scans other units, this isn't changing.

Yet such highlight is possible, for that there exists "Markup". There just does not yet exist a markup that gets such info from codetools.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9910
  • Debugger - SynEdit - and more
    • wiki
Re: Extending the Pascal highlighter with new elements
« Reply #2 on: March 13, 2023, 01:21:26 pm »
This style should also override the members style so that method calls after the dot operator are also colored.

All styles/markups already have priorities, that can be set separately for each of their foreground/background/frame/style(bold,italic).
So it can already be configured which style takes precedence.

Styles can also mix (colors have an alpha channel).

furious programming

  • Hero Member
  • *****
  • Posts: 858
Re: Extending the Pascal highlighter with new elements
« Reply #3 on: March 13, 2023, 02:26:06 pm »
In general all fine ideas,  but not likely very soon.

Of course, I understand. I will be waiting impatiently for new elements to color.

Quote
Well the "structure members" might be an easy one. That is, if they can be detected by the following rule.
- Inside a code block. Though that depends on what is wanted
- any identifier that follows after a dot.
- no other rules

Exactly. But this requires checking, because the members after the dot operator are given in many cases and each should be checked.

Quote
Obviously this should not count? "bar" is a member, but....
Code: Pascal  [Select][+][-]
  1. procudure TFoo.bar();

According to me also the member style should be applied here, but if the style for the routine headers (called Procedure header name in the IDE settings window) is not specified. So, the style of the procedure header name first, then the member style.

Quote
But what about. Note that however the HL does not know if TFoo is a class or a unit.
Code: Pascal  [Select][+][-]
  1. type MyBarForward = TFooClass.TBar // TBar is "public type"

This should also depend on the priority. As for me, this is where the datatype style should be applied by default.

Lazarus 3.2 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an acrade, action/adventure game in retro style (pixelart), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9910
  • Debugger - SynEdit - and more
    • wiki
Re: Extending the Pascal highlighter with new elements
« Reply #4 on: March 13, 2023, 03:25:22 pm »
Quote
Well the "structure members" might be an easy one. That is, if they can be detected by the following rule.
- Inside a code block. Though that depends on what is wanted
- any identifier that follows after a dot.
- no other rules

Exactly. But this requires checking, because the members after the dot operator are given in many cases and each should be checked.
What checking? Other than was a dot in front.

It doesn't check if its valid. (that be nice, but a diff topic).

All the HL would do is, any identifier after a dot is a member. ( ".." to be excluded)

While I am typing further on below, this already misses an important issue
Code: Pascal  [Select][+][-]
  1.   caption := '';
would not be detected. There is no dot.


Quote
Quote
But what about. Note that however the HL does not know if TFoo is a class or a unit.
Code: Pascal  [Select][+][-]
  1. type MyBarForward = TFooClass.TBar // TBar is "public type"

This should also depend on the priority. As for me, this is where the datatype style should be applied by default.
Only there is on "type style" there is a default style, but general code in the procedure body uses the exact same default style.

If that default style is prioritized over members, then that is everywhere.
That would require a "declaration style"... But I don't think that will happen.


To be honest just downlighting all members (as in identifier after a dot) the same is meaningless to me. But yes, it could be to others.

It gets interesting, if those kind of colors are retrieved from codetools, and there are differences for local vars, members, globals, ... Well even if only members, but including those without a dot in front of them.
However that is a long time away.
My todo list is simply full.

And then while in TMyClass in the term self.OtherClass.OtherMember only OtherClass would be a member of the current class.

Zvoni

  • Hero Member
  • *****
  • Posts: 2330
Re: Extending the Pascal highlighter with new elements
« Reply #5 on: March 13, 2023, 04:10:14 pm »
Let's add some spice
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. Uses SysUtils, Classes;
  4.  
  5. Type
  6.   TFoo = Record
  7.     SomeInt : Integer;
  8.   end;
  9.  
  10. //Start of "Bar"
  11. Procedure Bar;
  12. Type
  13.   TFoo = Record
  14.     SomeString:String;
  15.   end;
  16. Var
  17.   Foo:TFoo;
  18. Begin
  19.   Foo.SomeString:='SomeString';
  20. End;
  21. //End of "Bar"
  22.  
  23. begin
  24. end.
  25.  

How should the HL react to "TFoo"?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

 

TinyPortal © 2005-2018