- [FIX] Reajustats els delimitadors dels escalars

- [FIX] Ara es mentenen millor els espais entre comentaris
This commit is contained in:
2025-11-26 10:02:09 +01:00
parent acdfc6d27c
commit 2b41885f19

View File

@@ -102,10 +102,14 @@ public:
// Comment accessors
const std::string& getComment() const { return pre_comment; }
yamal& setComment(const std::string& c) { pre_comment = c; blank_line = true; return *this; }
yamal& setComment(const std::string& c) { pre_comment = c; /*blank_line = true;*/ return *this; }
yamal& appendComment(const std::string& c) {
if (!pre_comment.empty()) pre_comment += "\n";
pre_comment += c;
if (c.empty()) {
pre_comment += "\n";
} else {
if (!pre_comment.empty()) pre_comment += "\n";
pre_comment += c;
}
return *this;
}
@@ -163,7 +167,7 @@ public:
case MAP: {
if (inline_map) {
if (emit_self_comment && blank_line) { out << "\n"; }
//if (emit_self_comment && blank_line) { out << "\n"; }
if (emit_self_comment && !pre_comment.empty()) {
out << formatComment(pre_comment, indent);
}
@@ -177,14 +181,14 @@ public:
out << " }";
if (!inline_comment.empty()) out << " # " << inline_comment;
} else {
if (emit_self_comment && blank_line) { out << "\n"; }
//if (emit_self_comment && blank_line) { out << "\n"; }
// Only emit this nodes own comment at the start if requested
if (emit_self_comment && !pre_comment.empty()) {
out << formatComment(pre_comment, indent);
}
for (auto& kv : map_data.items()) {
// Emit childs pre-comment BEFORE the key line
if (kv.second.blank_line) { out << "\n"; }
//if (kv.second.blank_line) { out << "\n"; }
if (!kv.second.pre_comment.empty()) {
out << formatComment(kv.second.pre_comment, indent);
}
@@ -205,7 +209,7 @@ public:
case VECTOR: {
if (inline_map) {
if (emit_self_comment && blank_line) { out << "\n"; }
//if (emit_self_comment && blank_line) { out << "\n"; }
if (emit_self_comment && !pre_comment.empty()) {
out << formatComment(pre_comment, indent);
}
@@ -217,7 +221,7 @@ public:
out << " ]";
if (!inline_comment.empty()) out << " # " << inline_comment;
} else {
if (emit_self_comment && blank_line) { out << "\n"; }
//if (emit_self_comment && blank_line) { out << "\n"; }
if (emit_self_comment && !pre_comment.empty()) {
out << formatComment(pre_comment, indent);
}
@@ -227,7 +231,7 @@ public:
} else {
for (size_t i = 0; i < vec_data.size(); ++i) {
const yamal& item = vec_data[i];
if (emit_self_comment && item.blank_line) { out << "\n"; }
//if (emit_self_comment && item.blank_line) { out << "\n"; }
// Emit items comment BEFORE the dash line
if (!item.pre_comment.empty()) {
out << formatComment(item.pre_comment, indent);
@@ -273,7 +277,7 @@ public:
}
inline static std::string current_comment = "";
inline static bool current_blank_line = false;
//inline static bool current_blank_line = false;
void deserialize(int indent) {
if (tokenizer::error()) return;
@@ -282,15 +286,15 @@ public:
while(tokenizer::type != tokenizer::types::ENDOFFILE) {
switch (tokenizer::type) {
case tokenizer::types::COMMENT:
if (!current_comment.empty()) current_comment += "\n";
current_comment += tokenizer::string;
//if (!current_comment.empty()) current_comment += "\n";
current_comment += tokenizer::string + "\n";
tokenizer::getNextToken();
// Ignore for now
break;
case tokenizer::types::BLANKLINE:
tokenizer::getNextToken();
if (tokenizer::type == tokenizer::types::BLANKLINE) {
current_blank_line = true;
current_comment += "\n"; //current_blank_line = true;
tokenizer::getNextToken();
}
break;
@@ -301,7 +305,7 @@ public:
if (tokenizer::indent != current_indent) { tokenizer::error("Wrong indent"); return; }
yamal& key = (*this)[tokenizer::string];
if (!current_comment.empty()) { key.setComment(current_comment); current_comment = ""; }
if (current_blank_line) { key.setBlankLine(true); current_blank_line = false; }
//if (current_blank_line) { key.setBlankLine(true); current_blank_line = false; }
key.deserialize(current_indent);
break;
}
@@ -317,7 +321,7 @@ public:
if (tokenizer::indent != current_indent) { tokenizer::error("Wrong indent"); return; }
yamal& vec = (*this).emplace_back();
if (!current_comment.empty()) { vec.setComment(current_comment); current_comment = ""; }
if (current_blank_line) { vec.setBlankLine(true); current_blank_line = false; }
//if (current_blank_line) { vec.setBlankLine(true); current_blank_line = false; }
vec.deserialize(current_indent);
break;
}
@@ -404,7 +408,8 @@ private:
char tmp[256]; int i=0;
next(); ignoreWhiteSpace();
while (*buffer!=10 && *buffer!=13 && *buffer!=0) tmp[i++]=next();
if (*buffer==13) next(); next(); tmp[i]=0; string = tmp;
//if (*buffer==13) next(); next();
tmp[i]=0; string = tmp;
}
static void getEverythingUntilQuote() {
char tmp[256]; int i=0; next();
@@ -413,7 +418,7 @@ private:
}
static types getWord() {
char tmp[256]; int i=0;
const char *delimiters = inlined ? " \t\r\n[]{}#," : " \t\r\n[]{}#";
const char *delimiters = inlined ? " \t\r\n[]{}," : " \t\r\n";
while (!strchr(delimiters,*buffer)) tmp[i++]=next();
if (tmp[i-1]==':') {
//printf("KEY at line %i col %i\n", line, indent);