3
3
#include < QJsonArray>
4
4
#include < QJsonObject>
5
5
6
- DiffViewerTextBuilder::DiffViewerTextBuilder ()
6
+ DiffViewerTextBuilder::DiffViewerTextBuilder (int * diff_line )
7
7
{
8
8
global = Global::getInstance ();
9
+ this ->diff_line = diff_line;
9
10
}
10
11
11
12
QString DiffViewerTextBuilder::generateText (QJsonValue jsonVal, QJsonObject comments, bool isTopLevel= true )
@@ -35,7 +36,7 @@ QString DiffViewerTextBuilder::generateTextFromLexemsArray(QJsonArray lexems, QJ
35
36
pasteSpaces (lex[" column" ].toInt () - cur_column);
36
37
cur_line = getTrueLine (lex[" line" ].toInt ());
37
38
}
38
- pasteLexem (lex);
39
+ pasteAtom (lex);
39
40
if (lex[" type" ] == " string" ){
40
41
int newlines = lex[" string" ].toString ().count (' \n ' );
41
42
cur_line += newlines;
@@ -48,7 +49,7 @@ QString DiffViewerTextBuilder::generateTextFromLexemsArray(QJsonArray lexems, QJ
48
49
49
50
int DiffViewerTextBuilder::getTrueLine (int cur_line)
50
51
{
51
- return cur_line - diff_line;
52
+ return cur_line - * diff_line;
52
53
}
53
54
54
55
void DiffViewerTextBuilder::pasteTopLevel (const QJsonArray &array)
@@ -59,8 +60,8 @@ void DiffViewerTextBuilder::pasteTopLevel(const QJsonArray &array)
59
60
void DiffViewerTextBuilder::pasteNewLinesAndComments (int next_line){
60
61
QJsonObject comment;
61
62
while (cur_line < next_line){
62
- if (comments[QString::number (cur_line+diff_line)] != QJsonValue::Undefined) {
63
- comment = comments[QString::number (cur_line+diff_line)].toObject ();
63
+ if (comments[QString::number (cur_line+* diff_line)] != QJsonValue::Undefined) {
64
+ comment = comments[QString::number (cur_line+* diff_line)].toObject ();
64
65
int column_diff = comment[" column" ].toInt () - cur_column;
65
66
pasteSpaces (column_diff);
66
67
text.append (" <font style=\" color:#cccccc;\" >" );
@@ -74,41 +75,40 @@ void DiffViewerTextBuilder::pasteNewLinesAndComments(int next_line){
74
75
}
75
76
}
76
77
77
- void DiffViewerTextBuilder::pasteLexem (const QJsonObject &lex )
78
+ void DiffViewerTextBuilder::pasteAtom (const QJsonObject &atom )
78
79
{
79
- if (lex [" diff-st" ].toString () == " deleted" ){
80
+ if (atom [" diff-st" ].toString () == " deleted" ){
80
81
text.append (" <font style=\" background-color:#FF9CA1;\" >" );
81
- text.append (lex [" string" ].toString ());
82
+ text.append (atom [" string" ].toString ());
82
83
text.append (" </font>" );
83
- }else if (lex [" diff-st" ].toString () == " new" ){
84
+ }else if (atom [" diff-st" ].toString () == " new" ){
84
85
text.append (" <font style=\" background-color:#C9FFBF;\" >" );
85
- text.append (lex [" string" ].toString ());
86
+ text.append (atom [" string" ].toString ());
86
87
text.append (" </font>" );
87
- }else if (lex [" diff-st" ].toString () == " moved" ){
88
+ }else if (atom [" diff-st" ].toString () == " moved" ){
88
89
text.append (" <font style=\" background-color: #E5F0FF;\" >" );
89
- text.append (lex [" string" ].toString ());
90
+ text.append (atom [" string" ].toString ());
90
91
text.append (" </font>" );
91
- }else if (lex [" type" ].toString () == " errorLexem" ){
92
- if (lex [" id" ] == global->getSelectedErrorLexId ()){
92
+ }else if (atom [" type" ].toString () == " errorLexem" ){
93
+ if (atom [" id" ] == global->getSelectedErrorLexId ()){
93
94
text.append (" <font style=\" background-color:#ffffe6;\" >" );
94
95
}else {
95
96
text.append (" <font style=\" background-color:#FF9CA1;\" >" );
96
97
}
97
- text.append (lex [" string" ].toString ());
98
+ text.append (atom [" string" ].toString ());
98
99
text.append (" </font>" );
99
- }else {
100
- text.append (lex [" string" ].toString ());
100
+ } else {
101
+ text.append (atom [" string" ].toString ());
101
102
}
102
103
}
103
104
104
- void DiffViewerTextBuilder::pasteParent (QChar parent ){
105
+ void DiffViewerTextBuilder::pasteSymbol (QChar symbol ){
105
106
106
- text.append (parent );
107
+ text.append (symbol );
107
108
cur_column++;
108
109
}
109
110
110
-
111
- void DiffViewerTextBuilder::pasteSpacesBeforeParent (int line, int column)
111
+ void DiffViewerTextBuilder::pasteWhitespaces (int line, int column)
112
112
{
113
113
if (cur_line == line){
114
114
pasteSpaces (column - cur_column);
@@ -120,43 +120,50 @@ void DiffViewerTextBuilder::pasteSpacesBeforeParent(int line, int column)
120
120
}
121
121
}
122
122
123
- void DiffViewerTextBuilder::genLexem (const QJsonObject &lex)
123
+ void DiffViewerTextBuilder::genAtom (const QJsonObject &lex)
124
124
{
125
- QJsonArray lexem_pos = lex[" lexem-coord" ].toArray ();
126
- if (getTrueLine (lexem_pos [0 ].toInt ()) == cur_line){
127
- pasteSpaces (lexem_pos [1 ].toInt () - cur_column);
125
+ QJsonArray atom_pos = lex[" lexem-coord" ].toArray ();
126
+ if (getTrueLine (atom_pos [0 ].toInt ()) == cur_line){
127
+ pasteSpaces (atom_pos [1 ].toInt () - cur_column);
128
128
} else {
129
- pasteNewLinesAndComments (getTrueLine (lexem_pos [0 ].toInt ()));
130
- pasteSpaces (lexem_pos [1 ].toInt () - cur_column);
131
- cur_line = getTrueLine (lexem_pos [0 ].toInt ());
129
+ pasteNewLinesAndComments (getTrueLine (atom_pos [0 ].toInt ()));
130
+ pasteSpaces (atom_pos [1 ].toInt () - cur_column);
131
+ cur_line = getTrueLine (atom_pos [0 ].toInt ());
132
132
}
133
- pasteLexem (lex);
134
- cur_column = lexem_pos [1 ].toInt () + lex[" string" ].toString ().size ();
133
+ pasteAtom (lex);
134
+ cur_column = atom_pos [1 ].toInt () + lex[" string" ].toString ().size ();
135
135
}
136
136
137
137
void DiffViewerTextBuilder::genList (const QJsonObject &listObj, bool isFirstCall = false )
138
138
{
139
139
QJsonObject parent_info = listObj[" par-info" ].toObject ();
140
140
QJsonArray lparenCoord = parent_info[" lparenCoord" ].toArray ();
141
141
if (isFirstCall && !isTopLevel){
142
- diff_line = lparenCoord[0 ].toInt ();
142
+ * diff_line = lparenCoord[0 ].toInt ();
143
143
}
144
144
QJsonArray rparenCoord = parent_info[" rparenCoord" ].toArray ();
145
145
auto main_part = [&](){
146
- pasteParent (' (' );
146
+ pasteSymbol (' (' );
147
147
QJsonArray array = listObj[" elems" ].toArray ();
148
148
loopArray (array);
149
- pasteSpacesBeforeParent (getTrueLine (rparenCoord[0 ].toInt ()),rparenCoord[1 ].toInt ());
150
- pasteParent (' )' );
149
+ pasteWhitespaces (getTrueLine (rparenCoord[0 ].toInt ()),rparenCoord[1 ].toInt ());
150
+ pasteSymbol (' )' );
151
151
};
152
152
153
153
154
- pasteSpacesBeforeParent (getTrueLine (lparenCoord[0 ].toInt ()),lparenCoord[1 ].toInt ());
155
- if ((listObj[" diff-st" ].toString () == " deleted" ) ||
156
- listObj[" isIllegalNode" ].toBool ()){
154
+ pasteWhitespaces (getTrueLine (lparenCoord[0 ].toInt ()),lparenCoord[1 ].toInt ());
155
+ if (listObj[" diff-st" ].toString () == " deleted" ){
157
156
text.append (" <font style=\" background-color:#FF9CA1;\" >" );
158
157
main_part ();
159
158
text.append (" </font>" );
159
+ }else if (listObj[" isIllegalNode" ].toBool ()){
160
+ if (listObj[" id" ].toInt () == global->getSelectedErrorNodesId ()){
161
+ text.append (" <font style=\" background-color:#ffffe6;\" >" );
162
+ }else {
163
+ text.append (" <font style=\" background-color:#FF9CA1;\" >" );
164
+ }
165
+ main_part ();
166
+ text.append (" </font>" );
160
167
}else if (listObj[" diff-st" ].toString () == " new" ){
161
168
text.append (" <font style=\" background-color:#C9FFBF;\" >" );
162
169
main_part ();
@@ -175,14 +182,31 @@ void DiffViewerTextBuilder::genList(const QJsonObject &listObj, bool isFirstCall
175
182
}
176
183
}
177
184
185
+ void DiffViewerTextBuilder::genQuote (const QJsonObject "eSexpr)
186
+ {
187
+ QJsonArray quoteCoord = quoteSexpr[" quote-coord" ].toArray ();
188
+ pasteWhitespaces (getTrueLine (quoteCoord[0 ].toInt ()),quoteCoord[1 ].toInt ());
189
+ pasteSymbol (' \' ' );
190
+ QJsonObject nextSexpr = quoteSexpr[" q-s-expr" ].toObject ();
191
+ if (nextSexpr[" type" ].toString () == " list" ){
192
+ genList (nextSexpr);
193
+ } else if (nextSexpr[" type" ].toString () == " atom" ){
194
+ genAtom (nextSexpr);
195
+ } else if (nextSexpr[" type" ].toString () == " quote" ){
196
+ genQuote (nextSexpr);
197
+ }
198
+ }
199
+
178
200
void DiffViewerTextBuilder::loopArray (const QJsonArray &array)
179
201
{
180
202
for (int elem_index = 0 ; elem_index < array.size (); ++elem_index){
181
203
QJsonObject sexprObject = array[elem_index].toObject ();
182
204
if (sexprObject[" type" ].toString () == " list" ){
183
205
genList (sexprObject);
184
- } else if (sexprObject[" type" ].toString () == " lexem" ){
185
- genLexem (sexprObject);
206
+ } else if (sexprObject[" type" ].toString () == " atom" ){
207
+ genAtom (sexprObject);
208
+ } else if (sexprObject[" type" ].toString () == " quote" ){
209
+ genQuote (sexprObject);
186
210
}
187
211
}
188
212
}
@@ -191,7 +215,3 @@ void DiffViewerTextBuilder::pasteSpaces(int count)
191
215
{
192
216
text.append (QString (count, ' ' ));
193
217
}
194
-
195
-
196
-
197
-
0 commit comments