mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2024-12-24 12:34:39 +03:00
Fixed: no highlighting of keyword <let>
Fixed: no highlighting of strings quoted with apostrophe <`> Fixed: incorrect highlighting of multi-line comments /* ... */ Fixed: incorrect parentheses if there is an empty string between parentheses chars
This commit is contained in:
parent
409e8b1819
commit
0353dbb7b4
@ -197,11 +197,11 @@ bool CodeEditor::matchLeftParenthesis(QTextBlock currentBlock, QChar parenthesis
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
currentBlock = currentBlock.next();
|
currentBlock = currentBlock.next();
|
||||||
if (currentBlock.isValid())
|
if (currentBlock.isValid())
|
||||||
return matchLeftParenthesis(currentBlock, parenthesisType, 0, numLeftParentheses);
|
return matchLeftParenthesis(currentBlock, parenthesisType, 0, numLeftParentheses);
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -227,12 +227,12 @@ bool CodeEditor::matchRightParenthesis(QTextBlock currentBlock, QChar parenthesi
|
|||||||
--numRightParentheses;
|
--numRightParentheses;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
currentBlock = currentBlock.previous();
|
currentBlock = currentBlock.previous();
|
||||||
if (currentBlock.isValid())
|
if (currentBlock.isValid())
|
||||||
return matchRightParenthesis(currentBlock, parenthesisType, -2, numRightParentheses);
|
return matchRightParenthesis(currentBlock, parenthesisType, -2, numRightParentheses);
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
namespace LimeReport{
|
namespace LimeReport{
|
||||||
|
|
||||||
#define KEYWORDS_COUNT 59
|
#define KEYWORDS_COUNT 60
|
||||||
|
|
||||||
static const char *const keywords[KEYWORDS_COUNT] = {
|
static const char *const keywords[KEYWORDS_COUNT] = {
|
||||||
"do","if","in","for","int","new","try","var","byte","case","char","else","enum",
|
"do","if","in","for","int","new","try","var","byte","case","char","else","enum",
|
||||||
@ -14,12 +14,41 @@ static const char *const keywords[KEYWORDS_COUNT] = {
|
|||||||
"import","native","public","return","static","switch","throws","typeof","boolean",
|
"import","native","public","return","static","switch","throws","typeof","boolean",
|
||||||
"default","extends","finally","package","private","abstract","continue","debugger",
|
"default","extends","finally","package","private","abstract","continue","debugger",
|
||||||
"function","volatile","interface","protected","transient","implements","instanceof",
|
"function","volatile","interface","protected","transient","implements","instanceof",
|
||||||
"synchronized"
|
"synchronized","let"
|
||||||
};
|
};
|
||||||
|
|
||||||
enum LiteralsType{SpaceFound, AlpahabetFound, NumberFound, HashFound, SlashFound, AsterixFound,
|
enum LiteralsType {
|
||||||
BracketFound, QuotationFound, ApostropheFound, SeparatorFound, BackSlashFound, LiteralsCount};
|
SpaceFound,
|
||||||
enum States {Start, MayBeKeyWord, Code, MayBeComment, Comment, Comment2, MayBeComment2End, String, String2, MayBeNumber, Separator, StatesCount};
|
AlpahabetFound,
|
||||||
|
NumberFound,
|
||||||
|
HashFound,
|
||||||
|
SlashFound,
|
||||||
|
AsterixFound,
|
||||||
|
BracketFound,
|
||||||
|
QuotationFound,
|
||||||
|
ApostropheFound,
|
||||||
|
Apostrophe2Found,
|
||||||
|
SeparatorFound,
|
||||||
|
BackSlashFound,
|
||||||
|
LiteralsCount
|
||||||
|
};
|
||||||
|
|
||||||
|
enum States {
|
||||||
|
Undefinded = -1,
|
||||||
|
Start,
|
||||||
|
MayBeKeyWord,
|
||||||
|
Code,
|
||||||
|
MayBeComment,
|
||||||
|
Comment,
|
||||||
|
Comment2,
|
||||||
|
MayBeComment2End,
|
||||||
|
String,
|
||||||
|
String2,
|
||||||
|
String3,
|
||||||
|
MayBeNumber,
|
||||||
|
Separator,
|
||||||
|
StatesCount
|
||||||
|
};
|
||||||
|
|
||||||
void ScriptHighlighter::createParentheisisInfo(const char& literal, TextBlockData *data, const QString& text)
|
void ScriptHighlighter::createParentheisisInfo(const char& literal, TextBlockData *data, const QString& text)
|
||||||
{
|
{
|
||||||
@ -37,25 +66,36 @@ void ScriptHighlighter::highlightBlock(const QString& text)
|
|||||||
{
|
{
|
||||||
int literal = -1;
|
int literal = -1;
|
||||||
bool lastWasBackSlash = false;
|
bool lastWasBackSlash = false;
|
||||||
int state = previousBlockState() != -1 ? previousBlockState() : Start ;
|
States prevState = (States)previousBlockState();
|
||||||
int oldState = -1;
|
States state = prevState != Undefinded ? (States)prevState : Start;
|
||||||
int stateMaschine[StatesCount][LiteralsCount] = {
|
States oldState = Undefinded;
|
||||||
{Separator, MayBeKeyWord, MayBeNumber, Separator, MayBeComment, Separator, Separator, String, String2, Separator, Separator},
|
const States stateMaschine[StatesCount][LiteralsCount] = {
|
||||||
{Separator, MayBeKeyWord, Code, Separator, MayBeComment, Separator, Separator, String, String2, Separator, Separator},
|
// Space Alpahabet Number Hash Slash Asterix, Bracket, Quotation, Apostrophe, Apostrophe2 Separator, Back Slash
|
||||||
{Separator, Code, Code, Separator, Separator, Separator, Separator, String, String2, Separator, Separator},
|
{Separator, MayBeKeyWord, MayBeNumber, Separator, MayBeComment, Separator, Separator, String, String2, String3, Separator, Separator},
|
||||||
{Separator, Code, MayBeNumber, Code, Comment, Comment2, Code, String, String2, Separator, Code},
|
{Separator, MayBeKeyWord, Code, Separator, MayBeComment, Separator, Separator, String, String2, String3, Separator, Separator},
|
||||||
{Comment, Comment, Comment, Comment, Comment, Comment, Comment, Comment, Comment, Comment, Comment},
|
{Separator, Code, Code, Separator, Separator, Separator, Separator, String, String2, String3, Separator, Separator},
|
||||||
{Comment2, Comment2, Comment2, Comment2, Comment2, MayBeComment2End, Comment2, Comment2, Comment2, Comment2, Comment2},
|
{Separator, Code, MayBeNumber, Code, Comment, Comment2, Code, String, String2, String3, Separator, Code},
|
||||||
{Comment2, Comment2, Comment2, Comment2, Separator, Comment2, Comment2, Comment2, Comment2, Comment2, Comment2},
|
{Comment, Comment, Comment, Comment, Comment, Comment, Comment, Comment, Comment, Comment, Comment, Comment},
|
||||||
{String, String, String, String, String, String, String, Separator, String, String, String},
|
{Comment2, Comment2, Comment2, Comment2, Comment2, MayBeComment2End, Comment2, Comment2, Comment2, Comment2, Comment2, Comment2},
|
||||||
{String2, String2, String2, String2, String2, String2, String2, String2, Separator, String2, String2},
|
{Comment2, Comment2, Comment2, Comment2, Separator, Comment2, Comment2, Comment2, Comment2, Comment2, Comment2, Comment2},
|
||||||
{Separator, Code, MayBeNumber, Separator, MayBeComment, Separator, Separator, String, String2, Separator, Code},
|
{String, String, String, String, String, String, String, Separator, String, String, String, String},
|
||||||
{Separator, MayBeKeyWord, MayBeNumber, Separator, MayBeComment, Separator, Separator, String, String2, Separator, Separator }
|
{String2, String2, String2, String2, String2, String2, String2, String2, Separator, String2, String2, String2},
|
||||||
|
{String3, String3, String3, String3, String3, String3, String3, String3, String3, Separator, String3, String3},
|
||||||
|
{Separator, Code, MayBeNumber, Separator, MayBeComment, Separator, Separator, String, String2, String3, Separator, Code},
|
||||||
|
{Separator, MayBeKeyWord, MayBeNumber, Separator, MayBeComment, Separator, Separator, String, String2, String3, Separator, Separator},
|
||||||
};
|
};
|
||||||
|
|
||||||
QString buffer;
|
QString buffer;
|
||||||
|
|
||||||
if (text.isEmpty()) return;
|
setCurrentBlockState(Undefinded);
|
||||||
|
|
||||||
|
if (text.isEmpty())
|
||||||
|
{
|
||||||
|
if (prevState == Comment2)
|
||||||
|
setCurrentBlockState(Comment2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (;;){
|
for (;;){
|
||||||
QChar currentChar = text.at(i);
|
QChar currentChar = text.at(i);
|
||||||
@ -81,6 +121,9 @@ void ScriptHighlighter::highlightBlock(const QString& text)
|
|||||||
case '"':
|
case '"':
|
||||||
literal = QuotationFound;
|
literal = QuotationFound;
|
||||||
break;
|
break;
|
||||||
|
case '`':
|
||||||
|
literal = Apostrophe2Found;
|
||||||
|
break;
|
||||||
case '{': case '[': case '(':
|
case '{': case '[': case '(':
|
||||||
case '}': case ']': case ')':
|
case '}': case ']': case ')':
|
||||||
literal = BracketFound;
|
literal = BracketFound;
|
||||||
@ -114,6 +157,7 @@ void ScriptHighlighter::highlightBlock(const QString& text)
|
|||||||
break;
|
break;
|
||||||
case String:
|
case String:
|
||||||
case String2:
|
case String2:
|
||||||
|
case String3:
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
buffer += currentChar;
|
buffer += currentChar;
|
||||||
break;
|
break;
|
||||||
@ -128,7 +172,7 @@ void ScriptHighlighter::highlightBlock(const QString& text)
|
|||||||
switch(oldState){
|
switch(oldState){
|
||||||
case MayBeComment2End:
|
case MayBeComment2End:
|
||||||
setFormat(i-(buffer.length()-1), buffer.length(), m_formats[CommentFormat]);
|
setFormat(i-(buffer.length()-1), buffer.length(), m_formats[CommentFormat]);
|
||||||
setCurrentBlockState(-1);
|
setCurrentBlockState(Undefinded);
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
break;
|
break;
|
||||||
case MayBeKeyWord:
|
case MayBeKeyWord:
|
||||||
@ -142,6 +186,7 @@ void ScriptHighlighter::highlightBlock(const QString& text)
|
|||||||
buffer.clear();
|
buffer.clear();
|
||||||
case String:
|
case String:
|
||||||
case String2:
|
case String2:
|
||||||
|
case String3:
|
||||||
setFormat(i-(buffer.length()-1), buffer.length(), m_formats[StringFormat]);
|
setFormat(i-(buffer.length()-1), buffer.length(), m_formats[StringFormat]);
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
break;
|
break;
|
||||||
@ -150,12 +195,16 @@ void ScriptHighlighter::highlightBlock(const QString& text)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (state == Comment2)
|
||||||
|
{
|
||||||
|
setCurrentBlockState(Comment2);
|
||||||
|
}
|
||||||
|
|
||||||
if ( state == Comment || state == Comment2 ){
|
if ( state == Comment || state == Comment2 ){
|
||||||
setFormat(i-(buffer.length()-1), buffer.length(), m_formats[CommentFormat]);
|
setFormat(i-(buffer.length()-1), buffer.length(), m_formats[CommentFormat]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( state == String || state == String2 ){
|
if ( state == String || state == String2 || state == String3 ){
|
||||||
setFormat(i-(buffer.length()-1), buffer.length(), m_formats[StringFormat]);
|
setFormat(i-(buffer.length()-1), buffer.length(), m_formats[StringFormat]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,6 +212,15 @@ void ScriptHighlighter::highlightBlock(const QString& text)
|
|||||||
if ( i>= text.length()) break;
|
if ( i>= text.length()) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (buffer.length())
|
||||||
|
{
|
||||||
|
if (oldState == MayBeKeyWord)
|
||||||
|
{
|
||||||
|
if (isKeyWord(buffer))
|
||||||
|
setFormat(i - buffer.length(), buffer.length(), m_formats[KeywordFormat]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TextBlockData *data = new TextBlockData;
|
TextBlockData *data = new TextBlockData;
|
||||||
|
|
||||||
for (int i = 0; i < PARENHEIS_COUNT; ++i){
|
for (int i = 0; i < PARENHEIS_COUNT; ++i){
|
||||||
|
Loading…
Reference in New Issue
Block a user