or
if IsKeyWord('usit') then Caption := Caption + 'X';
Morton: The algorithm is flawed, however much you change it.
And even if you get a version that works for the current list of pascal identifiers (either which is well possible, the ones you use, or the ones in the SynPasSyn), it will not work for other lists.
Take a scriptable HL, and it will always be possible to find a set of 2 keywords that allow for a 3rd none keyword to be detected.
Which also means I will stop testing them....
Also the speed of an actual highlighter is not just the matching of keywords...
Besides:
- the hash is pretty good as it is
- the hash could be improved (e.g storing the keywords on the hashtable, together with the function ref, and compare before calling the function)
- a trie (prefix tree) could be used
- ...
But all that is only a part of the time used.
Scanning is only needed to the last visible line, after that it could be done on idle.
Scanning a big pascal file create 1500 ranges and more. They are in a tree, and are searched for each line.
Searching a tree with 1500 entries is of course nothing...But doing so 100-thousand times (for 100,000 lines) or more, and it gets noticeable.
This is because of some words (like deprecated) are only highlighted in very specific context. So ranges contain a lot of information, and therefore there are plenty of different ranges.
Yet a highlighter could be subdivided:
1) general structure:
unit interface implementation procedure begin end ....
This needs to be scanned from the start of file, to the last visible line
2) all the other details
only needed for the visible part. Find the start of a suitable range, just before the first visible line. And scan only what is needed.
Cache a certain amount around the visible area, for faster scrolling
You can do a simplified version of the above spilt:
Keywords like and,or,not => they do not change the state of the range
So you can have:
- a hashtable without them for scanning the entire file
- a hashtable with them, when scanning a line for getting the tokens to display.