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