33#include < QJsonArray>
44#include < QJsonObject>
55
6- DiffViewerTextBuilder::DiffViewerTextBuilder ()
6+ DiffViewerTextBuilder::DiffViewerTextBuilder (int * diff_line )
77{
88 global = Global::getInstance ();
9+ this ->diff_line = diff_line;
910}
1011
1112QString DiffViewerTextBuilder::generateText (QJsonValue jsonVal, QJsonObject comments, bool isTopLevel= true )
@@ -35,7 +36,7 @@ QString DiffViewerTextBuilder::generateTextFromLexemsArray(QJsonArray lexems, QJ
3536 pasteSpaces (lex[" column" ].toInt () - cur_column);
3637 cur_line = getTrueLine (lex[" line" ].toInt ());
3738 }
38- pasteLexem (lex);
39+ pasteAtom (lex);
3940 if (lex[" type" ] == " string" ){
4041 int newlines = lex[" string" ].toString ().count (' \n ' );
4142 cur_line += newlines;
@@ -48,7 +49,7 @@ QString DiffViewerTextBuilder::generateTextFromLexemsArray(QJsonArray lexems, QJ
4849
4950int DiffViewerTextBuilder::getTrueLine (int cur_line)
5051{
51- return cur_line - diff_line;
52+ return cur_line - * diff_line;
5253}
5354
5455void DiffViewerTextBuilder::pasteTopLevel (const QJsonArray &array)
@@ -59,8 +60,8 @@ void DiffViewerTextBuilder::pasteTopLevel(const QJsonArray &array)
5960void DiffViewerTextBuilder::pasteNewLinesAndComments (int next_line){
6061 QJsonObject comment;
6162 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 ();
6465 int column_diff = comment[" column" ].toInt () - cur_column;
6566 pasteSpaces (column_diff);
6667 text.append (" <font style=\" color:#cccccc;\" >" );
@@ -74,41 +75,40 @@ void DiffViewerTextBuilder::pasteNewLinesAndComments(int next_line){
7475 }
7576}
7677
77- void DiffViewerTextBuilder::pasteLexem (const QJsonObject &lex )
78+ void DiffViewerTextBuilder::pasteAtom (const QJsonObject &atom )
7879{
79- if (lex [" diff-st" ].toString () == " deleted" ){
80+ if (atom [" diff-st" ].toString () == " deleted" ){
8081 text.append (" <font style=\" background-color:#FF9CA1;\" >" );
81- text.append (lex [" string" ].toString ());
82+ text.append (atom [" string" ].toString ());
8283 text.append (" </font>" );
83- }else if (lex [" diff-st" ].toString () == " new" ){
84+ }else if (atom [" diff-st" ].toString () == " new" ){
8485 text.append (" <font style=\" background-color:#C9FFBF;\" >" );
85- text.append (lex [" string" ].toString ());
86+ text.append (atom [" string" ].toString ());
8687 text.append (" </font>" );
87- }else if (lex [" diff-st" ].toString () == " moved" ){
88+ }else if (atom [" diff-st" ].toString () == " moved" ){
8889 text.append (" <font style=\" background-color: #E5F0FF;\" >" );
89- text.append (lex [" string" ].toString ());
90+ text.append (atom [" string" ].toString ());
9091 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 ()){
9394 text.append (" <font style=\" background-color:#ffffe6;\" >" );
9495 }else {
9596 text.append (" <font style=\" background-color:#FF9CA1;\" >" );
9697 }
97- text.append (lex [" string" ].toString ());
98+ text.append (atom [" string" ].toString ());
9899 text.append (" </font>" );
99- }else {
100- text.append (lex [" string" ].toString ());
100+ } else {
101+ text.append (atom [" string" ].toString ());
101102 }
102103}
103104
104- void DiffViewerTextBuilder::pasteParent (QChar parent ){
105+ void DiffViewerTextBuilder::pasteSymbol (QChar symbol ){
105106
106- text.append (parent );
107+ text.append (symbol );
107108 cur_column++;
108109}
109110
110-
111- void DiffViewerTextBuilder::pasteSpacesBeforeParent (int line, int column)
111+ void DiffViewerTextBuilder::pasteWhitespaces (int line, int column)
112112{
113113 if (cur_line == line){
114114 pasteSpaces (column - cur_column);
@@ -120,43 +120,50 @@ void DiffViewerTextBuilder::pasteSpacesBeforeParent(int line, int column)
120120 }
121121}
122122
123- void DiffViewerTextBuilder::genLexem (const QJsonObject &lex)
123+ void DiffViewerTextBuilder::genAtom (const QJsonObject &lex)
124124{
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);
128128 } 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 ());
132132 }
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 ();
135135}
136136
137137void DiffViewerTextBuilder::genList (const QJsonObject &listObj, bool isFirstCall = false )
138138{
139139 QJsonObject parent_info = listObj[" par-info" ].toObject ();
140140 QJsonArray lparenCoord = parent_info[" lparenCoord" ].toArray ();
141141 if (isFirstCall && !isTopLevel){
142- diff_line = lparenCoord[0 ].toInt ();
142+ * diff_line = lparenCoord[0 ].toInt ();
143143 }
144144 QJsonArray rparenCoord = parent_info[" rparenCoord" ].toArray ();
145145 auto main_part = [&](){
146- pasteParent (' (' );
146+ pasteSymbol (' (' );
147147 QJsonArray array = listObj[" elems" ].toArray ();
148148 loopArray (array);
149- pasteSpacesBeforeParent (getTrueLine (rparenCoord[0 ].toInt ()),rparenCoord[1 ].toInt ());
150- pasteParent (' )' );
149+ pasteWhitespaces (getTrueLine (rparenCoord[0 ].toInt ()),rparenCoord[1 ].toInt ());
150+ pasteSymbol (' )' );
151151 };
152152
153153
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" ){
157156 text.append (" <font style=\" background-color:#FF9CA1;\" >" );
158157 main_part ();
159158 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>" );
160167 }else if (listObj[" diff-st" ].toString () == " new" ){
161168 text.append (" <font style=\" background-color:#C9FFBF;\" >" );
162169 main_part ();
@@ -175,14 +182,31 @@ void DiffViewerTextBuilder::genList(const QJsonObject &listObj, bool isFirstCall
175182 }
176183}
177184
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+
178200void DiffViewerTextBuilder::loopArray (const QJsonArray &array)
179201{
180202 for (int elem_index = 0 ; elem_index < array.size (); ++elem_index){
181203 QJsonObject sexprObject = array[elem_index].toObject ();
182204 if (sexprObject[" type" ].toString () == " list" ){
183205 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);
186210 }
187211 }
188212}
@@ -191,7 +215,3 @@ void DiffViewerTextBuilder::pasteSpaces(int count)
191215{
192216 text.append (QString (count, ' ' ));
193217}
194-
195-
196-
197-
0 commit comments