add dumper + attempt debug next value entry on processor
This commit is contained in:
parent
37f5e43720
commit
a6d16dee96
2
build.sh
2
build.sh
|
@ -95,7 +95,7 @@ function build.sample()
|
||||||
local f="$(basename $1)"
|
local f="$(basename $1)"
|
||||||
local fx="${f:0:-5}"
|
local fx="${f:0:-5}"
|
||||||
local state="FAILED"
|
local state="FAILED"
|
||||||
local cmd="valac -v --pkg gee-0.8 --pkg pluie-echo-0.2 --pkg $lib $1 -o ./bin/$fx"
|
local cmd="valac -v --pkg gee-0.8 --pkg gio-2.0 --pkg pluie-echo-0.2 --pkg $lib $1 -o ./bin/$fx"
|
||||||
build.title "$f SAMPLE BUILD"
|
build.title "$f SAMPLE BUILD"
|
||||||
echo -e "\n$cmd"
|
echo -e "\n$cmd"
|
||||||
$cmd
|
$cmd
|
||||||
|
|
|
@ -68,6 +68,7 @@ sources = [
|
||||||
'src/vala/Pluie/Yaml.Builder.vala',
|
'src/vala/Pluie/Yaml.Builder.vala',
|
||||||
'src/vala/Pluie/Yaml.Collection.vala',
|
'src/vala/Pluie/Yaml.Collection.vala',
|
||||||
'src/vala/Pluie/Yaml.Config.vala',
|
'src/vala/Pluie/Yaml.Config.vala',
|
||||||
|
'src/vala/Pluie/Yaml.Dumper.vala',
|
||||||
'src/vala/Pluie/Yaml.Event.vala',
|
'src/vala/Pluie/Yaml.Event.vala',
|
||||||
'src/vala/Pluie/Yaml.Example.vala',
|
'src/vala/Pluie/Yaml.Example.vala',
|
||||||
'src/vala/Pluie/Yaml.ExampleChild.vala',
|
'src/vala/Pluie/Yaml.ExampleChild.vala',
|
||||||
|
|
|
@ -27,20 +27,43 @@
|
||||||
- 3.2
|
- 3.2
|
||||||
- 4.2
|
- 4.2
|
||||||
!v!Gee.ArrayList type_gee_alobject :
|
!v!Gee.ArrayList type_gee_alobject :
|
||||||
- toto : totovalue1
|
- !v!Pluie.Yaml.ExampleChild entry1:
|
||||||
|
toto : totovalue1
|
||||||
tata : tatavalue1
|
tata : tatavalue1
|
||||||
titi : 789
|
titi : 789
|
||||||
tutu : true
|
tutu : true
|
||||||
- toto : totovalue2
|
- !v!Pluie.Yaml.ExampleChild entry2:
|
||||||
|
toto : totovalue2
|
||||||
tata : tatavalue2
|
tata : tatavalue2
|
||||||
titi : 456
|
titi : 456
|
||||||
tutu : false
|
tutu : false
|
||||||
- toto : totovalue3
|
- !v!Pluie.Yaml.ExampleChild entry3:
|
||||||
|
toto : totovalue3
|
||||||
tata : tatavalue3
|
tata : tatavalue3
|
||||||
titi : 123
|
titi : 123
|
||||||
tutu : 1
|
tutu : 1
|
||||||
- toto : totovalue4
|
- !v!Pluie.Yaml.ExampleChild entry4:
|
||||||
|
toto : totovalue4
|
||||||
tata : tatavalue4
|
tata : tatavalue4
|
||||||
titi : 44
|
titi : 44
|
||||||
tutu : 0
|
tutu : 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#~ !v!Gee.ArrayList type_gee_alobject :
|
||||||
|
#~ - toto : totovalue1
|
||||||
|
#~ tata : tatavalue1
|
||||||
|
#~ titi : 789
|
||||||
|
#~ tutu : true
|
||||||
|
#~ - toto : totovalue2
|
||||||
|
#~ tata : tatavalue2
|
||||||
|
#~ titi : 456
|
||||||
|
#~ tutu : false
|
||||||
|
#~ - toto : totovalue3
|
||||||
|
#~ tata : tatavalue3
|
||||||
|
#~ titi : 123
|
||||||
|
#~ tutu : 1
|
||||||
|
#~ - toto : totovalue4
|
||||||
|
#~ tata : tatavalue4
|
||||||
|
#~ titi : 44
|
||||||
|
#~ tutu : 0
|
||||||
|
|
75
samples/yaml-dump.vala
Normal file
75
samples/yaml-dump.vala
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
*
|
||||||
|
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||||
|
* @version : 0.5
|
||||||
|
* @type : library
|
||||||
|
* @date : 2018
|
||||||
|
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
|
||||||
|
* @author : a-Sansara <[dev]at[pluie]dot[org]>
|
||||||
|
* @copyright : pluie.org <http://www.pluie.org/>
|
||||||
|
*
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
*
|
||||||
|
* This file is part of pluie-yaml.
|
||||||
|
*
|
||||||
|
* pluie-yaml is free software (free as in speech) : you can redistribute it
|
||||||
|
* and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
*/
|
||||||
|
|
||||||
|
using GLib;
|
||||||
|
using Gee;
|
||||||
|
using Pluie;
|
||||||
|
|
||||||
|
int main (string[] args)
|
||||||
|
{
|
||||||
|
Echo.init(false);
|
||||||
|
|
||||||
|
var path = Yaml.DATA_PATH + "/tag.yml";
|
||||||
|
var done = false;
|
||||||
|
|
||||||
|
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
|
||||||
|
Pluie.Yaml.DEBUG = true;
|
||||||
|
var config = new Yaml.Config (path, true);
|
||||||
|
var root = config.root_node () as Yaml.Root;
|
||||||
|
if ((done = root != null)) {
|
||||||
|
root.display_childs ();
|
||||||
|
|
||||||
|
|
||||||
|
of.action("Yaml.Node", "to_yaml_string");
|
||||||
|
string yaml = root.to_yaml_string ();
|
||||||
|
print (yaml);
|
||||||
|
try {
|
||||||
|
// an output file in the current working directory
|
||||||
|
var file = File.new_for_path ( "./tag-generated.yml");
|
||||||
|
// delete if file already exists
|
||||||
|
if (file.query_exists ()) {
|
||||||
|
file.delete ();
|
||||||
|
}
|
||||||
|
var dos = new DataOutputStream (file.create (FileCreateFlags.REPLACE_DESTINATION));
|
||||||
|
uint8[] data = yaml.data;
|
||||||
|
long written = 0;
|
||||||
|
while (written < data.length) {
|
||||||
|
// sum of the bytes of 'text' that already have been written to the stream
|
||||||
|
written += dos.write (data[written:data.length]);
|
||||||
|
}
|
||||||
|
} catch (Error e) {
|
||||||
|
stderr.printf ("%s\n", e.message);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int) done;
|
||||||
|
}
|
|
@ -51,7 +51,7 @@ int main (string[] args)
|
||||||
foreach (var node in root) {
|
foreach (var node in root) {
|
||||||
of.action ("Yaml.Object from node", node.name);
|
of.action ("Yaml.Object from node", node.name);
|
||||||
of.echo (node.to_string (false));
|
of.echo (node.to_string (false));
|
||||||
if ((obj = Yaml.Builder.from_node (node)) != null) {
|
if ((obj = (Yaml.Object) Yaml.Builder.from_node (node)) != null) {
|
||||||
list[node.name] = obj;
|
list[node.name] = obj;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -75,16 +75,28 @@ int main (string[] args)
|
||||||
of.keyval("type_float" , "%f" .printf(o.type_float));
|
of.keyval("type_float" , "%f" .printf(o.type_float));
|
||||||
of.keyval("type_double" , "%f" .printf(o.type_double));
|
of.keyval("type_double" , "%f" .printf(o.type_double));
|
||||||
of.keyval("type_struct" , "%s" .printf(o.type_struct.to_string ()));
|
of.keyval("type_struct" , "%s" .printf(o.type_struct.to_string ()));
|
||||||
|
of.keyval("type_enum" , "%d (%s)" .printf(o.type_enum, o.type_enum.infos()));
|
||||||
of.keyval("type_object" , "%s" .printf(o.type_object.get_type ().name ()));
|
of.keyval("type_object" , "%s" .printf(o.type_object.get_type ().name ()));
|
||||||
of.keyval(" toto" , "%s (string)" .printf(o.type_object.toto));
|
of.keyval(" toto" , "%s (string)" .printf(o.type_object.toto));
|
||||||
of.keyval(" tapa" , "%s (string)" .printf(o.type_object.tata));
|
of.keyval(" tapa" , "%s (string)" .printf(o.type_object.tata));
|
||||||
of.keyval(" titi" , "%d (int)" .printf(o.type_object.titi));
|
of.keyval(" titi" , "%d (int)" .printf(o.type_object.titi));
|
||||||
of.keyval(" tutu" , "%s (bool)" .printf(o.type_object.tutu.to_string ()));
|
of.keyval(" tutu" , "%s (bool)" .printf(o.type_object.tutu.to_string ()));
|
||||||
o.type_object.method_a ();
|
o.type_object.method_a ();
|
||||||
if (o.type_gee_al != null) {
|
if (o.type_gee_al!= null) {
|
||||||
of.keyval("type_gee_al", "(%s)" .printf(o.type_gee_al.get_type ().name ()));
|
of.keyval("type_gee_al", "(%s)" .printf(o.type_gee_al.get_type ().name ()));
|
||||||
foreach (double v in o.type_gee_al) {
|
foreach (var v in o.type_gee_al) {
|
||||||
of.echo(" - item : %f".printf (v));
|
of.echo(" - item : %g".printf (v));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (o.type_gee_alobject != null) {
|
||||||
|
of.keyval("type_gee_alobject", "(%s<%s>)" .printf(o.type_gee_alobject.get_type ().name (), o.type_gee_alobject.element_type.name ()));
|
||||||
|
foreach (var child in o.type_gee_alobject) {
|
||||||
|
of.echo(" == entry (%s) ==".printf(child.get_type ().name ()));
|
||||||
|
of.keyval(" toto" , "%s (string)" .printf(child.toto));
|
||||||
|
of.keyval(" tapa" , "%s (string)" .printf(child.tata));
|
||||||
|
of.keyval(" titi" , "%d (int)" .printf(child.titi));
|
||||||
|
of.keyval(" tutu" , "%s (bool)" .printf(child.tutu.to_string ()));
|
||||||
|
child.method_a ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,17 +63,22 @@ int main (string[] args)
|
||||||
if (obj.type_gee_al != null) {
|
if (obj.type_gee_al != null) {
|
||||||
of.keyval("type_gee_al", "(%s<%s>)" .printf(obj.type_gee_al.get_type ().name (), obj.type_gee_al.element_type.name ()));
|
of.keyval("type_gee_al", "(%s<%s>)" .printf(obj.type_gee_al.get_type ().name (), obj.type_gee_al.element_type.name ()));
|
||||||
foreach (var v in obj.type_gee_al) {
|
foreach (var v in obj.type_gee_al) {
|
||||||
of.echo(" - item : %f".printf (v));
|
of.echo(" - item : %g".printf (v));
|
||||||
}
|
}
|
||||||
of.keyval("type_object", "(%s)" .printf(obj.type_object.get_type ().name ()));
|
of.keyval("type_object", "(%s)" .printf(obj.type_object.get_type ().name ()));
|
||||||
of.echo(" - item toto : %s".printf (obj.type_object.toto));
|
of.keyval(" toto" , "%s (string)" .printf(obj.type_object.toto));
|
||||||
of.echo(" - item tata : %s".printf (obj.type_object.tata));
|
of.keyval(" tapa" , "%s (string)" .printf(obj.type_object.tata));
|
||||||
|
of.keyval(" titi" , "%d (int)" .printf(obj.type_object.titi));
|
||||||
|
of.keyval(" tutu" , "%s (bool)" .printf(obj.type_object.tutu.to_string ()));
|
||||||
obj.type_object.method_a ();
|
obj.type_object.method_a ();
|
||||||
|
|
||||||
of.keyval("type_gee_alobject", "(%s<%s>)" .printf(obj.type_gee_alobject.get_type ().name (), obj.type_gee_alobject.element_type.name ()));
|
of.keyval("type_gee_alobject", "(%s<%s>)" .printf(obj.type_gee_alobject.get_type ().name (), obj.type_gee_alobject.element_type.name ()));
|
||||||
foreach (var child in obj.type_gee_alobject) {
|
foreach (var child in obj.type_gee_alobject) {
|
||||||
of.echo(" - item toto : %s".printf (child.toto));
|
of.echo(" == entry (%s) ==".printf(child.get_type ().name ()));
|
||||||
of.echo(" - item tata : %s".printf (child.tata));
|
of.keyval(" toto" , "%s (string)" .printf(child.toto));
|
||||||
|
of.keyval(" tapa" , "%s (string)" .printf(child.tata));
|
||||||
|
of.keyval(" titi" , "%d (int)" .printf(child.titi));
|
||||||
|
of.keyval(" tutu" , "%s (bool)" .printf(child.tutu.to_string ()));
|
||||||
child.method_a ();
|
child.method_a ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,4 +103,16 @@ public abstract class Pluie.Yaml.AbstractNode : GLib.Object
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get a yaml presentation of current Yaml.Node
|
||||||
|
*/
|
||||||
|
public string to_yaml_string (
|
||||||
|
int indent = Yaml.Dumper.DEFAULT_INDENT,
|
||||||
|
bool show_doc = Yaml.Dumper.SHOW_DOC,
|
||||||
|
bool show_tags = Yaml.Dumper.SHOW_TAGS,
|
||||||
|
bool show_fullkeys = Yaml.Dumper.SHOW_FULL_KEYS
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return Yaml.Dumper.dump ((Yaml.Node) this, indent, show_doc, show_tags);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -282,7 +282,7 @@ public class Pluie.Yaml.Builder
|
||||||
case Type.DOUBLE :
|
case Type.DOUBLE :
|
||||||
double d;
|
double d;
|
||||||
obj.get (name, out d);
|
obj.get (name, out d);
|
||||||
v = "%f".printf (d);
|
v = "%g".printf (d);
|
||||||
break;
|
break;
|
||||||
case Type.FLOAT :
|
case Type.FLOAT :
|
||||||
float f;
|
float f;
|
||||||
|
|
186
src/vala/Pluie/Yaml.Dumper.vala
Normal file
186
src/vala/Pluie/Yaml.Dumper.vala
Normal file
|
@ -0,0 +1,186 @@
|
||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
*
|
||||||
|
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||||
|
* @version : 0.5
|
||||||
|
* @type : library
|
||||||
|
* @date : 2018
|
||||||
|
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
|
||||||
|
* @author : a-Sansara <[dev]at[pluie]dot[org]>
|
||||||
|
* @copyright : pluie.org <http://www.pluie.org/>
|
||||||
|
*
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
*
|
||||||
|
* This file is part of pluie-yaml.
|
||||||
|
*
|
||||||
|
* pluie-yaml is free software (free as in speech) : you can redistribute it
|
||||||
|
* and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
*/
|
||||||
|
|
||||||
|
using GLib;
|
||||||
|
using Gee;
|
||||||
|
using Pluie;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* interface representing a collection node
|
||||||
|
*/
|
||||||
|
public class Pluie.Yaml.Dumper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static int DEFAULT_INDENT { get; internal set; default = 4; }
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static bool SHOW_DOC { get; internal set; default = true; }
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static bool SHOW_TAGS { get; internal set; default = true; }
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static bool SHOW_FULL_KEYS { get; internal set; default = false; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
internal Dumper ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get a yaml presentation of current Yaml.Node
|
||||||
|
*/
|
||||||
|
public static string dump (
|
||||||
|
Yaml.Node node,
|
||||||
|
int indent = Yaml.Dumper.DEFAULT_INDENT,
|
||||||
|
bool show_doc = Yaml.Dumper.SHOW_DOC,
|
||||||
|
bool show_tags = Yaml.Dumper.SHOW_TAGS,
|
||||||
|
bool show_fullkeys = Yaml.Dumper.SHOW_FULL_KEYS
|
||||||
|
)
|
||||||
|
{
|
||||||
|
var yaml = new StringBuilder("");
|
||||||
|
if (node.ntype.is_root ()) {
|
||||||
|
yaml_root (ref yaml, node as Yaml.Root, show_doc);
|
||||||
|
foreach (var child in node) {
|
||||||
|
yaml.append (Yaml.Dumper.dump (child, indent, show_doc, show_tags, show_fullkeys));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (node.ntype.is_single_pair ()) {
|
||||||
|
yaml_key (ref yaml, node, indent);
|
||||||
|
yaml_scalar (ref yaml, node.first (), indent);
|
||||||
|
}
|
||||||
|
else if (node.ntype.is_collection ()) {
|
||||||
|
yaml_key (ref yaml, node, indent);
|
||||||
|
foreach (var child in node) {
|
||||||
|
yaml.append (Yaml.Dumper.dump (child, indent, show_doc, show_tags, show_fullkeys));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (node.ntype.is_scalar ()) {
|
||||||
|
yaml_scalar (ref yaml, node, indent);
|
||||||
|
}
|
||||||
|
return yaml.str;
|
||||||
|
//~ return "%s%s%s%s%s%s%s%s%s%s%s".printf (
|
||||||
|
//~ this.level == 0 ? "" : of.s_indent ((int8) (withIndent ? (this.level-1)*4 : 0)),
|
||||||
|
//~ of.c (ECHO.OPTION).s ("["),
|
||||||
|
//~ this.name != null && !this.ntype.is_scalar ()
|
||||||
|
//~ ? of.c (ntype.is_root () ? ECHO.MICROTIME : ECHO.TIME).s ("%s".printf (this.name))
|
||||||
|
//~ : (
|
||||||
|
//~ this.ntype.is_scalar ()
|
||||||
|
//~ ? of.c(ECHO.DATE).s ("%s".printf (this.data))
|
||||||
|
//~ : ""
|
||||||
|
//~ ),
|
||||||
|
//~ withRefCount ? of.c (ECHO.COMMAND).s ("[%lu]".printf (this.ref_count)) : "",
|
||||||
|
//~ !withParent || this.parent == null
|
||||||
|
//~ ? withLevel ? of.c (ECHO.NUM).s (" %d".printf (this.level)) : ""
|
||||||
|
//~ : of.c (ECHO.SECTION).s (" "+this.parent.name)+(
|
||||||
|
//~ withLevel ? of.c (ECHO.NUM).s (" %d".printf (this.level)) : " "
|
||||||
|
//~ ),
|
||||||
|
//~ withType ? of.c (ECHO.OPTION_SEP).s (" %s".printf(this.ntype.infos ())) : "",
|
||||||
|
//~ withCount && this.ntype.is_collection () ? of.c (ECHO.MICROTIME).s (" %d".printf(this.count ())) : "",
|
||||||
|
//~ withUuid ? of.c (ECHO.COMMENT).s (" %s".printf(this.uuid[0:8]+"...")) : "",
|
||||||
|
//~ this.tag != null && withTag
|
||||||
|
//~ ? " %s%s".printf (
|
||||||
|
//~ of.c (ECHO.TITLE).s (" %s ".printf(this.tag.handle)),
|
||||||
|
//~ of.c (ECHO.DEFAULT).s (" %s".printf(this.tag.value))
|
||||||
|
//~ )
|
||||||
|
//~ : "",
|
||||||
|
//~ of.c (ECHO.OPTION).s ("]"),
|
||||||
|
//~ withTag && this.ntype.is_root () ? (this as Yaml.Root).get_display_tag_directives () : ""
|
||||||
|
//~ );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static void yaml_indent (ref StringBuilder yaml, Yaml.Node node, int indent, bool wrapchild = false)
|
||||||
|
{
|
||||||
|
yaml.append("%s".printf (string.nfill ((node.level-1) * indent - (wrapchild ? 2 : 0), ' ')));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static void yaml_tag (ref StringBuilder yaml, Yaml.Node node)
|
||||||
|
{
|
||||||
|
if (node.tag != null) yaml.append ("!%s!%s ".printf (node.tag.handle, node.tag.value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static void yaml_root (ref StringBuilder yaml, Yaml.Root node, bool show_doc)
|
||||||
|
{
|
||||||
|
yaml.append("%YAML %s\n".printf (Yaml.YAML_VERSION));
|
||||||
|
foreach (var entry in node.tag_directives.entries) {
|
||||||
|
yaml.append ("%TAG %s %s\n".printf (entry.key, entry.value));
|
||||||
|
}
|
||||||
|
if (show_doc) yaml.append ("---\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static void yaml_key (ref StringBuilder yaml, Yaml.Node node, int indent)
|
||||||
|
{
|
||||||
|
bool wrapseq = node.parent.ntype.is_sequence () && node.ntype.is_mapping () && node.name[0]=='_';
|
||||||
|
bool childwrap = node.parent.parent.ntype.is_sequence () && node.parent.ntype.is_mapping () && node.parent.name[0]=='_';
|
||||||
|
if (!childwrap) yaml_indent (ref yaml, node, indent);
|
||||||
|
else if (!node.is_first ()) {
|
||||||
|
yaml_indent (ref yaml, node, indent, true);
|
||||||
|
}
|
||||||
|
if (node.parent.ntype.is_sequence ()) yaml.append ("- ");
|
||||||
|
if (wrapseq) {
|
||||||
|
of.warn ("node %s wrapseq ? %s".printf (node.name, wrapseq.to_string ()));
|
||||||
|
}
|
||||||
|
yaml_tag (ref yaml, node);
|
||||||
|
if (!wrapseq) {
|
||||||
|
yaml.append("%s:%s".printf(node.name, node.ntype.is_collection () ? "\n" : " "));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static void yaml_scalar (ref StringBuilder yaml, Yaml.Node node, int indent)
|
||||||
|
{
|
||||||
|
if (!node.parent.ntype.is_single_pair ()) yaml_indent (ref yaml, node, indent);
|
||||||
|
if (node.parent.ntype.is_sequence ()) yaml.append ("- ");
|
||||||
|
yaml_tag (ref yaml, node);
|
||||||
|
yaml.append ("%s\n".printf (node.data));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -145,10 +145,10 @@ public class Pluie.Yaml.Example : Yaml.Object
|
||||||
else if (type == typeof (Gee.ArrayList)) {
|
else if (type == typeof (Gee.ArrayList)) {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case "type_gee_al" :
|
case "type_gee_al" :
|
||||||
Yaml.GeeBuilder.arraylist_to_node (this.type_gee_al, name, parent);
|
Yaml.GeeBuilder.fundamental_arraylist_to_node (this.type_gee_al, name, parent);
|
||||||
break;
|
break;
|
||||||
case "type_gee_alobject" :
|
case "type_gee_alobject" :
|
||||||
Yaml.Object.collection_to_node (this.type_gee_alobject, name, parent);
|
Yaml.Object.objects_collection_to_node (this.type_gee_alobject, name, parent);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,14 +40,15 @@ public class Pluie.Yaml.GeeBuilder
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static Yaml.Node? arraylist_to_node (Gee.ArrayList* o, string property_name, Yaml.Node parent, bool is_char = false)
|
public static Yaml.Node? fundamental_arraylist_to_node (Gee.ArrayList* o, string property_name, Yaml.Node parent, bool is_char = false)
|
||||||
{
|
{
|
||||||
Yaml.dbg_action ("prop %s (type %s) has element type :".printf (property_name, o->get_type ().name ()), o->element_type.name ());
|
Yaml.dbg_action ("prop %s (type %s) has element type :".printf (property_name, o->get_type ().name ()), o->element_type.name ());
|
||||||
|
Yaml.Node? node = null;
|
||||||
var type = o->element_type;
|
var type = o->element_type;
|
||||||
var node = new Yaml.Sequence (parent, property_name);
|
if (!type.is_object () && type.is_fundamental ()) {
|
||||||
|
node = new Yaml.Sequence (parent, property_name);
|
||||||
var it = o->iterator();
|
var it = o->iterator();
|
||||||
while (it.next ()) {
|
while (it.next ()) {
|
||||||
if (!type.is_object () && type.is_fundamental ()) {
|
|
||||||
string data = "";
|
string data = "";
|
||||||
if (is_char && (type == typeof (unichar) || type == typeof (uchar))) {
|
if (is_char && (type == typeof (unichar) || type == typeof (uchar))) {
|
||||||
void* d = (void*) it.get ();
|
void* d = (void*) it.get ();
|
||||||
|
@ -85,8 +86,8 @@ public class Pluie.Yaml.GeeBuilder
|
||||||
data = f.to_string ();
|
data = f.to_string ();
|
||||||
break;
|
break;
|
||||||
case Type.DOUBLE :
|
case Type.DOUBLE :
|
||||||
double* d = (double*) it.get ();
|
var d = (double*) it.get ();
|
||||||
data = d.to_string ();
|
data = "%g".printf (double.parse(d.to_string ()));
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
data = (string) it.get ();
|
data = (string) it.get ();
|
||||||
|
@ -95,9 +96,9 @@ public class Pluie.Yaml.GeeBuilder
|
||||||
}
|
}
|
||||||
new Yaml.Scalar (node, data);
|
new Yaml.Scalar (node, data);
|
||||||
}
|
}
|
||||||
else if (type.is_object ()) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
of.error ("in %s : Gee.ArrayList.element_type (%s) is not a fundamental type".printf (Log.METHOD, type.name ()));
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,14 +113,15 @@ public abstract class Pluie.Yaml.Object : GLib.Object
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static Yaml.Node? collection_to_node (Gee.Collection list, string name, Yaml.Node? parent = null)
|
public static Yaml.Node? objects_collection_to_node (Gee.Collection list, string name, Yaml.Node? parent = null)
|
||||||
{
|
{
|
||||||
|
of.echo (Log.METHOD);
|
||||||
var node = new Yaml.Sequence (parent, name);
|
var node = new Yaml.Sequence (parent, name);
|
||||||
node.tag = new Yaml.Tag (Yaml.Register.resolve_namespace_type(list.get_type ()), "v");
|
node.tag = new Yaml.Tag (Yaml.Register.resolve_namespace_type(list.get_type ()), "v");
|
||||||
var it = list.iterator ();
|
var it = list.iterator ();
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while (it.next ()) {
|
while (it.next ()) {
|
||||||
Yaml.Builder.to_node (
|
var s = Yaml.Builder.to_node (
|
||||||
(GLib.Object) it.get (),
|
(GLib.Object) it.get (),
|
||||||
node,
|
node,
|
||||||
false,
|
false,
|
||||||
|
|
|
@ -77,6 +77,11 @@ public class Pluie.Yaml.Processor
|
||||||
*/
|
*/
|
||||||
string? tagHandle;
|
string? tagHandle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* current tag handle
|
||||||
|
*/
|
||||||
|
Yaml.Event? nextValueEvt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Events list
|
* Events list
|
||||||
*/
|
*/
|
||||||
|
@ -164,6 +169,7 @@ public class Pluie.Yaml.Processor
|
||||||
this.reset ();
|
this.reset ();
|
||||||
for (var has_next = this.iterator.next (); has_next; has_next = this.iterator.next ()) {
|
for (var has_next = this.iterator.next (); has_next; has_next = this.iterator.next ()) {
|
||||||
this.event = this.iterator.get ();
|
this.event = this.iterator.get ();
|
||||||
|
Yaml.dbg ("Processing event %s".printf (this.event.evtype.infos ()));
|
||||||
if (this.event.evtype.is_tag_directive ()) {
|
if (this.event.evtype.is_tag_directive ()) {
|
||||||
this.on_tag_directive ();
|
this.on_tag_directive ();
|
||||||
}
|
}
|
||||||
|
@ -220,6 +226,7 @@ public class Pluie.Yaml.Processor
|
||||||
this.keyTag = null;
|
this.keyTag = null;
|
||||||
this.valueTag = null;
|
this.valueTag = null;
|
||||||
this.beginFlowSeq = false;
|
this.beginFlowSeq = false;
|
||||||
|
this.nextValueEvt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -256,6 +263,8 @@ public class Pluie.Yaml.Processor
|
||||||
var e = this.iterator.get ();
|
var e = this.iterator.get ();
|
||||||
if (e != null && e.evtype.is_value ()) {
|
if (e != null && e.evtype.is_value ()) {
|
||||||
evt = this.next_event ();
|
evt = this.next_event ();
|
||||||
|
this.nextValueEvt = evt;
|
||||||
|
of.echo ("next value event is %s".printf (evt.evtype.infos ()));
|
||||||
}
|
}
|
||||||
return evt;
|
return evt;
|
||||||
}
|
}
|
||||||
|
@ -282,11 +291,32 @@ public class Pluie.Yaml.Processor
|
||||||
*/
|
*/
|
||||||
private void on_block_end ()
|
private void on_block_end ()
|
||||||
{
|
{
|
||||||
|
of.echo (" > [ ON BLOCK END ]");
|
||||||
|
if (!this.prev_node.ntype.is_collection ()) {
|
||||||
|
of.echo (" *** prev not a collection deal with parent");
|
||||||
|
this.prev_node = this.prev_node.parent;
|
||||||
|
}
|
||||||
|
of.echo (" PREV WAS %s (%s)".printf (this.prev_node.ntype.infos (), this.prev_node.name));
|
||||||
|
of.echo (" PARENT WAS %s (%s)".printf (this.parent_node.ntype.infos (), this.parent_node.name));
|
||||||
|
bool isSequenceWithBlock = this.prev_node.ntype.is_sequence () && !this.prev_node.empty() && this.prev_node.first ().ntype.is_collection ();
|
||||||
|
of.echo (" !! isSequenceWithBlock ? %s".printf (isSequenceWithBlock.to_string ()));
|
||||||
|
if (!isSequenceWithBlock || (isSequenceWithBlock && (this.prev_node as Yaml.Sequence).close_block)) {
|
||||||
|
of.echo (" PREV IS NOT A SEQUENCE OR !! isSequenceWithBlock ? %s".printf (isSequenceWithBlock.to_string ()));
|
||||||
this.parent_node = this.prev_node.parent != null && this.prev_node.parent != this.root
|
this.parent_node = this.prev_node.parent != null && this.prev_node.parent != this.root
|
||||||
? this.prev_node.parent.parent
|
? this.prev_node.parent
|
||||||
: this.root;
|
: this.root;
|
||||||
this.prev_node = this.parent_node;
|
this.prev_node = this.parent_node;
|
||||||
}
|
}
|
||||||
|
if (isSequenceWithBlock) {
|
||||||
|
var seq = this.prev_node as Yaml.Sequence;
|
||||||
|
if (seq != null) {
|
||||||
|
seq.close_block = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
of.echo (" PREV IS %s (%s)".printf (this.prev_node.ntype.infos (), this.prev_node.name));
|
||||||
|
of.echo (" PARENT IS %s (%s)".printf (this.parent_node.ntype.infos (), this.parent_node.name));
|
||||||
|
of.echo (" < [ ON BLOCK END ]");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -294,7 +324,9 @@ public class Pluie.Yaml.Processor
|
||||||
private void on_entry ()
|
private void on_entry ()
|
||||||
{
|
{
|
||||||
this.event = this.next_event();
|
this.event = this.next_event();
|
||||||
if (this.event.evtype.is_mapping_start ()) {
|
of.echo (" >>> ON ENTRY : next value event is %s".printf (this.nextValueEvt.evtype.infos ()));
|
||||||
|
if (this.event.evtype.is_mapping_start () && this.nextValueEvt.evtype.is_mapping_start ()) {
|
||||||
|
of.echo (" THE mapping start");
|
||||||
this.on_mapping_start (true);
|
this.on_mapping_start (true);
|
||||||
}
|
}
|
||||||
else if (this.event.evtype.is_scalar ()) {
|
else if (this.event.evtype.is_scalar ()) {
|
||||||
|
@ -420,6 +452,7 @@ public class Pluie.Yaml.Processor
|
||||||
if (entry) {
|
if (entry) {
|
||||||
this.ckey = "_%d".printf(this.parent_node.count());
|
this.ckey = "_%d".printf(this.parent_node.count());
|
||||||
}
|
}
|
||||||
|
of.echo ("ckey : %s".printf (this.ckey));
|
||||||
this.node = new Yaml.Mapping (this.parent_node, this.ckey);
|
this.node = new Yaml.Mapping (this.parent_node, this.ckey);
|
||||||
this.change = true;
|
this.change = true;
|
||||||
}
|
}
|
||||||
|
@ -446,6 +479,10 @@ public class Pluie.Yaml.Processor
|
||||||
Yaml.dbg (this.node.name);
|
Yaml.dbg (this.node.name);
|
||||||
}
|
}
|
||||||
if (this.change) {
|
if (this.change) {
|
||||||
|
if (this.node.parent.ntype.is_sequence ()) {
|
||||||
|
var seq = this.node.parent as Yaml.Sequence;
|
||||||
|
if (seq != null) seq.close_block = false;
|
||||||
|
}
|
||||||
Yaml.dbg_action ("on change", this.node.name != null ? this.node.name : this.node.data);
|
Yaml.dbg_action ("on change", this.node.name != null ? this.node.name : this.node.data);
|
||||||
if (this.keyTag != null) {
|
if (this.keyTag != null) {
|
||||||
Yaml.dbg_action ("setting tag", this.keyTag.@value);
|
Yaml.dbg_action ("setting tag", this.keyTag.@value);
|
||||||
|
@ -460,11 +497,15 @@ public class Pluie.Yaml.Processor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.node.ntype.is_collection () && (this.node.empty() || (!this.node.first().ntype.is_scalar ()))) {
|
if (this.node.ntype.is_collection () && (this.node.empty() || (!this.node.first().ntype.is_scalar ()))) {
|
||||||
|
of.echo (" => SET *** **parent %s (%s) TO node %s (%s) ****".printf (this.parent_node.ntype.infos (), this.parent_node.name, this.node.ntype.infos (), this.node.name));
|
||||||
|
of.echo (" => CURNODE %s (%s) has parent : %s (%s) ****".printf (this.node.ntype.infos (), this.node.name, this.node.parent.ntype.infos (), this.node.parent.name));
|
||||||
this.parent_node = this.node;
|
this.parent_node = this.node;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
of.echo (" => SET parent %s (%s) TO node %s (%s) ====".printf (this.parent_node.ntype.infos (), this.parent_node.name, this.node.parent.ntype.infos (), this.node.parent.name));
|
||||||
this.parent_node = this.node.parent;
|
this.parent_node = this.node.parent;
|
||||||
}
|
}
|
||||||
|
of.echo (" => SET prev_node %s (%s) TO node %s (%s) ====".printf (this.prev_node.ntype.infos (), this.prev_node.name, this.node.ntype.infos (), this.node.name));
|
||||||
this.prev_node = this.node;
|
this.prev_node = this.node;
|
||||||
this.tagHandle = null;
|
this.tagHandle = null;
|
||||||
this.keyTag = null;
|
this.keyTag = null;
|
||||||
|
|
|
@ -170,6 +170,7 @@ public class Pluie.Yaml.Register
|
||||||
Yaml.dbg ("resolve_namespace_type %u (%s) => %s".printf (serial, type.name (), name));
|
Yaml.dbg ("resolve_namespace_type %u (%s) => %s".printf (serial, type.name (), name));
|
||||||
ns_resolved.set (serial, name);
|
ns_resolved.set (serial, name);
|
||||||
}
|
}
|
||||||
|
of.echo ("resolve_namespace_type %s => %s".printf (type.name (), get_resolved_ns (type)));
|
||||||
return get_resolved_ns (type);
|
return get_resolved_ns (type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ public class Pluie.Yaml.Scanner
|
||||||
{
|
{
|
||||||
var f = GLib.File.new_for_path (this.path);
|
var f = GLib.File.new_for_path (this.path);
|
||||||
try {
|
try {
|
||||||
f.delete ();
|
//~ f.delete ();
|
||||||
}
|
}
|
||||||
catch (GLib.Error e) {
|
catch (GLib.Error e) {
|
||||||
of.error (e.message);
|
of.error (e.message);
|
||||||
|
|
|
@ -37,6 +37,7 @@ using Gee;
|
||||||
*/
|
*/
|
||||||
public class Pluie.Yaml.Sequence : Yaml.Node
|
public class Pluie.Yaml.Sequence : Yaml.Node
|
||||||
{
|
{
|
||||||
|
public bool close_block { get; internal set; default = false; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default Yaml.Node constructor
|
* default Yaml.Node constructor
|
||||||
|
|
|
@ -32,6 +32,8 @@ namespace Pluie
|
||||||
{
|
{
|
||||||
namespace Yaml
|
namespace Yaml
|
||||||
{
|
{
|
||||||
|
const string YAML_VERSION = "1.2";
|
||||||
|
|
||||||
public static bool DEBUG = false;
|
public static bool DEBUG = false;
|
||||||
|
|
||||||
public static bool DBG_SHOW_INDENT = true;
|
public static bool DBG_SHOW_INDENT = true;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user