summaryrefslogtreecommitdiff
path: root/src/highlighter.cc
diff options
context:
space:
mode:
authordon bright <hugh.m.bright@gmail.com>2013-03-28 02:49:48 (GMT)
committerdon bright <hugh.m.bright@gmail.com>2013-03-28 02:49:48 (GMT)
commitbeff2b1f4811b7f9d2b58bfc6a469a363bc9bfd0 (patch)
tree98292dde86d8e195fb3210768ba3fa3bf414c7d8 /src/highlighter.cc
parentd98518ef5acba1811581aed46652e4b9d95d48f4 (diff)
fix issue #324 crashes. add 'resize', {}. fix documentation
Diffstat (limited to 'src/highlighter.cc')
-rw-r--r--src/highlighter.cc30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/highlighter.cc b/src/highlighter.cc
index 77d1bb8..391e3a5 100644
--- a/src/highlighter.cc
+++ b/src/highlighter.cc
@@ -32,7 +32,7 @@
setFormat() is very slow. normally this doesnt matter because we
only highlight a block or two at once. But when OpenSCAD first starts,
- QT automatigically calls 'highlightBlock' on every single textblock in the file
+ QT automagically calls 'highlightBlock' on every single textblock in the file
even if it's not visible in the window. On a large file (50,000 lines) this
can take several seconds.
@@ -103,9 +103,7 @@
expected result: it should load in a reasonable amount of time
action: scroll to bottom, put '=' after last ;
expected result: there should be a highlight, and a report of syntax error
- action: comment out the highlighter code from mainwin.cc, recompile,
- run openscad again on the large file. put '=' after last ;
- expected result: there should be only a small difference in speed.
+ and it should be almost instantaneous.
8. action: open any file, and hold down 'f5' key to repeatedly reparse
expected result: no crashing!
@@ -116,6 +114,10 @@
10. action: type random string of [][][][]()()[][90,3904,00,000]
expected result: all should be highlighted correctly
+11. action: type a single slash (/) or slash-star-star (/x**, remove x)
+ into a blank document.
+ expected result: don't crash esp. on mac
+
*/
#include "highlighter.h"
@@ -134,7 +136,7 @@ Highlighter::Highlighter(QTextDocument *parent)
typeformats["keyword"].setForeground(QColor("Green"));
typeformats["keyword"].setToolTip("Keyword");
- tokentypes["transform"] << "scale" << "translate" << "rotate" << "multmatrix" << "color" << "projection" << "hull";
+ tokentypes["transform"] << "scale" << "translate" << "rotate" << "multmatrix" << "color" << "projection" << "hull" << "resize";
typeformats["transform"].setForeground(QColor("Indigo"));
tokentypes["csgop"] << "union" << "intersection" << "difference" << "render";
@@ -164,7 +166,7 @@ Highlighter::Highlighter(QTextDocument *parent)
tokentypes["bool"] << "true" << "false";
typeformats["bool"].setForeground(QColor("DarkRed"));
- // Put each tokens into single QHash, mapped to it's format
+ // Put each token into single QHash, mapped to it's format
QList<QString>::iterator ki;
QList<QString> toktypes = tokentypes.keys();
for ( ki=toktypes.begin(); ki!=toktypes.end(); ++ki ) {
@@ -249,12 +251,14 @@ void Highlighter::highlightBlock(const QString &text)
// << ", err:" << errorPos << "," << errorState
// << ", text:'" << text.toStdString() << "'\n";
- // Split the block into pieces and highlight each as appropriate
+ // Split the block into chunks (tokens), based on whitespace,
+ // and then highlight each token as appropriate
QString newtext = text;
QStringList splitHelpers;
QStringList::iterator sh, token;
- // splitHelpers - so "[a+b]" is treated as "[ a + b ]" and formatted
- splitHelpers << tokentypes["operator"] << "(" << ")" << "[" << "]" << "," << ":";
+ // splitHelpers - so "{[a+b]}" is treated as " { [ a + b ] } "
+ splitHelpers << tokentypes["operator"] << tokentypes["bracket"]
+ << tokentypes["curlies"] << ":" << ",";
for ( sh = splitHelpers.begin(); sh!=splitHelpers.end(); ++sh ) {
newtext = newtext.replace( *sh, " " + *sh + " ");
}
@@ -287,21 +291,21 @@ void Highlighter::highlightBlock(const QString &text)
state = QUOTE;
setFormat(n,1,quoteFormat);
} else if (text[n] == '/'){
- if (text[n+1] == '/'){
+ if ( n+1 < text.size() && text[n+1] == '/'){
setFormat(n,text.size(),commentFormat);
break;
- } else if (text[n+1] == '*'){
+ } else if ( n+1 < text.size() && text[n+1] == '*'){
setFormat(n++,2,commentFormat);
state = COMMENT;
}
}
} else if (state == QUOTE){
setFormat(n,1,quoteFormat);
- if (text[n] == '"' && text[n-1] != '\\')
+ if (text[n] == '"' && n-1 >=0 && text[n-1] != '\\')
state = NORMAL;
} else if (state == COMMENT){
setFormat(n,1,commentFormat);
- if (text[n] == '*' && text[n+1] == '/'){
+ if (text[n] == '*' && n+1 < text.size() && text[n+1] == '/'){
setFormat(++n,1,commentFormat);
state = NORMAL;
}
contact: Jan Huwald // Impressum