- El deserialitzador ja soporta linies en blanc i comentaris
This commit is contained in:
54
yamal.hpp
54
yamal.hpp
@@ -272,6 +272,9 @@ public:
|
|||||||
deserialize(-1);
|
deserialize(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline static std::string current_comment = "";
|
||||||
|
inline static bool current_blank_line = false;
|
||||||
|
|
||||||
void deserialize(int indent) {
|
void deserialize(int indent) {
|
||||||
if (tokenizer::error()) return;
|
if (tokenizer::error()) return;
|
||||||
int current_indent = -2;
|
int current_indent = -2;
|
||||||
@@ -279,31 +282,45 @@ 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";
|
||||||
|
current_comment += tokenizer::string;
|
||||||
tokenizer::getNextToken();
|
tokenizer::getNextToken();
|
||||||
// Ignore for now
|
// Ignore for now
|
||||||
break;
|
break;
|
||||||
case tokenizer::types::BLANKLINE:
|
case tokenizer::types::BLANKLINE:
|
||||||
tokenizer::getNextToken();
|
tokenizer::getNextToken();
|
||||||
// Ignore for now
|
if (tokenizer::type == tokenizer::types::BLANKLINE) {
|
||||||
|
current_blank_line = true;
|
||||||
|
tokenizer::getNextToken();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case tokenizer::types::KEY:
|
case tokenizer::types::KEY: {
|
||||||
if (tokenizer::indent <= indent) return;
|
if (tokenizer::indent <= indent)
|
||||||
|
return;
|
||||||
if (current_indent<0) current_indent = tokenizer::indent;
|
if (current_indent<0) current_indent = tokenizer::indent;
|
||||||
if (tokenizer::indent != current_indent) { tokenizer::error("Wrong indent"); return; }
|
if (tokenizer::indent != current_indent) { tokenizer::error("Wrong indent"); return; }
|
||||||
(*this)[tokenizer::string].deserialize(current_indent);
|
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; }
|
||||||
|
key.deserialize(current_indent);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case tokenizer::types::STRINGSCALAR:
|
case tokenizer::types::STRINGSCALAR:
|
||||||
this->setQuoted(true);
|
this->setQuoted(true);
|
||||||
case tokenizer::types::SCALAR:
|
case tokenizer::types::SCALAR:
|
||||||
*(this) = tokenizer::string;
|
*(this) = tokenizer::string;
|
||||||
tokenizer::getNextToken();
|
tokenizer::getNextToken();
|
||||||
return;
|
return;
|
||||||
case tokenizer::types::VECTOR:
|
case tokenizer::types::VECTOR: {
|
||||||
if (tokenizer::indent <= indent) return;
|
if (tokenizer::indent <= indent) return;
|
||||||
if (current_indent<0) current_indent = tokenizer::indent;
|
if (current_indent<0) current_indent = tokenizer::indent;
|
||||||
if (tokenizer::indent != current_indent) { tokenizer::error("Wrong indent"); return; }
|
if (tokenizer::indent != current_indent) { tokenizer::error("Wrong indent"); return; }
|
||||||
(*this).emplace_back().deserialize(current_indent);
|
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; }
|
||||||
|
vec.deserialize(current_indent);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case tokenizer::types::INLINEVEC: {
|
case tokenizer::types::INLINEVEC: {
|
||||||
(*this).setInline(true);
|
(*this).setInline(true);
|
||||||
(*this).clearToVector();
|
(*this).clearToVector();
|
||||||
@@ -385,6 +402,7 @@ private:
|
|||||||
static void ignoreWhiteSpace() { while (*buffer==32 || *buffer==9) next(); }
|
static void ignoreWhiteSpace() { while (*buffer==32 || *buffer==9) next(); }
|
||||||
static void getEverythingUntilEOL() {
|
static void getEverythingUntilEOL() {
|
||||||
char tmp[256]; int i=0;
|
char tmp[256]; int i=0;
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
@@ -398,11 +416,11 @@ private:
|
|||||||
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);
|
||||||
tmp[i-1]=0; string=tmp; return types::KEY;
|
tmp[i-1]=0; string=tmp; return types::KEY;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("SCALAR at line %i col %i\n", line, indent);
|
//printf("SCALAR at line %i col %i\n", line, indent);
|
||||||
tmp[i]=0; string = tmp;; return types::SCALAR;
|
tmp[i]=0; string = tmp;; return types::SCALAR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -412,32 +430,32 @@ private:
|
|||||||
indent = col;
|
indent = col;
|
||||||
switch (*buffer) {
|
switch (*buffer) {
|
||||||
case 0: {
|
case 0: {
|
||||||
printf("ENDOFFILE at line %i col %i\n", line, indent);
|
//printf("ENDOFFILE at line %i col %i\n", line, indent);
|
||||||
type = types::ENDOFFILE;
|
type = types::ENDOFFILE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case '#': {
|
case '#': {
|
||||||
printf("COMMENT at line %i col %i\n", line, indent);
|
//printf("COMMENT at line %i col %i\n", line, indent);
|
||||||
getEverythingUntilEOL();
|
getEverythingUntilEOL();
|
||||||
type = types::COMMENT;
|
type = types::COMMENT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case '"': {
|
case '"': {
|
||||||
printf("STRING SCALAR at line %i col %i\n", line, indent);
|
//printf("STRING SCALAR at line %i col %i\n", line, indent);
|
||||||
getEverythingUntilQuote();
|
getEverythingUntilQuote();
|
||||||
type = types::STRINGSCALAR;
|
type = types::STRINGSCALAR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case '\r':
|
case '\r':
|
||||||
case '\n': {
|
case '\n': {
|
||||||
printf("BLANKLINE at line %i col %i\n", line, indent);
|
//printf("BLANKLINE at line %i col %i\n", line, indent);
|
||||||
type = types::BLANKLINE;
|
type = types::BLANKLINE;
|
||||||
if (*buffer==13) next(); next();
|
if (*buffer==13) next(); next();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case '-': {
|
case '-': {
|
||||||
if (*(buffer+1)==' ') {
|
if (*(buffer+1)==' ') {
|
||||||
printf("VECTOR at line %i col %i\n", line, indent);
|
//printf("VECTOR at line %i col %i\n", line, indent);
|
||||||
type = types::VECTOR;
|
type = types::VECTOR;
|
||||||
next();
|
next();
|
||||||
} else {
|
} else {
|
||||||
@@ -446,31 +464,31 @@ private:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case '[': {
|
case '[': {
|
||||||
printf("INLINEVEC at line %i col %i\n", line, indent);
|
//printf("INLINEVEC at line %i col %i\n", line, indent);
|
||||||
type = types::INLINEVEC; inlined = true;
|
type = types::INLINEVEC; inlined = true;
|
||||||
next();
|
next();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ']': {
|
case ']': {
|
||||||
printf("INLINEVECOFF at line %i col %i\n", line, indent);
|
//printf("INLINEVECOFF at line %i col %i\n", line, indent);
|
||||||
type = types::INLINEVECOFF; inlined = false;
|
type = types::INLINEVECOFF; inlined = false;
|
||||||
next();
|
next();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case '{': {
|
case '{': {
|
||||||
printf("INLINEKEY at line %i col %i\n", line, indent);
|
//printf("INLINEKEY at line %i col %i\n", line, indent);
|
||||||
type = types::INLINEKEY; inlined = true;
|
type = types::INLINEKEY; inlined = true;
|
||||||
next();
|
next();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case '}': {
|
case '}': {
|
||||||
printf("INLINEKEYOFF at line %i col %i\n", line, indent);
|
//printf("INLINEKEYOFF at line %i col %i\n", line, indent);
|
||||||
type = types::INLINEKEYOFF; inlined = false;
|
type = types::INLINEKEYOFF; inlined = false;
|
||||||
next();
|
next();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ',': {
|
case ',': {
|
||||||
printf("COMMA at line %i col %i\n", line, indent);
|
//printf("COMMA at line %i col %i\n", line, indent);
|
||||||
type = types::COMMA;
|
type = types::COMMA;
|
||||||
next();
|
next();
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user