tag directives & tag partially managed
This commit is contained in:
parent
6c1e4d0251
commit
7a597188de
54
README.md
54
README.md
|
@ -8,7 +8,8 @@ So, currently the lib deal only with one yaml document (it's not recommended to
|
||||||
but you can use a special `^imports` clause (special mapping node) to load a subset of yaml files
|
but you can use a special `^imports` clause (special mapping node) to load a subset of yaml files
|
||||||
in the main yaml document.
|
in the main yaml document.
|
||||||
|
|
||||||
the lib does not manage yet tag directives and tag values (planned).
|
The lib partially manage tag directives and tag values (basic types and Yaml.Object extended objects types).
|
||||||
|
|
||||||
**pluie-yaml** use the ![libyaml c library](https://github.com/yaml/libyaml) (License MIT, many thanks to Kirill Simonov) to parse and retriew related yaml events.
|
**pluie-yaml** use the ![libyaml c library](https://github.com/yaml/libyaml) (License MIT, many thanks to Kirill Simonov) to parse and retriew related yaml events.
|
||||||
|
|
||||||
![pluie-yaml](https://www.meta-tech.academy/img/pluie-yaml-imports2.png)
|
![pluie-yaml](https://www.meta-tech.academy/img/pluie-yaml-imports2.png)
|
||||||
|
@ -237,6 +238,55 @@ or
|
||||||
|
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
### Tag Directives & Tag values
|
||||||
|
|
||||||
|
an example is available with `samples/yaml-tag.vala` sample
|
||||||
|
and `resources/tag.yml` file
|
||||||
|
|
||||||
|
on yaml side, proceed like that :
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
%YAML 1.2
|
||||||
|
%TAG !v! tag:pluie.org,2018:vala/
|
||||||
|
---
|
||||||
|
!v!Pluie.Yaml.Example test1 :
|
||||||
|
myname : test1object
|
||||||
|
type_int : !v!int 3306
|
||||||
|
type_bool : !v!bool false
|
||||||
|
type_char : !v!char c
|
||||||
|
type_string : !v!string mystring1
|
||||||
|
type_uchar : !v!uchar L
|
||||||
|
type_uint : !v!uint 62005
|
||||||
|
type_float : !v!float 42.36
|
||||||
|
type_double : !v!double 95542123.4579512128
|
||||||
|
!v!Pluie.Yaml.SubExample type_object :
|
||||||
|
toto : totovalue1
|
||||||
|
tata : tatavalue1
|
||||||
|
titi : 123
|
||||||
|
tutu : 1
|
||||||
|
```
|
||||||
|
|
||||||
|
on vala side :
|
||||||
|
|
||||||
|
```vala
|
||||||
|
...
|
||||||
|
Yaml.Example obj = (Yaml.Example) Yaml.Object.from_node (root.first ());
|
||||||
|
of.echo("obj.type_int : %d".printf (o.type_int));
|
||||||
|
obj.type_object.method_a ()
|
||||||
|
```
|
||||||
|
|
||||||
|
![pluie-yaml-tag](https://www.meta-tech.academy/img/libyaml-tag-ex.png)
|
||||||
|
|
||||||
|
code from samples/yaml-tag.vala :
|
||||||
|
|
||||||
|
![pluie-yaml-tag](https://www.meta-tech.academy/img/libyaml-tag-code.png)
|
||||||
|
|
||||||
|
output from samples/yaml-tag.vala :
|
||||||
|
|
||||||
|
![pluie-yaml-tag](https://www.meta-tech.academy/img/libyaml-tag-ex2.png)
|
||||||
|
|
||||||
|
-------------------
|
||||||
|
|
||||||
### more samples
|
### more samples
|
||||||
|
|
||||||
see samples files in ./samples directory
|
see samples files in ./samples directory
|
||||||
|
@ -250,6 +300,6 @@ see samples files in ./samples directory
|
||||||
* ~~rewrite nodes classes~~
|
* ~~rewrite nodes classes~~
|
||||||
* ~~put doc online~~
|
* ~~put doc online~~
|
||||||
* ~~add docker image~~
|
* ~~add docker image~~
|
||||||
* manage tag directives & tag
|
* manage tag directives & tag (partially done)
|
||||||
* improve doc
|
* improve doc
|
||||||
* dumper
|
* dumper
|
||||||
|
|
|
@ -74,9 +74,11 @@ sources = [
|
||||||
'src/vala/Pluie/Yaml.Node.vala',
|
'src/vala/Pluie/Yaml.Node.vala',
|
||||||
'src/vala/Pluie/Yaml.Object.vala',
|
'src/vala/Pluie/Yaml.Object.vala',
|
||||||
'src/vala/Pluie/Yaml.Processor.vala',
|
'src/vala/Pluie/Yaml.Processor.vala',
|
||||||
|
'src/vala/Pluie/Yaml.Root.vala',
|
||||||
'src/vala/Pluie/Yaml.Scalar.vala',
|
'src/vala/Pluie/Yaml.Scalar.vala',
|
||||||
'src/vala/Pluie/Yaml.Scanner.vala',
|
'src/vala/Pluie/Yaml.Scanner.vala',
|
||||||
'src/vala/Pluie/Yaml.Sequence.vala',
|
'src/vala/Pluie/Yaml.Sequence.vala',
|
||||||
|
'src/vala/Pluie/Yaml.SubExample.vala',
|
||||||
'src/vala/Pluie/Yaml.Tag.vala',
|
'src/vala/Pluie/Yaml.Tag.vala',
|
||||||
'src/c/yaml.c'
|
'src/c/yaml.c'
|
||||||
]
|
]
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
%TAG !v! tag:pluie.org,2018:vala/
|
%TAG !v! tag:pluie.org,2018:vala/
|
||||||
---
|
---
|
||||||
!v!Pluie.Yaml.Example test1 :
|
!v!Pluie.Yaml.Example test1 :
|
||||||
|
myname : test1object
|
||||||
type_int : !v!int 3306
|
type_int : !v!int 3306
|
||||||
type_bool : !v!bool false
|
type_bool : !v!bool false
|
||||||
type_char : !v!char c
|
type_char : !v!char c
|
||||||
|
@ -12,14 +12,24 @@
|
||||||
type_uint : !v!uint 62005
|
type_uint : !v!uint 62005
|
||||||
type_float : !v!float 42.36
|
type_float : !v!float 42.36
|
||||||
type_double : !v!double 95542123.4579512128
|
type_double : !v!double 95542123.4579512128
|
||||||
|
!v!Pluie.Yaml.SubExample type_object :
|
||||||
|
toto : totovalue1
|
||||||
|
tata : tatavalue1
|
||||||
|
titi : 123
|
||||||
|
tutu : 1
|
||||||
|
|
||||||
!v!Pluie.Yaml.Example test2 :
|
!v!Pluie.Yaml.Example test2 :
|
||||||
|
myname : test2object
|
||||||
type_int : !v!int 3306
|
type_int : 3306
|
||||||
type_bool : !v!bool true
|
type_bool : "true"
|
||||||
type_char : !v!char g
|
type_char : g
|
||||||
type_string : !v!string mystring2
|
type_string : mystring2
|
||||||
type_uchar : !v!uchar Y
|
type_uchar : Y
|
||||||
type_uint : !v!uint 63005
|
type_uint : 63005
|
||||||
type_float : !v!float 5.28
|
type_float : 5.28
|
||||||
type_double : !v!double 9.28
|
type_double : 9.28
|
||||||
|
!v!Pluie.Yaml.SubExample type_object :
|
||||||
|
toto : totovalue2
|
||||||
|
tata : tatavalue2
|
||||||
|
titi : !v!int 456
|
||||||
|
tutu : !v!bool TRUE
|
||||||
|
|
|
@ -59,12 +59,11 @@ int main (string[] args)
|
||||||
node = node.next_sibling ();
|
node = node.next_sibling ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
of.echo ("");
|
|
||||||
// hard code
|
// hard code
|
||||||
Yaml.Example? o = new Pluie.Yaml.Example ();
|
Yaml.Example? o = null;
|
||||||
foreach (var entry in list.entries) {
|
foreach (var entry in list.entries) {
|
||||||
of.action ("Getting Hard coded values for Yaml.Object %s".printf (of.c (ECHO.MICROTIME).s (o.type_from_self ())), entry.key);
|
if ((o = (Yaml.Example) entry.value)!=null) {
|
||||||
if ((o = entry.value as Yaml.Example)!=null) {
|
of.action ("Getting Hard coded values for Yaml.Object %s".printf (of.c (ECHO.MICROTIME).s (o.type_from_self ())), entry.key);
|
||||||
of.keyval("type_int" , "%d" .printf(o.type_int));
|
of.keyval("type_int" , "%d" .printf(o.type_int));
|
||||||
of.keyval("type_bool" , "%s" .printf(o.type_bool.to_string ()));
|
of.keyval("type_bool" , "%s" .printf(o.type_bool.to_string ()));
|
||||||
of.keyval("type_char" , "%c" .printf(o.type_char));
|
of.keyval("type_char" , "%c" .printf(o.type_char));
|
||||||
|
@ -72,6 +71,12 @@ int main (string[] args)
|
||||||
of.keyval("type_uchar" , "%u" .printf(o.type_uchar));
|
of.keyval("type_uchar" , "%u" .printf(o.type_uchar));
|
||||||
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_object", "%s" .printf(o.type_object.get_type ().name ()));
|
||||||
|
of.keyval(" toto (string)", "%s" .printf(o.type_object.toto));
|
||||||
|
of.keyval(" tapa (string)", "%s" .printf(o.type_object.tata));
|
||||||
|
of.keyval(" titi (int)" , "%d" .printf(o.type_object.titi));
|
||||||
|
of.keyval(" tutu (bool)" , "%s" .printf(o.type_object.tutu.to_string ()));
|
||||||
|
o.type_object.method_a ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,17 @@ public abstract class Pluie.Yaml.AbstractNode : GLib.Object
|
||||||
return node != null && node.uuid == this.uuid;
|
return node != null && node.uuid == this.uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual string to_string (bool withIndent = Yaml.DBG_SHOW_INDENT, bool withParent = Yaml.DBG_SHOW_PARENT, bool withUuid = Yaml.DBG_SHOW_UUID, bool withLevel = Yaml.DBG_SHOW_LEVEL, bool withCount = Yaml.DBG_SHOW_COUNT, bool withRefCount = Yaml.DBG_SHOW_REF){
|
public virtual string to_string (
|
||||||
|
bool withIndent = Yaml.DBG_SHOW_INDENT,
|
||||||
|
bool withParent = Yaml.DBG_SHOW_PARENT,
|
||||||
|
bool withUuid = Yaml.DBG_SHOW_UUID,
|
||||||
|
bool withLevel = Yaml.DBG_SHOW_LEVEL,
|
||||||
|
bool withCount = Yaml.DBG_SHOW_COUNT,
|
||||||
|
bool withRefCount = Yaml.DBG_SHOW_REF,
|
||||||
|
bool withTag = Yaml.DBG_SHOW_TAG,
|
||||||
|
bool withType = Yaml.DBG_SHOW_TYPE
|
||||||
|
)
|
||||||
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,28 +33,39 @@
|
||||||
*/
|
*/
|
||||||
public class Pluie.Yaml.Example : Yaml.Object
|
public class Pluie.Yaml.Example : Yaml.Object
|
||||||
{
|
{
|
||||||
public string type_string { get; set; }
|
public string myname { get; set; }
|
||||||
public int type_int { get; set; }
|
public string type_string { get; set; }
|
||||||
public uint type_uint { get; set; }
|
public int type_int { get; set; }
|
||||||
public float type_float { get; set; }
|
public uint type_uint { get; set; }
|
||||||
public double type_double { get; set; }
|
public float type_float { get; set; }
|
||||||
public char type_char { get; set; }
|
public double type_double { get; set; }
|
||||||
public uchar type_uchar { get; set; }
|
public char type_char { get; set; }
|
||||||
public unichar type_unichar { get; set; }
|
public uchar type_uchar { get; set; }
|
||||||
public short type_short { get; set; }
|
public unichar type_unichar { get; set; }
|
||||||
public ushort type_ushort { get; set; }
|
public short type_short { get; set; }
|
||||||
public long type_long { get; set; }
|
public ushort type_ushort { get; set; }
|
||||||
public ulong type_ulong { get; set; }
|
public long type_long { get; set; }
|
||||||
public size_t type_size_t { get; set; }
|
public ulong type_ulong { get; set; }
|
||||||
public ssize_t type_ssize_t { get; set; }
|
public size_t type_size_t { get; set; }
|
||||||
public int8 type_int8 { get; set; }
|
public ssize_t type_ssize_t { get; set; }
|
||||||
public uint8 type_uint8 { get; set; }
|
public int8 type_int8 { get; set; }
|
||||||
public int16 type_int16 { get; set; }
|
public uint8 type_uint8 { get; set; }
|
||||||
public uint16 type_uint16 { get; set; }
|
public int16 type_int16 { get; set; }
|
||||||
public int32 type_int32 { get; set; }
|
public uint16 type_uint16 { get; set; }
|
||||||
public uint32 type_uint32 { get; set; }
|
public int32 type_int32 { get; set; }
|
||||||
public int64 type_int64 { get; set; }
|
public uint32 type_uint32 { get; set; }
|
||||||
public uint64 type_uint64 { get; set; }
|
public int64 type_int64 { get; set; }
|
||||||
public bool type_bool { get; set; }
|
public uint64 type_uint64 { get; set; }
|
||||||
|
public bool type_bool { get; set; }
|
||||||
|
public Yaml.SubExample type_object { get; set; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected override void yaml_init ()
|
||||||
|
{
|
||||||
|
// base.yaml_init ();
|
||||||
|
Dbg.msg ("Yaml.Object %s (%s) instantiated".printf (this.myname, this.type_from_self ()), Log.LINE, Log.FILE);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class Pluie.Yaml.Mapping : Yaml.Node
|
||||||
*/
|
*/
|
||||||
public Mapping.with_scalar (Yaml.Node? parent = null, string? name = null, string? data = null)
|
public Mapping.with_scalar (Yaml.Node? parent = null, string? name = null, string? data = null)
|
||||||
{
|
{
|
||||||
base (parent, NODE_TYPE.MAPPING, name);
|
base (parent, NODE_TYPE.SINGLE_PAIR, name);
|
||||||
var s = new Scalar (null, data);
|
var s = new Scalar (null, data);
|
||||||
this.add (s);
|
this.add (s);
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,9 @@ public class Pluie.Yaml.Mapping : Yaml.Node
|
||||||
{
|
{
|
||||||
base.on_added (child);
|
base.on_added (child);
|
||||||
if (this.keys != null) {
|
if (this.keys != null) {
|
||||||
|
if (!this.ntype.is_single_pair () && this.keys.size == 0 && child.ntype.is_scalar ()) {
|
||||||
|
this.ntype = Yaml.NODE_TYPE.SINGLE_PAIR;
|
||||||
|
}
|
||||||
this.keys.add(child.name);
|
this.keys.add(child.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,6 +259,7 @@ public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
|
||||||
{
|
{
|
||||||
if (withTitle) {
|
if (withTitle) {
|
||||||
of.action ("display_childs", this.name);
|
of.action ("display_childs", this.name);
|
||||||
|
of.echo ("");
|
||||||
}
|
}
|
||||||
of.echo (this.to_string ());
|
of.echo (this.to_string ());
|
||||||
if (!this.empty ()) {
|
if (!this.empty ()) {
|
||||||
|
@ -271,13 +272,22 @@ public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
|
||||||
/**
|
/**
|
||||||
* get a presentation string of current Yaml.Node
|
* get a presentation string of current Yaml.Node
|
||||||
*/
|
*/
|
||||||
public override string to_string (bool withIndent = Yaml.DBG_SHOW_INDENT, bool withParent = Yaml.DBG_SHOW_PARENT, bool withUuid = Yaml.DBG_SHOW_UUID, bool withLevel = Yaml.DBG_SHOW_LEVEL, bool withCount = Yaml.DBG_SHOW_COUNT, bool withRefCount = Yaml.DBG_SHOW_REF)
|
public override string to_string (
|
||||||
|
bool withIndent = Yaml.DBG_SHOW_INDENT,
|
||||||
|
bool withParent = Yaml.DBG_SHOW_PARENT,
|
||||||
|
bool withUuid = Yaml.DBG_SHOW_UUID,
|
||||||
|
bool withLevel = Yaml.DBG_SHOW_LEVEL,
|
||||||
|
bool withCount = Yaml.DBG_SHOW_COUNT,
|
||||||
|
bool withRefCount = Yaml.DBG_SHOW_REF,
|
||||||
|
bool withTag = Yaml.DBG_SHOW_TAG,
|
||||||
|
bool withType = Yaml.DBG_SHOW_TYPE
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return "%s%s%s%s%s%s%s%s%s%s".printf (
|
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)),
|
this.level == 0 ? "" : of.s_indent ((int8) (withIndent ? (this.level-1)*4 : 0)),
|
||||||
of.c (ECHO.OPTION).s ("["),
|
of.c (ECHO.OPTION).s ("["),
|
||||||
this.name != null && !this.ntype.is_scalar ()
|
this.name != null && !this.ntype.is_scalar ()
|
||||||
? of.c (ECHO.TIME).s ("%s".printf (this.name))
|
? of.c (ntype.is_root () ? ECHO.MICROTIME : ECHO.TIME).s ("%s".printf (this.name))
|
||||||
: (
|
: (
|
||||||
this.ntype.is_scalar ()
|
this.ntype.is_scalar ()
|
||||||
? of.c(ECHO.DATE).s ("%s".printf (this.data))
|
? of.c(ECHO.DATE).s ("%s".printf (this.data))
|
||||||
|
@ -285,18 +295,21 @@ public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
|
||||||
),
|
),
|
||||||
withRefCount ? of.c (ECHO.COMMAND).s ("[%lu]".printf (this.ref_count)) : "",
|
withRefCount ? of.c (ECHO.COMMAND).s ("[%lu]".printf (this.ref_count)) : "",
|
||||||
!withParent || this.parent == null
|
!withParent || this.parent == null
|
||||||
? ""
|
? withLevel ? of.c (ECHO.NUM).s (" %d".printf (this.level)) : ""
|
||||||
: of.c (ECHO.SECTION).s (" "+this.parent.name)+(
|
: of.c (ECHO.SECTION).s (" "+this.parent.name)+(
|
||||||
withLevel ? of.c (ECHO.NUM).s (" %d".printf (this.level)) : " "
|
withLevel ? of.c (ECHO.NUM).s (" %d".printf (this.level)) : " "
|
||||||
),
|
),
|
||||||
of.c (ECHO.OPTION_SEP).s (" %s".printf(
|
withType ? of.c (ECHO.OPTION_SEP).s (" %s".printf(this.ntype.infos ())) : "",
|
||||||
!this.ntype.is_mapping () || this.count () >= 1 && !this.first().ntype.is_scalar () ? this.ntype.infos () : NODE_TYPE.SINGLE_PAIR.infos ()
|
withCount && this.ntype.is_collection () ? of.c (ECHO.MICROTIME).s (" %d".printf(this.count ())) : "",
|
||||||
)),
|
|
||||||
withCount ? of.c (ECHO.MICROTIME).s (" %d".printf(this.count ())) : "",
|
|
||||||
withUuid ? of.c (ECHO.COMMENT).s (" %s".printf(this.uuid[0:8]+"...")) : "",
|
withUuid ? of.c (ECHO.COMMENT).s (" %s".printf(this.uuid[0:8]+"...")) : "",
|
||||||
this.tag != null ? of.c (ECHO.OPTION_SEP).s (" %s".printf(this.tag.@value)) : "",
|
this.tag != null && withTag
|
||||||
//~ of.c (ECHO.NUM).s ("%d".printf (this.level)),
|
? " %s%s".printf (
|
||||||
of.c (ECHO.OPTION).s ("]")
|
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 () : ""
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,19 @@ using Gee;
|
||||||
*/
|
*/
|
||||||
public abstract class Pluie.Yaml.Object : GLib.Object
|
public abstract class Pluie.Yaml.Object : GLib.Object
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
private static GLib.Module? p_module;
|
private static GLib.Module? p_module;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public virtual void yaml_init ()
|
||||||
|
{
|
||||||
|
Dbg.msg ("Yaml.Object (%s) instantiated".printf (this.type_from_self ()), Log.LINE, Log.FILE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -135,18 +146,18 @@ public abstract class Pluie.Yaml.Object : GLib.Object
|
||||||
if (Yaml.Scanner.DEBUG) of.echo ("object type founded : %s".printf (type.to_string ()));
|
if (Yaml.Scanner.DEBUG) of.echo ("object type founded : %s".printf (type.to_string ()));
|
||||||
obj = (Yaml.Object) GLib.Object.new (type);
|
obj = (Yaml.Object) GLib.Object.new (type);
|
||||||
if (node!= null && !node.empty ()) {
|
if (node!= null && !node.empty ()) {
|
||||||
GLib.ParamSpec? def = null;
|
GLib.ParamSpec? def = null;
|
||||||
Yaml.Node? snode = null;
|
Yaml.Node? scalar = null;
|
||||||
foreach (var child in node) {
|
foreach (var child in node) {
|
||||||
if ((def = obj.get_class ().find_property (child.name)) != null) {
|
if ((def = obj.get_class ().find_property (child.name)) != null) {
|
||||||
if ((snode = child.first ()) != null) {
|
if (child.ntype.is_single_pair ()) {
|
||||||
if (snode.tag != null) {
|
if ((scalar = child.first ()) != null) {
|
||||||
obj.set_from_scalar (def.name, def.value_type, snode);
|
obj.set_from_scalar (def.name, def.value_type, scalar);
|
||||||
}
|
|
||||||
else {
|
|
||||||
obj.set (child.name, snode.data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (child.ntype.is_mapping ()) {
|
||||||
|
obj.set (child.name, from_node(child));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,6 +170,7 @@ public abstract class Pluie.Yaml.Object : GLib.Object
|
||||||
catch (GLib.Error e) {
|
catch (GLib.Error e) {
|
||||||
of.warn (e.message);
|
of.warn (e.message);
|
||||||
}
|
}
|
||||||
|
obj.yaml_init ();
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +197,7 @@ public abstract class Pluie.Yaml.Object : GLib.Object
|
||||||
v.set_uchar((uint8)data.data[0]);
|
v.set_uchar((uint8)data.data[0]);
|
||||||
break;
|
break;
|
||||||
case Type.BOOLEAN :
|
case Type.BOOLEAN :
|
||||||
v.set_boolean (bool.parse(data.down ()));
|
v.set_boolean (data == "1" || data.down () == "true");
|
||||||
break;
|
break;
|
||||||
case Type.INT :
|
case Type.INT :
|
||||||
v.set_int(int.parse(data));
|
v.set_int(int.parse(data));
|
||||||
|
|
|
@ -86,11 +86,6 @@ public class Pluie.Yaml.Processor
|
||||||
*/
|
*/
|
||||||
Gee.HashMap<string, Yaml.Node> anchors { get; internal set; }
|
Gee.HashMap<string, Yaml.Node> anchors { get; internal set; }
|
||||||
|
|
||||||
/**
|
|
||||||
* Tags map definition
|
|
||||||
*/
|
|
||||||
Gee.HashMap<string, string> tags { get; internal set; }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error event
|
* Error event
|
||||||
*/
|
*/
|
||||||
|
@ -104,7 +99,7 @@ public class Pluie.Yaml.Processor
|
||||||
/**
|
/**
|
||||||
* the root Yaml.Node
|
* the root Yaml.Node
|
||||||
*/
|
*/
|
||||||
public Yaml.Node root;
|
public Yaml.Root root;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* current previous Yaml.Node
|
* current previous Yaml.Node
|
||||||
|
@ -133,7 +128,6 @@ public class Pluie.Yaml.Processor
|
||||||
{
|
{
|
||||||
this.events = new Gee.ArrayList<Yaml.Event>();
|
this.events = new Gee.ArrayList<Yaml.Event>();
|
||||||
this.anchors = new Gee.HashMap<string, Yaml.Node>();
|
this.anchors = new Gee.HashMap<string, Yaml.Node>();
|
||||||
this.tags = new Gee.HashMap<string, string>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -214,8 +208,7 @@ public class Pluie.Yaml.Processor
|
||||||
*/
|
*/
|
||||||
private void reset ()
|
private void reset ()
|
||||||
{
|
{
|
||||||
this.root = new Yaml.Mapping (null, "PluieYamlRoot");
|
this.root = new Yaml.Root ();
|
||||||
this.root.ntype = Yaml.NODE_TYPE.ROOT;
|
|
||||||
this.prev_node = this.root;
|
this.prev_node = this.root;
|
||||||
this.parent_node = this.root;
|
this.parent_node = this.root;
|
||||||
this.iterator = this.events.iterator ();
|
this.iterator = this.events.iterator ();
|
||||||
|
@ -273,7 +266,7 @@ public class Pluie.Yaml.Processor
|
||||||
{
|
{
|
||||||
if (Yaml.Scanner.DEBUG)
|
if (Yaml.Scanner.DEBUG)
|
||||||
of.action ("on_tag_directive %s".printf (this.event.data["handle"]), this.event.data["prefix"]);
|
of.action ("on_tag_directive %s".printf (this.event.data["handle"]), this.event.data["prefix"]);
|
||||||
this.tags[this.event.data["handle"]] = this.event.data["prefix"];
|
this.root.tag_directives[this.event.data["handle"]] = this.event.data["prefix"];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -318,8 +311,8 @@ public class Pluie.Yaml.Processor
|
||||||
if (this.event.evtype.is_tag ()) {
|
if (this.event.evtype.is_tag ()) {
|
||||||
if (Yaml.Scanner.DEBUG)
|
if (Yaml.Scanner.DEBUG)
|
||||||
of.keyval ("tag %s".printf (this.event.data["handle"]), this.event.data["suffix"]);
|
of.keyval ("tag %s".printf (this.event.data["handle"]), this.event.data["suffix"]);
|
||||||
if (this.tags.has_key (this.event.data["handle"])) {
|
if (this.root.tag_directives.has_key (this.event.data["handle"])) {
|
||||||
var tag = new Yaml.Tag (this.event.data["suffix"], this.tags[this.event.data["handle"]]);
|
var tag = new Yaml.Tag (this.event.data["suffix"], this.event.data["handle"].replace("!", ""));
|
||||||
if (onKey)
|
if (onKey)
|
||||||
this.keyTag = tag;
|
this.keyTag = tag;
|
||||||
else
|
else
|
||||||
|
|
72
src/vala/Pluie/Yaml.Root.vala
Normal file
72
src/vala/Pluie/Yaml.Root.vala
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
*
|
||||||
|
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||||
|
* @version : 0.4
|
||||||
|
* @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 lib-yaml.
|
||||||
|
*
|
||||||
|
* lib-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.
|
||||||
|
*
|
||||||
|
* lib-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 lib-yaml. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
*/
|
||||||
|
|
||||||
|
using GLib;
|
||||||
|
using Pluie;
|
||||||
|
using Gee;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a class representing a mapping node
|
||||||
|
*/
|
||||||
|
public class Pluie.Yaml.Root : Yaml.Mapping
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Tags map definition
|
||||||
|
*/
|
||||||
|
public Gee.HashMap<string, string> tag_directives { get; internal set; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public Root (string? name = "PluieYamlRoot")
|
||||||
|
{
|
||||||
|
base (null, name);
|
||||||
|
this.ntype = Yaml.NODE_TYPE.ROOT;
|
||||||
|
this.tag_directives = new Gee.HashMap<string, string> ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public string get_display_tag_directives ()
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
foreach (var entry in this.tag_directives.entries) {
|
||||||
|
int len = 10 - entry.key.length -2;
|
||||||
|
var str = " %TAG "+@" %$(len)s"+" %s %s";
|
||||||
|
sb.append (
|
||||||
|
"\n %s %s".printf (
|
||||||
|
of.c(ECHO.TITLE).s (str.printf (" ", entry.key.replace("!", ""), Color.off ())),
|
||||||
|
of.c (ECHO.DEFAULT).s (entry.value))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return sb.str;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
45
src/vala/Pluie/Yaml.SubExample.vala
Normal file
45
src/vala/Pluie/Yaml.SubExample.vala
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
*
|
||||||
|
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||||
|
* @version : 0.4
|
||||||
|
* @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 lib-yaml.
|
||||||
|
*
|
||||||
|
* lib-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.
|
||||||
|
*
|
||||||
|
* lib-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 lib-yaml. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a test class to implements yamlize
|
||||||
|
|
||||||
|
*/
|
||||||
|
public class Pluie.Yaml.SubExample : Yaml.Object
|
||||||
|
{
|
||||||
|
public string toto { get; set; }
|
||||||
|
public string tata { get; set; }
|
||||||
|
public int titi { get; set; }
|
||||||
|
public bool tutu { get; set; }
|
||||||
|
|
||||||
|
public void method_a ()
|
||||||
|
{
|
||||||
|
of.echo (" called method from object %s builded via yaml".printf (this.type_from_self ()));
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,11 +32,13 @@ namespace Pluie
|
||||||
namespace Yaml
|
namespace Yaml
|
||||||
{
|
{
|
||||||
public static bool DBG_SHOW_INDENT = true;
|
public static bool DBG_SHOW_INDENT = true;
|
||||||
public static bool DBG_SHOW_PARENT = true;
|
public static bool DBG_SHOW_PARENT = false;
|
||||||
public static bool DBG_SHOW_UUID = true;
|
public static bool DBG_SHOW_UUID = true;
|
||||||
public static bool DBG_SHOW_LEVEL = true;
|
public static bool DBG_SHOW_LEVEL = false;
|
||||||
public static bool DBG_SHOW_REF = true;
|
public static bool DBG_SHOW_REF = false;
|
||||||
public static bool DBG_SHOW_COUNT = true;
|
public static bool DBG_SHOW_COUNT = true;
|
||||||
|
public static bool DBG_SHOW_TAG = true;
|
||||||
|
public static bool DBG_SHOW_TYPE = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ParseError
|
* ParseError
|
||||||
|
|
Loading…
Reference in New Issue
Block a user