fix processor

This commit is contained in:
a-Sansara 2018-09-05 02:07:59 +02:00
parent c019ff1749
commit 83e6aa5729
9 changed files with 66 additions and 89 deletions

View File

@ -73,10 +73,10 @@
product: product:
- sku : BL394D - sku : BL394D
quantity : 4 quantity : 5
description : Basketball description : Basketball
price : 450.00 price : 450.00
- sku : BL394D - sku : BL394D
quantity : 4 quantity : 5
description : Basketball description : Basketball
price : 450.00 price : 450.00

View File

@ -1,20 +1,20 @@
{ {
"glossary": { "glossary": {
"title": "example glossary", "title": "example glossary",
"GlossDiv": { "GlossDiv": {
"title": "S", "title": "S",
"GlossList": { "GlossList": {
"GlossEntry": { "GlossEntry": {
"ID": "SGML", "ID": "SGML",
"SortAs": "SGML", "SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language", "GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML", "Acronym": "SGML",
"Abbrev": "ISO 8879:1986", "Abbrev": "ISO 8879:1986",
"GlossDef": { "GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.", "para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"] "GlossSeeAlso": ["GML", "XML"]
}, },
"GlossSee": "markup" "GlossSee": "markup"
} }
} }
} }

View File

@ -40,7 +40,7 @@ int main (string[] args)
var done = false; var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara"); of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
Pluie.Yaml.DEBUG = false; Pluie.Yaml.DEBUG = true;
var loader = new Yaml.Loader (path, true, true); var loader = new Yaml.Loader (path, true, true);
if ((done = loader.done)) { if ((done = loader.done)) {
var root = loader.get_nodes (); var root = loader.get_nodes ();

View File

@ -42,6 +42,7 @@ int main (string[] args)
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara"); of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
Pluie.Yaml.DEBUG = false; Pluie.Yaml.DEBUG = false;
Yaml.Loader.PACK_NESTED_ENTRIES = true;
var loader = new Yaml.Loader (path, true, true); var loader = new Yaml.Loader (path, true, true);
if ((done = loader.done)) { if ((done = loader.done)) {
var root = loader.get_nodes (); var root = loader.get_nodes ();

View File

@ -41,7 +41,7 @@ int main (string[] args)
var done = false; var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara"); of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
Pluie.Yaml.DEBUG = true; Pluie.Yaml.DEBUG = false;
Yaml.Object? obj = null; Yaml.Object? obj = null;
var config = new Yaml.Config (path, true); var config = new Yaml.Config (path, true);
var root = config.root_node (); var root = config.root_node ();

View File

@ -106,6 +106,7 @@ int main (string[] args)
Pluie.Yaml.DEBUG = false; Pluie.Yaml.DEBUG = false;
var config = new Yaml.Config (path, true); var config = new Yaml.Config (path, true);
var root = config.root_node (); var root = config.root_node ();
root.display_childs ();
root.first ().display_childs (); root.first ().display_childs ();
of.action ("Yaml.Builder.from_node", root.first ().name); of.action ("Yaml.Builder.from_node", root.first ().name);

View File

@ -343,7 +343,7 @@ public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
) )
: "", : "",
of.c (ECHO.OPTION).s ("]"), of.c (ECHO.OPTION).s ("]"),
withTag && this.ntype.is_root () ? (this as Yaml.Root).get_display_tag_directives () : "" withTag && this.ntype.is_root () && (this as Yaml.Root) !=null ? (this as Yaml.Root).get_display_tag_directives () : ""
); );
} }
} }

View File

@ -198,30 +198,36 @@ public class Pluie.Yaml.Processor
break; break;
} }
if (!this.begin) { if (!this.begin) {
if (this.event.evtype.is_document_start ()) { if (this.event.evtype.is_sequence_start () || this.event.evtype.is_mapping_start ()) {
this.begin = true;
continue;
}
else if (this.event.evtype.is_document_start ()) {
this.begin = true; this.begin = true;
// to do // to do
this.next_event (); this.event = this.next_event ();
if (this.event.evtype.is_tag ()) {
this.root.tag = new Yaml.Tag (this.event.data["suffix"], this.event.data["handle"].replace("!", ""));
this.event = this.next_event ();
}
continue; continue;
} }
} }
else { else {
if (this.event.evtype.is_mapping_end () || this.event.evtype.is_sequence_end ()) { if (this.event.evtype.is_anchor ()) {
this.on_anchor ();
}
else if (this.event.evtype.is_alias ()) {
this.on_alias ();
}
else if (this.event.evtype.is_mapping_end () || this.event.evtype.is_sequence_end ()) {
this.on_block_end (); this.on_block_end ();
continue; continue;
} }
if (this.event.evtype.is_key () && (this.event = this.get_value_key_event ()) != null) { else if (this.event.evtype.is_key () && (this.event = this.get_value_key_event ()) != null) {
this.on_key (); this.on_key ();
} }
if (this.event.evtype.is_anchor ()) { else if (this.event.evtype.is_entry ()) {
this.event = this.next_event ();
this.on_anchor ();
}
if (this.event.evtype.is_alias ()) {
this.event = this.next_event ();
this.on_alias ();
}
else if (this.event.evtype.is_entry ()) {
this.on_entry (); this.on_entry ();
} }
else if (this.event.evtype.is_mapping_start ()) { else if (this.event.evtype.is_mapping_start ()) {
@ -275,7 +281,7 @@ public class Pluie.Yaml.Processor
Yaml.Event? evt = null; Yaml.Event? evt = null;
if (this.iterator.has_next () && this.iterator.next ()) { if (this.iterator.has_next () && this.iterator.next ()) {
evt = this.iterator.get (); evt = this.iterator.get ();
Yaml.dbg (" 1>>>>> [EVENT event [%d] %s <<<<< %s".printf (this.indexEvt++, evt.evtype.infos (), Log.METHOD)); Yaml.dbg (" >>>>> [EVENT event [%d] %s <<<<< %s".printf (this.indexEvt++, evt.evtype.infos (), Log.METHOD));
} }
return evt; return evt;
} }
@ -374,31 +380,13 @@ public class Pluie.Yaml.Processor
*/ */
private void on_block_end () private void on_block_end ()
{ {
Yaml.dbg (" ===== >> ON BLOCK END ===== "); if (this.prev_node.ntype.is_scalar () || (this.prev_node.ntype.is_single_pair () && this.prev_node.parent != null && this.prev_node.parent.ntype.is_mapping ())) {
Yaml.dbg (" - parent_node : %s (%s)".printf (this.parent_node.name, this.parent_node.ntype.infos ())); this.prev_node = this.prev_node.parent;
Yaml.dbg (" - prev_node : %s (%s - collection ? %s)".printf (this.prev_node.name, this.prev_node.ntype.infos (), this.prev_node.ntype.is_collection ().to_string ()));
bool suite = true;
if (this.prev_node.ntype.is_mapping () && this.prev_node.parent != null && this.prev_node.parent.ntype.is_sequence ()) {
if (!(this.prev_node.parent as Yaml.Sequence).close_block) {
(this.prev_node.parent as Yaml.Sequence).close_block = true;
Yaml.dbg (" SET FALSE SUITE");
//~ suite = false;
}
} }
if (suite) { this.parent_node = this.prev_node.parent != null && this.prev_node.parent != this.root
Yaml.dbg (" SUITE"); ? this.prev_node.parent
if (this.prev_node.ntype.is_scalar () || (this.prev_node.ntype.is_single_pair () && this.prev_node.parent != null && this.prev_node.parent.ntype.is_mapping ())) { : this.root;
this.prev_node = this.prev_node.parent; this.prev_node = this.parent_node;
}
this.parent_node = this.prev_node.parent != null && this.prev_node.parent != this.root
? this.prev_node.parent
: this.root;
this.prev_node = this.parent_node;
}
Yaml.dbg (" - parent_node : %s (%s)".printf (this.parent_node.name, this.parent_node.ntype.infos ()));
Yaml.dbg (" - prev_node : %s (%s - collection ? %s)".printf (this.prev_node.name, this.prev_node.ntype.infos (), this.prev_node.ntype.is_collection ().to_string ()));
Yaml.dbg (this.prev_node.to_string ());
Yaml.dbg (" ===== << ON BLOCK END ====================== ");
} }
/** /**
@ -450,34 +438,12 @@ public class Pluie.Yaml.Processor
} }
} }
/**
*
*/
private void on_value ()
{
var e = this.get_next_event();
if (e.evtype.is_scalar ()) {
this.event = this.next_event ();
this.on_tag (false);
this.node = new Yaml.Scalar (this.parent_node, this.event.data["data"]);
this.change = true;
}
else if (e.evtype.is_anchor ()) {
this.event = this.next_event ();
this.on_anchor ();
}
else if (e.evtype.is_alias ()) {
this.event = this.next_event ();
this.on_alias ();
}
}
/** /**
* *
*/ */
private void on_scalar (bool entry = false) private void on_scalar (bool entry = false)
{ {
if (this.ckey != null && this.parent_node.ntype.is_mapping ()) { if (this.ckey != null && this.parent_node.ntype.is_collection ()) {
this.node = new Yaml.Mapping.with_scalar (this.parent_node, this.ckey, this.event.data["data"]); this.node = new Yaml.Mapping.with_scalar (this.parent_node, this.ckey, this.event.data["data"]);
} }
else { else {
@ -491,7 +457,9 @@ public class Pluie.Yaml.Processor
*/ */
private void on_anchor () private void on_anchor ()
{ {
this.idAnchor = this.event.data["id"]; if (this.event.data != null) {
this.idAnchor = this.event.data["id"];
}
} }
/** /**
@ -499,12 +467,14 @@ public class Pluie.Yaml.Processor
*/ */
private void on_alias () private void on_alias ()
{ {
this.idAnchor = this.event.data["id"]; if (this.event.data != null) {
Yaml.Node? refnode = this.anchors.get(this.idAnchor); this.idAnchor = this.event.data["id"];
if (refnode != null) { Yaml.Node? refnode = this.anchors.get(this.idAnchor);
this.node = refnode.clone_node (this.ckey); if (refnode != null) {
this.parent_node.add (this.node); this.node = refnode.clone_node (this.ckey);
this.prev_node = this.node; this.parent_node.add (this.node);
this.prev_node = this.node;
}
} }
} }
@ -515,7 +485,6 @@ public class Pluie.Yaml.Processor
{ {
this.node = new Yaml.Sequence (this.parent_node, this.ckey); this.node = new Yaml.Sequence (this.parent_node, this.ckey);
this.change = true; this.change = true;
//~ this.beginFlowSeq = true;
} }
/** /**
@ -530,10 +499,8 @@ public class Pluie.Yaml.Processor
this.on_tag (true); this.on_tag (true);
if (this.event.evtype.is_scalar ()) { if (this.event.evtype.is_scalar ()) {
this.ckey = this.event.data["data"]; this.ckey = this.event.data["data"];
Yaml.dbg (" >> node name : %s".printf (this.ckey));
} }
var e = this.get_next_value_event(); var e = this.get_next_value_event();
//~ Yaml.dbg (e.evtype.infos ());
if (e!=null) { if (e!=null) {
if ( e.evtype.is_sequence_start ()) { if ( e.evtype.is_sequence_start ()) {
this.on_sequence_start (); this.on_sequence_start ();
@ -562,10 +529,8 @@ public class Pluie.Yaml.Processor
*/ */
private void add_anchor_if_needed () private void add_anchor_if_needed ()
{ {
if (this.idAnchor != null) { if (this.idAnchor != null && this.node != null) {
if (this.node != null) { this.anchors.set(this.idAnchor, this.node);
this.anchors.set(this.idAnchor, this.node);
}
this.idAnchor = null; this.idAnchor = null;
} }
} }
@ -579,6 +544,7 @@ public class Pluie.Yaml.Processor
Yaml.dbg (Log.METHOD); Yaml.dbg (Log.METHOD);
Yaml.dbg (this.node.name); Yaml.dbg (this.node.name);
Yaml.dbg (this.node.ntype.infos ()); Yaml.dbg (this.node.ntype.infos ());
Yaml.dbg ("anchor ? %s".printf (this.idAnchor));
} }
if (this.change) { if (this.change) {
if (this.node.parent.ntype.is_sequence ()) { if (this.node.parent.ntype.is_sequence ()) {
@ -612,6 +578,7 @@ public class Pluie.Yaml.Processor
this.isEntryMapping = false; this.isEntryMapping = false;
this.change = false; this.change = false;
this.isEntry = false; this.isEntry = false;
this.ckey = null;
} }
} }

View File

@ -327,6 +327,14 @@ namespace Pluie.Yaml
return this == EVT.DOCUMENT_START; return this == EVT.DOCUMENT_START;
} }
/**
* @return event is stream start event
*/
public bool is_stream_start ()
{
return this == EVT.STREAM_START;
}
} }
/** /**