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?
Mailing lists / lazarus / 2008-10
SynEdit: TSynPasSyn and keywords
13 messages · 4 people · –
- AAlexander Klenin 6
- MMattias Gärtner 4
- MMattias Gaertner 2
- MMartin Friebe 1
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
An embedded and charset-unspecified text was scrubbed... Name: not available
Url: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20081008/b8df6bc3/attachment.pl
Mattias G?rtner wrote 7 lines
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.
Zitat von Alexander Klenin :
Show quoted text 13 lines
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
Mattias G?rtner wroteThanks. 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?
Zitat von Alexander Klenin :
Show quoted text 6 lines
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
I noticed that FreePascal highlighter does not overload IsKeyword function. Thinking that…
Alexander Klenin wroteI 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
Show quoted text 9 lines
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
Maybe off topic, but out of curiosity. What is the benefit you hope to get from adding…
Martin Friebe wrote 5 lines
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.
An embedded and charset-unspecified text was scrubbed... Name: not available
Url: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20081010/ea4232e0/attachment.pl
Mattias G?rtner wrote 7 lines
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.
Show quoted text 17 lines
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
Mattias Gaertner wroteI'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?
