evstevemd wrote:Why?
You should check last time it was colorized and only colorize that part. Unless I don't understand your question something like:
Code: Select all
int lastStyled = GetEndStyled();
if(lastStyled < pos) //pos can be your current position
{
Colourise(lastStyled, pos);
Now that's one big step towards the solution... I was looking for that end position over and over. After reading your code snipped and trying around a little, I found
Code: Select all
uint64_t startpos=GUIFrame::m_EditorSTC->GetEndStyled();
uint64_t endpos=GUIFrame::m_EditorSTC->GetLineEndPosition(GUIFrame::m_EditorSTC->LineFromPosition(GUIFrame::m_EditorSTC->GetCurrentPos()));
this->highlightSTCsyntax(startpos,endpos);
to work out perfectly. To make absolutely sure that I get everything alright, I parse the few words in front of that sequence as well since a variable might have gotten "cut off".
Still, there are some flaws performance- wise but this is not related to wxWidgets at all. I found a workaround for that, more of that later.
My deep trouble was finding the end position of "style end" which I have been searching inside the event all day long. I thought that the event specifies the end of the position you need to restyle
Thank you very much!
ONEEYEMAN wrote:Hi,
Why do you use regular expressions?
Anyway, there is an example of using custom lexer in in Git HEAD of wxWidgets. You should check it and do something similar.
Thank you.
I have to explain the background, I think... There are lines like this in a siemens NC program:
Code: Select all
SUPA G0 G90 G40 G60 Z=($MA_POS_LIMIT_PLUS[AX3]-0.1)
SUPA is an NC command, followed by a couple of G-Codes. $MA_POS_LIMIT_PLUS is the software end, but this includes "POS" as an NC-command as well. In total, the siemens knows about ~1100 different nc commands each with its own command. After removing G- and M-Codes and stuff from the list, about 900 remain.
Every NC command has to have a space or line feed in front and might be trailed by "=" or "[]" or "()" or digits (like G54).
I came up with having
Code: Select all
std::string key=("\\b("+m_CommandHighlightVector[i]+")\\W");
which gives good results (no digits, but those left don't have digits), but is one hell of a performance eater.
In total, the CNC code is a programming language on its own, similar to BASIC, just with a few hundred keywords and thousands of different variables
I plan to parse things like
inside the NC program and display those variables (the above declares a "member variable" in your NC program), along with some other fancy stuff in the future. The ultimate goal is to include some kind of autocompletion for NC variables and parsing control structures... Maybe.
Think of some kind of "NC-Code IDE".
To sum things up: I need to parse a lot of stuff in the background which includes pulling the whole text from the STC at once, parsing for about up to a minute or so (I should do that multithreaded) and then (hopefully) recoloring keywords if the content did not change in the meantime.
The solution I got now is that I parse the basic G-Codes like "G0 G90", M-Codes and stuff with a fast parser and not highlighting the ~900 nc commands.
Doing some quick testing, I think this should work the same way using a std mutex on STC_modified- either style or modify.
I hope that someone having a similar problem can find this topic via google now- I've seen quite a few questions, sadly none of the suggested solutions did work.
I will have a closer look on the possibility of an external lexer.
The deeper I dive into wxWidgets, the more I love it...
Thank you all for your help!