Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-10

SynEdit: TSynPasSyn and keywords

13 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Alexander Klenin

I noticed that FreePascal highlighter does not overload IsKeyword function. Thinking that it should be trivial to implement, I have taken a look at SynHighlighterPas unit.
I found some code worthy of TheDailyWTF.com ;-)
TSynPasSyn class have more than a hundred functions names Fun15 to Func191, each recognizing one or two keywords, called via a sort of hash table. So my question is -- how do I reuse them to create IsKeyword function? Or is it better to just create a separate keyword list, similar to e.g. SynHighlighterPython?

Alexander S. Klenin Insight Experts Ltd.

Reply by email

Alexander Klenin
to Mattias Gärtner
Mattias G?rtner wrote 7 lines
> So my question is -- how do I reuse them to create IsKeyword function? > Or is it better to just create a separate keyword list, similar to > e.g. SynHighlighterPython? Some words like 'end' depends on the context, if they are a keyword or an identifier. Please define IsKeyword.

Hm. This does not answer my question, so I suppose I have to decide myself ;-) Here is simplified patch, which ignores context-sensitive modifiers for now. Reserved word lists taken from FPC Reference Guide.

Alexander S. Klenin Insight Experts Ltd. -------------- next part -------------- A non-text attachment was scrubbed... Name: synpas_is_keyword.patch Type: application/octet-stream Size: 3407 bytes Desc: not available Url : http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20081009/69566b6d/attachment.obj

Reply by email

Mattias Gärtner
to Alexander Klenin

Zitat von Alexander Klenin :

Show quoted text 13 lines
On Wed, Oct 8, 2008 at 22:06, Mattias G??rtner wrote: >> So my question is -- how do I reuse them to create IsKeyword function? >> Or is it better to just create a separate keyword list, similar to >> e.g. SynHighlighterPython? > Some words like 'end' depends on the context, if they are a keyword or an > identifier. > Please define IsKeyword. Hm. This does not answer my question, so I suppose I have to decide myself ;-)

This was the answer to your question. ;)

Here is simplified patch, which ignores context-sensitive modifiers for now. Reserved word lists taken from FPC Reference Guide.

Thanks. I added it with a small comment.

Mattias

Reply by email

Alexander Klenin
to Mattias Gärtner
Mattias G?rtner wrote
Thanks. I added it with a small comment.

Ok, but I do not quite understand the part of comment about 'end' keyword -- where can it be used as non-reserved? Also, the list was taken straight from the FPR Reference guide, so if it is incorrect, then the guide should be fixed too. Regarding the non-reserved keywords (called 'modifiers' in the Reference) I think it would be better to explicitly say the are not included, instead of only offering one example ('static').
BTW, 'static' seems to be unknown to FPC 2.2.2 is it new in 2.3 series?

Alexander S. Klenin Insight Experts Ltd.

Reply by email

Mattias Gärtner
to Alexander Klenin

Zitat von Alexander Klenin :

Show quoted text 6 lines
On Thu, Oct 9, 2008 at 03:50, Mattias G??rtner wrote: > Thanks. I added it with a small comment. Ok, but I do not quite understand the part of comment about 'end' keyword -- where can it be used as non-reserved?

As label in asm.

Also, the list was taken straight from the FPR Reference guide, so if it is incorrect, then the guide should be fixed too.

The list correct, that each listed word can be a keyword. And yes, it is incorrect to not list the exceptions.

Regarding the non-reserved keywords (called 'modifiers' in the Reference) I think it would be better to explicitly say the are not included, instead of only offering one example ('static'). BTW, 'static' seems to be unknown to FPC 2.2.2 is it new in 2.3 series?

It's only available with the -St switch.

Mattias

Reply by email

Martin Friebe
to Alexander Klenin: I noticed that FreePascal highlighter does not overload IsKeyword function. Thinking that…
Alexander Klenin wrote
I noticed that FreePascal highlighter does not overload IsKeyword function. Thinking that it should be trivial to implement, I have taken a look at SynHighlighterPas unit.

Maybe off topic, but out of curiosity.
What is the benefit you hope to get from adding it? It *seems* that highlighting works fine (conclusion Highlighting is not using this for pascal?) Or have I missed something.

Thnaks
Martin

Reply by email

Mattias Gaertner
to Martin Friebe
Show quoted text 9 lines
Alexander Klenin wrote: > I noticed that FreePascal highlighter does not overload IsKeyword > function. Thinking that it should be trivial to implement, I have > taken a look at SynHighlighterPas unit. > Maybe off topic, but out of curiosity. What is the benefit you hope to get from adding it? It *seems* that highlighting works fine (conclusion Highlighting is not using this for pascal?) Or have I missed something.

It can be useful for simple tools, that should work with arbitrary synedit highlighters.
For all other cases I recommend the keyword lists in the codetools. For Delphi code jcf can be used too.

Mattias

Reply by email

Alexander Klenin
to Martin Friebe: Maybe off topic, but out of curiosity. What is the benefit you hope to get from adding…
Martin Friebe wrote 5 lines
Alexander Klenin wrote: Maybe off topic, but out of curiosity. What is the benefit you hope to get from adding it? It *seems* that highlighting works fine (conclusion Highlighting is not using this for pascal?) Or have I missed something.

Good question, actually ;-)
Attached is the patch which served as a motivation. It disables linkification of keywords (and numbers) in Lazarus, since it was useless and distracting.

Alexander S. Klenin Insight Experts Ltd. -------------- next part -------------- A non-text attachment was scrubbed... Name: synedit_dont_link_keywords.patch Type: application/octet-stream Size: 2096 bytes Desc: not available Url : http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20081010/6d9de496/attachment.obj

Reply by email

Alexander Klenin
to Mattias Gärtner
Mattias G?rtner wrote 7 lines
Ah, then I understood correct in the first place. Keywords are context sensitive and so are the highlighters. A link does not work on keywords, symbols, ..., but only on identifiers. You can get this with Synedit1.GetHighlighterAttriAtRowCol. And in Lazarus it is currently only implemented for filenames and identifiers in pascal.

Ok, so my second patch could be improved and the first one disregearded ;-). The only question is how to extract the right token kind from value returned by GetHighlighterAttriAtRowCol without breaking encapsulation? It is returned as a simple integer, and I see no correct way to compare it to tkIdentifier from Pascal highlighter.

Alexander S. Klenin Insight Experts Ltd.

Reply by email

Mattias Gaertner
to Alexander Klenin
Show quoted text 17 lines
On Fri, Oct 10, 2008 at 20:00, Mattias G?rtner wrote: > Ah, then I understood correct in the first place. > Keywords are context sensitive and so are the highlighters. > A link does not work on keywords, symbols, ..., but only on > identifiers. You can get this with > Synedit1.GetHighlighterAttriAtRowCol. > > And in Lazarus it is currently only implemented for filenames and > identifiers in pascal. Ok, so my second patch could be improved and the first one disregearded ;-). The only question is how to extract the right token kind from value returned by GetHighlighterAttriAtRowCol without breaking encapsulation? It is returned as a simple integer, and I see no correct way to compare it to tkIdentifier from Pascal highlighter.

I'm not yet sure, what you want to achieve. Do you need a general solution for your application, which uses synedit, or a special solution for the IDE?

Mattias

Reply by email

Alexander Klenin
to Mattias Gaertner
Mattias Gaertner wrote
I'm not yet sure, what you want to achieve. Do you need a general solution for your application, which uses synedit, or a special solution for the IDE?

A special one of the IDE. I just usually try not to write too specific solutions --
e.g. I consider bad style "magic" comparison like
if TokenKind == 4 then token_is_linkable

So my last question was -- how to achieve that in a good style?

Alexander S. Klenin Insight Experts Ltd.

Reply by email