begin tag impl
This commit is contained in:
parent
79a5c4704c
commit
a3ba700140
10
README.md
10
README.md
|
@ -180,6 +180,16 @@ vala code :
|
||||||
|
|
||||||
#### via iterator
|
#### via iterator
|
||||||
|
|
||||||
|
```vala
|
||||||
|
var config = new Yaml.Config (path);
|
||||||
|
var root = config.root_node ();
|
||||||
|
foreach (var child in root) {
|
||||||
|
of.echo (child.to_string ());
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
```vala
|
```vala
|
||||||
var config = new Yaml.Config (path);
|
var config = new Yaml.Config (path);
|
||||||
var root = config.root_node ();
|
var root = config.root_node ();
|
||||||
|
|
|
@ -60,6 +60,7 @@ sources = [
|
||||||
'build/install.vala',
|
'build/install.vala',
|
||||||
'src/vala/Pluie/Io.Reader.vala',
|
'src/vala/Pluie/Io.Reader.vala',
|
||||||
'src/vala/Pluie/Io.StreamLineMark.vala',
|
'src/vala/Pluie/Io.StreamLineMark.vala',
|
||||||
|
'src/vala/Pluie/Db.Profile.vala',
|
||||||
'src/vala/Pluie/Yaml.global.vala',
|
'src/vala/Pluie/Yaml.global.vala',
|
||||||
'src/vala/Pluie/Yaml.AbstractChild.vala',
|
'src/vala/Pluie/Yaml.AbstractChild.vala',
|
||||||
'src/vala/Pluie/Yaml.AbstractNode.vala',
|
'src/vala/Pluie/Yaml.AbstractNode.vala',
|
||||||
|
@ -70,6 +71,7 @@ sources = [
|
||||||
'src/vala/Pluie/Yaml.Loader.vala',
|
'src/vala/Pluie/Yaml.Loader.vala',
|
||||||
'src/vala/Pluie/Yaml.Mapping.vala',
|
'src/vala/Pluie/Yaml.Mapping.vala',
|
||||||
'src/vala/Pluie/Yaml.Node.vala',
|
'src/vala/Pluie/Yaml.Node.vala',
|
||||||
|
'src/vala/Pluie/Yaml.Object.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',
|
||||||
|
|
|
@ -5,6 +5,7 @@ bo :
|
||||||
user : dev
|
user : dev
|
||||||
password : mysql
|
password : mysql
|
||||||
charset : utf8
|
charset : utf8
|
||||||
|
port : 3306
|
||||||
|
|
||||||
therapy :
|
therapy :
|
||||||
driver : mysql
|
driver : mysql
|
||||||
|
@ -13,3 +14,4 @@ therapy :
|
||||||
user : dev
|
user : dev
|
||||||
password : mysql
|
password : mysql
|
||||||
charset : utf8
|
charset : utf8
|
||||||
|
port : !!int 3306
|
||||||
|
|
80
samples/yamlize.vala
Normal file
80
samples/yamlize.vala
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
*
|
||||||
|
* @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 Gee;
|
||||||
|
using Pluie;
|
||||||
|
|
||||||
|
int main (string[] args)
|
||||||
|
{
|
||||||
|
Echo.init(false);
|
||||||
|
|
||||||
|
var path = Yaml.DATA_PATH + "/config/db.yml";
|
||||||
|
var done = false;
|
||||||
|
|
||||||
|
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
|
||||||
|
Pluie.Yaml.Scanner.DEBUG = false;
|
||||||
|
var config = new Yaml.Config (path, true);
|
||||||
|
Yaml.Node root = (Yaml.Node) config.root_node ();
|
||||||
|
Gee.HashMap<string, Db.Profile> db = new Gee.HashMap<string, Db.Profile> ();
|
||||||
|
if ((done = root != null)) {
|
||||||
|
foreach (var node in root) {
|
||||||
|
of.action ("Yamlize DB profile", node.name);
|
||||||
|
db[node.name] = new Db.Profile ();
|
||||||
|
if (db[node.name].yamlize (node)) {
|
||||||
|
foreach (var p in db[node.name].get_class().list_properties ()) {
|
||||||
|
var g = (node as Yaml.Mapping).item (p.name);
|
||||||
|
if (g.tag == null) {
|
||||||
|
var v = null;
|
||||||
|
db[node.name].get(p.name, &v);
|
||||||
|
of.keyval (p.name, v != null ? v : "null");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//~ of.echo ("tag is %s".printf (g.tag));
|
||||||
|
if (g.tag == "int") {
|
||||||
|
int z = -1;
|
||||||
|
db[node.name].get(p.name, ref z);
|
||||||
|
of.keyval (p.name, z.to_string ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
node = node.next_sibling ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
of.echo ("param [%s] port as int %d".printf ("bo", db["bo"].port));
|
||||||
|
of.echo ("param [%s] port as int %d".printf ("therapy", db["therapy"].port));
|
||||||
|
|
||||||
|
|
||||||
|
of.rs (done);
|
||||||
|
of.echo ();
|
||||||
|
return (int) done;
|
||||||
|
|
||||||
|
}
|
44
src/vala/Pluie/Db.Profile.vala
Normal file
44
src/vala/Pluie/Db.Profile.vala
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
*
|
||||||
|
* @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.Db.Profile : Yaml.Object
|
||||||
|
{
|
||||||
|
public string driver { get; set; }
|
||||||
|
public string host { get; set; }
|
||||||
|
public string dbname { get; set; }
|
||||||
|
public string user { get; set; }
|
||||||
|
public string password { get; set; }
|
||||||
|
public string charset { get; set; }
|
||||||
|
public int port { get; set; }
|
||||||
|
|
||||||
|
}
|
|
@ -51,6 +51,11 @@ public abstract class Pluie.Yaml.AbstractChild : Yaml.AbstractNode
|
||||||
*/
|
*/
|
||||||
public string? anchor { get; internal set; default = null; }
|
public string? anchor { get; internal set; default = null; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public string? tag { get; internal set; default = null; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default Yaml.Node constructor
|
* default Yaml.Node constructor
|
||||||
* @param parent the parent node
|
* @param parent the parent node
|
||||||
|
|
|
@ -34,7 +34,7 @@ using Pluie;
|
||||||
/**
|
/**
|
||||||
* abstract class representing a node
|
* abstract class representing a node
|
||||||
*/
|
*/
|
||||||
public abstract class Pluie.Yaml.AbstractNode : Object
|
public abstract class Pluie.Yaml.AbstractNode : GLib.Object
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* universal unique identifier
|
* universal unique identifier
|
||||||
|
|
|
@ -34,7 +34,7 @@ using Pluie;
|
||||||
/**
|
/**
|
||||||
* Finder class used to easily retriew Yaml.Node
|
* Finder class used to easily retriew Yaml.Node
|
||||||
*/
|
*/
|
||||||
public class Pluie.Yaml.Finder : Object
|
public class Pluie.Yaml.Finder : GLib.Object
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -273,7 +273,7 @@ public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
|
||||||
*/
|
*/
|
||||||
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)
|
||||||
{
|
{
|
||||||
return "%s%s%s%s%s%s%s%s%s".printf (
|
return "%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 ()
|
||||||
|
@ -294,6 +294,7 @@ public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
|
||||||
)),
|
)),
|
||||||
withCount ? 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)) : "",
|
||||||
//~ of.c (ECHO.NUM).s ("%d".printf (this.level)),
|
//~ of.c (ECHO.NUM).s ("%d".printf (this.level)),
|
||||||
of.c (ECHO.OPTION).s ("]")
|
of.c (ECHO.OPTION).s ("]")
|
||||||
);
|
);
|
||||||
|
|
72
src/vala/Pluie/Yaml.Object.vala
Normal file
72
src/vala/Pluie/Yaml.Object.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 Gee;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a test class to implements yamlize
|
||||||
|
|
||||||
|
*/
|
||||||
|
public abstract class Pluie.Yaml.Object : GLib.Object
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public bool yamlize (Yaml.Node node)
|
||||||
|
{
|
||||||
|
bool done = false;
|
||||||
|
try {
|
||||||
|
if (node!= null && !node.empty ()) {
|
||||||
|
Iterator<Yaml.Node> it = node.iterator ();
|
||||||
|
foreach (var child in node) {
|
||||||
|
foreach (var p in this.get_class ().list_properties ()) {
|
||||||
|
if (p.name == child.name) {
|
||||||
|
if (child.tag != null) {
|
||||||
|
switch (child.tag) {
|
||||||
|
case "int" :
|
||||||
|
this.set (p.name, int.parse(child.first ().data));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.set (p.name, child.first ().data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (GLib.Error e) {
|
||||||
|
of.warn (e.message);
|
||||||
|
done = false;
|
||||||
|
}
|
||||||
|
done = true;
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
}
|
|
@ -61,6 +61,16 @@ public class Pluie.Yaml.Processor
|
||||||
*/
|
*/
|
||||||
string? ckey;
|
string? ckey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* current tag suffix
|
||||||
|
*/
|
||||||
|
string? tagSuffix;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* current tag handle
|
||||||
|
*/
|
||||||
|
string? tagHandle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Events list
|
* Events list
|
||||||
*/
|
*/
|
||||||
|
@ -198,6 +208,8 @@ public class Pluie.Yaml.Processor
|
||||||
this.change = false;
|
this.change = false;
|
||||||
this.ckey = null;
|
this.ckey = null;
|
||||||
this.idAnchor = null;
|
this.idAnchor = null;
|
||||||
|
this.tagHandle = null;
|
||||||
|
this.tagSuffix = null;
|
||||||
this.beginFlowSeq = false;
|
this.beginFlowSeq = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,6 +297,12 @@ public class Pluie.Yaml.Processor
|
||||||
*/
|
*/
|
||||||
private void on_value ()
|
private void on_value ()
|
||||||
{
|
{
|
||||||
|
if (this.event.evtype.is_tag ()) {
|
||||||
|
of.keyval ("tag", this.event.evtype.to_string ());
|
||||||
|
this.tagSuffix = this.event.data["suffix"];
|
||||||
|
this.tagHandle = this.event.data["handle"];
|
||||||
|
this.event = this.next_event ();
|
||||||
|
}
|
||||||
if (this.event.evtype.is_scalar ()) {
|
if (this.event.evtype.is_scalar ()) {
|
||||||
this.on_scalar ();
|
this.on_scalar ();
|
||||||
}
|
}
|
||||||
|
@ -389,6 +407,11 @@ public class Pluie.Yaml.Processor
|
||||||
private void on_update ()
|
private void on_update ()
|
||||||
{
|
{
|
||||||
if (this.change) {
|
if (this.change) {
|
||||||
|
if (this.tagSuffix != null) {
|
||||||
|
of.action ("setting tag");
|
||||||
|
this.node.tag = this.tagSuffix;
|
||||||
|
of.echo (this.node.to_string ());
|
||||||
|
}
|
||||||
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 ()))) {
|
||||||
this.parent_node = this.node;
|
this.parent_node = this.node;
|
||||||
}
|
}
|
||||||
|
@ -396,6 +419,8 @@ public class Pluie.Yaml.Processor
|
||||||
this.parent_node = this.node.parent;
|
this.parent_node = this.node.parent;
|
||||||
}
|
}
|
||||||
this.prev_node = this.node;
|
this.prev_node = this.node;
|
||||||
|
this.tagHandle = null;
|
||||||
|
this.tagSuffix = null;
|
||||||
this.node = null;
|
this.node = null;
|
||||||
this.change = false;
|
this.change = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,6 +124,14 @@ namespace Pluie
|
||||||
return this == EVT.ALIAS;
|
return this == EVT.ALIAS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return event is tag
|
||||||
|
*/
|
||||||
|
public bool is_tag ()
|
||||||
|
{
|
||||||
|
return this == EVT.TAG;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return event is key
|
* @return event is key
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user