big refacto - version 0.40
This commit is contained in:
parent
e6518a32de
commit
6cad99df70
63
README.md
63
README.md
|
@ -31,7 +31,7 @@ sudo ninja install -C build
|
|||
## Compilation
|
||||
|
||||
```
|
||||
valac --pkg gee-0.8 --pkg pluie-echo-0.2 --pkg pluie-yaml-0.3 main.vala
|
||||
valac --pkg gee-0.8 --pkg pluie-echo-0.2 --pkg pluie-yaml-0.4 main.vala
|
||||
```
|
||||
|
||||
see https://git.pluie.org/pluie/libpluie-echo in order to install pluie-echo-0.2 pkg
|
||||
|
@ -40,7 +40,7 @@ you can use `./build.sh` to rebuild/install the **pluie-yaml** lib and compile s
|
|||
|
||||
## Api / Documentation
|
||||
|
||||
https://pluie.org/pluie-yaml-0.3/index.htm
|
||||
https://pluie.org/pluie-yaml-0.4/index.htm
|
||||
(comming soon)
|
||||
|
||||
## Docker
|
||||
|
@ -66,6 +66,8 @@ docker run --rm -it pluie/libyaml
|
|||
}
|
||||
|
||||
```
|
||||
see Finder below to get precision about config.get parameter
|
||||
|
||||
-------------------
|
||||
|
||||
### config with ^imports clause
|
||||
|
@ -104,7 +106,7 @@ load a single document.
|
|||
// Pluie.Yaml.Scanner.DEBUG = true;
|
||||
var loader = new Yaml.Loader (path /* , displayFile, displayNode */);
|
||||
if ((done = loader.done)) {
|
||||
Yaml.NodeRoot root = loader.get_nodes ();
|
||||
Yaml.Node root = loader.get_nodes ();
|
||||
root.display_childs ();
|
||||
}
|
||||
```
|
||||
|
@ -141,12 +143,61 @@ vala code :
|
|||
|
||||
```vala
|
||||
...
|
||||
Yaml.NodeRoot root = loader.get_nodes ();
|
||||
var loader = new Yaml.Loader (path, true);
|
||||
if ((done = loader.done)) {
|
||||
Yaml.Node root = loader.get_nodes ();
|
||||
var finder = new Yaml.Finder(root);
|
||||
Yaml.Node? node = null;
|
||||
if ((node = finder.find ("product{0}.description")) != null) {
|
||||
var val = node.val ();
|
||||
}
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
### Traversing
|
||||
|
||||
#### via iterator
|
||||
|
||||
```
|
||||
var config = new Yaml.Config (path);
|
||||
var root = config.root_node ();
|
||||
Iterator<Yaml.Node> it = root.iterator ();
|
||||
Yaml.Node? child = null;
|
||||
for (var has_next = it.next (); has_next; has_next = it.next ()) {
|
||||
child = it.get ();
|
||||
of.echo (child.to_string ());
|
||||
}
|
||||
```
|
||||
|
||||
#### other
|
||||
|
||||
```
|
||||
if (!node.empty ()) {
|
||||
Yaml.Node child = node.first();
|
||||
of.action("loop throught mapping next sibling", child.name);
|
||||
while (child!=null && !child.is_last()) {
|
||||
// do stuff
|
||||
of.echo (child.to_string ());
|
||||
|
||||
child = child.next_sibling ();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```
|
||||
if (node.count () > 0) {
|
||||
child = node.last();
|
||||
of.action("loop throught mapping previous sibling", child.name);
|
||||
while (child!=null && !child.is_first()) {
|
||||
// do stuff
|
||||
of.echo (child.to_string ());
|
||||
|
||||
child = child.previous_sibling ();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
-------------------
|
||||
|
||||
### more samples
|
||||
|
@ -158,7 +209,7 @@ see samples files in ./samples directory
|
|||
### todo
|
||||
|
||||
* ~~imports clause~~
|
||||
* fix nodes traversing
|
||||
* ~~fix nodes traversing~~
|
||||
* ~~rewrite nodes classes~~
|
||||
* dumper
|
||||
* manage tag directives & tag
|
||||
|
||||
|
|
5
build.sh
5
build.sh
|
@ -30,7 +30,7 @@
|
|||
|
||||
# --------------------------------------------------------
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
lib="pluie-yaml-0.3"
|
||||
lib="pluie-yaml-0.4"
|
||||
c1="\033[1;38;5;215m"
|
||||
c2="\033[1;38;5;97m"
|
||||
cok="\033[1;38;5;37m"
|
||||
|
@ -51,7 +51,7 @@ function build.title()
|
|||
s="$cko<"
|
||||
fi
|
||||
if [ ! -z $3 ]; then
|
||||
echo -e " |- $c1[$c2$1$c1] $state$off"
|
||||
echo -e " |- $state $c1$1 $off"
|
||||
else
|
||||
echo -e "\n $s $c1[$c2$1$c1] $state$off"
|
||||
fi
|
||||
|
@ -81,6 +81,7 @@ function build.samples()
|
|||
for t in $resume; do
|
||||
build.title "${t:1}" ${t:0:1} 1
|
||||
done
|
||||
echo -e " binary files are located in ./bin ($DIR)"
|
||||
}
|
||||
# --------------------------------------------------------
|
||||
function build.sample()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||
* @version : 0.3
|
||||
* @version : 0.4
|
||||
* @date : 2018
|
||||
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
|
||||
* @author : a-Sansara <[dev]at[pluie]dot[org]>
|
||||
|
|
23
meson.build
23
meson.build
|
@ -1,7 +1,7 @@
|
|||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
#
|
||||
# @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||
# @version : 0.3
|
||||
# @version : 0.4
|
||||
# @date : 2018
|
||||
# @licence : GPLv3.0 <http://www.gnu.org/licenses/>
|
||||
# @author : a-Sansara <[dev]at[pluie]dot[org]>
|
||||
|
@ -39,7 +39,7 @@ dep_yaml = cc.find_library('yaml', required : true)
|
|||
|
||||
#~ add_global_link_arguments('-lyaml', language : 'c')
|
||||
|
||||
version = '0.3'
|
||||
version = '0.4'
|
||||
bindir = join_paths(get_option('prefix'), get_option('bindir'))
|
||||
datadir = join_paths(get_option('prefix'), get_option('datadir'), 'pluie')
|
||||
libdir = join_paths(get_option('prefix'), get_option('libdir'), 'pkgconfig')
|
||||
|
@ -61,20 +61,19 @@ sources = [
|
|||
'src/vala/Pluie/Io.Reader.vala',
|
||||
'src/vala/Pluie/Io.StreamLineMark.vala',
|
||||
'src/vala/Pluie/Yaml.global.vala',
|
||||
'src/vala/Pluie/Yaml.AbstractChild.vala',
|
||||
'src/vala/Pluie/Yaml.AbstractNode.vala',
|
||||
'src/vala/Pluie/Yaml.Collection.vala',
|
||||
'src/vala/Pluie/Yaml.Config.vala',
|
||||
'src/vala/Pluie/Yaml.Event.vala',
|
||||
'src/vala/Pluie/Yaml.Loader.vala',
|
||||
'src/vala/Pluie/Yaml.Finder.vala',
|
||||
'src/vala/Pluie/Yaml.Scanner.vala',
|
||||
'src/vala/Pluie/Yaml.Processor.vala',
|
||||
'src/vala/Pluie/Yaml.BaseNode.vala',
|
||||
'src/vala/Pluie/Yaml.Loader.vala',
|
||||
'src/vala/Pluie/Yaml.Mapping.vala',
|
||||
'src/vala/Pluie/Yaml.Node.vala',
|
||||
'src/vala/Pluie/Yaml.NodeCollection.vala',
|
||||
'src/vala/Pluie/Yaml.NodeMap.vala',
|
||||
'src/vala/Pluie/Yaml.NodeRoot.vala',
|
||||
'src/vala/Pluie/Yaml.NodeScalar.vala',
|
||||
'src/vala/Pluie/Yaml.NodeSequence.vala',
|
||||
'src/vala/Pluie/Yaml.NodeSinglePair.vala',
|
||||
'src/vala/Pluie/Yaml.Scalar.vala',
|
||||
'src/vala/Pluie/Yaml.Scanner.vala',
|
||||
'src/vala/Pluie/Yaml.Sequence.vala',
|
||||
'src/vala/Pluie/Yaml.Processor.vala',
|
||||
'src/c/yaml.c'
|
||||
]
|
||||
|
||||
|
|
|
@ -42,7 +42,8 @@ int main (string[] args)
|
|||
Pluie.Yaml.Scanner.DEBUG = false;
|
||||
var loader = new Yaml.Loader (path, true, true);
|
||||
if ((done = loader.done)) {
|
||||
Yaml.NodeRoot root = loader.get_nodes ();
|
||||
var root = loader.get_nodes ();
|
||||
done = root != null;
|
||||
}
|
||||
|
||||
of.rs (done);
|
||||
|
|
|
@ -42,6 +42,8 @@ int main (string[] args)
|
|||
Pluie.Yaml.Scanner.DEBUG = false;
|
||||
var config = new Yaml.Config (path, true);
|
||||
var spath = "bo.host{0}";
|
||||
var root = config.root_node ();
|
||||
root.display_childs ();
|
||||
var node = config.get (spath);
|
||||
if ((done = node != null)) {
|
||||
of.action ("retriew node from Yaml.Config", spath);
|
||||
|
|
|
@ -42,7 +42,7 @@ int main (string[] args)
|
|||
//~ Pluie.Yaml.Scanner.DEBUG = false;
|
||||
var loader = new Yaml.Loader (path, true);
|
||||
if ((done = loader.done)) {
|
||||
Yaml.NodeRoot root = loader.get_nodes ();
|
||||
Yaml.Node root = loader.get_nodes ();
|
||||
var finder = new Yaml.Finder(root);
|
||||
Yaml.Node? node = null;
|
||||
|
||||
|
@ -51,18 +51,18 @@ int main (string[] args)
|
|||
if ((node = finder.find(spath)) != null) {
|
||||
of.echo (node.to_string (false));
|
||||
of.action ("get scalar value", spath);
|
||||
of.echo ((node as Yaml.NodeSinglePair).scalar ().data);
|
||||
of.echo (node.first ().data);
|
||||
|
||||
of.action ("get parent node");
|
||||
of.echo (node.parent.to_string ());
|
||||
|
||||
of.action ("get address node");
|
||||
if ((node = (node.parent as Yaml.NodeMap).map["address"])!= null) {
|
||||
if ((node = (node.parent as Yaml.Mapping).item ("address"))!= null) {
|
||||
of.echo (node.to_string (false));
|
||||
(node as Yaml.NodeMap).display_childs ();
|
||||
node.display_childs ();
|
||||
|
||||
of.action ("Loop throught childs", node.name);
|
||||
foreach (var child in (node as Yaml.NodeMap).map.values) {
|
||||
foreach (var child in node.list) {
|
||||
of.echo (child.to_string (false));
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ int main (string[] args)
|
|||
else of.state (node != null);
|
||||
|
||||
of.action ("Set find mode", "SQUARE_BRACKETS");
|
||||
Yaml.BaseNode.mode = Yaml.FIND_MODE.SQUARE_BRACKETS;
|
||||
Yaml.MODE = Yaml.FIND_MODE.SQUARE_BRACKETS;
|
||||
of.state (true);
|
||||
|
||||
spath = "[product]{0}[description]";
|
||||
|
|
|
@ -42,7 +42,8 @@ int main (string[] args)
|
|||
Pluie.Yaml.Scanner.DEBUG = false;
|
||||
var loader = new Yaml.Loader (path, true, true);
|
||||
if ((done = loader.done)) {
|
||||
Yaml.NodeRoot root = loader.get_nodes ();
|
||||
var root = loader.get_nodes ();
|
||||
done = root != null;
|
||||
}
|
||||
|
||||
of.rs (done);
|
||||
|
|
141
samples/yaml-node.vala
Normal file
141
samples/yaml-node.vala
Normal file
|
@ -0,0 +1,141 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||
* @version : 0.3
|
||||
* @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 done = false;
|
||||
|
||||
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
|
||||
|
||||
var gp = new Yaml.Mapping (null, "grandfather");
|
||||
of.action ("new mapping", gp.name);
|
||||
of.echo (gp.to_string ());
|
||||
var f = new Yaml.Mapping (gp, "father");
|
||||
of.action ("new mapping", f.name);
|
||||
of.echo (f.to_string ());
|
||||
|
||||
var c1 = new Yaml.Mapping.with_scalar (f, "son1", "saraxce");
|
||||
of.action ("new mapping", c1.name);
|
||||
of.echo (c1.to_string ());
|
||||
var d1 = new Yaml.Scalar(null, "mes data");
|
||||
of.action ("new mapping", "scalar");
|
||||
of.echo (d1.to_string ());
|
||||
var d2 = new Yaml.Mapping(c1, "sonar");
|
||||
of.action ("new mapping", d2.name);
|
||||
of.echo (d2.to_string ());
|
||||
of.action ("adding scalar to ", c1.name);
|
||||
c1.add (d1);
|
||||
of.action ("count from", c1.name);
|
||||
of.echo ("%d ".printf (c1.count ()));
|
||||
of.action ("count from", gp.name);
|
||||
of.echo ("%d ".printf (gp.count ()));
|
||||
|
||||
var c2 = new Yaml.Mapping (f, "son2");
|
||||
of.action ("new mapping", c2.name);
|
||||
of.echo (c2.to_string ());
|
||||
var d3 = new Yaml.Mapping.with_scalar (c2, "little-son1", "with data");
|
||||
of.action ("new mapping with scalar", d2.name);
|
||||
of.echo (d3.to_string ());
|
||||
var d4 = new Yaml.Mapping.with_scalar (c2, "little-son2", "with data too");
|
||||
of.action ("new mapping with scalar", d4.name);
|
||||
of.echo (d4.to_string ());
|
||||
var c3 = new Yaml.Mapping (f, "son3");
|
||||
of.action ("new mapping", c3.name);
|
||||
of.echo (c3.to_string ());
|
||||
var c4 = new Yaml.Mapping (f, "son4");
|
||||
of.action ("new mapping", c4.name);
|
||||
of.echo (c4.to_string ());
|
||||
|
||||
of.action ("first from", f.name);
|
||||
var child = f.first( );
|
||||
if (child != null) {
|
||||
of.echo (child.to_string ());
|
||||
|
||||
of.echo ("is first ? %d".printf ((int)child.is_first ()));
|
||||
of.echo ("is last ? %d".printf ((int)child.is_last ()));
|
||||
|
||||
while ((child = child.next_sibling ()) != null) {
|
||||
of.action ("next sibling", child.name);
|
||||
of.echo (child.to_string ());
|
||||
of.echo ("is last ? %d".printf ((int)child.is_last ()));
|
||||
}
|
||||
}
|
||||
|
||||
of.action ("clone node ", f.name);
|
||||
Yaml.Mapping f2 = f.clone_node("father2") as Yaml.Mapping;
|
||||
of.echo (f2.to_string ());
|
||||
|
||||
of.action ("iterator from", f2.name);
|
||||
Iterator<Yaml.Node> it = f2.iterator ();
|
||||
Yaml.Node? n = null;
|
||||
for (var has_next = it.next (); has_next; has_next = it.next ()) {
|
||||
n = it.get ();
|
||||
of.action ("node via iterator.next ()", n.name);
|
||||
of.echo (n.to_string ());
|
||||
}
|
||||
|
||||
of.action ("first from cloned", f2.name);
|
||||
child = f2.first( );
|
||||
if (child != null) {
|
||||
of.echo (child.to_string ());
|
||||
|
||||
of.echo ("is first ? %d".printf ((int)child.is_first ()));
|
||||
of.echo ("is last ? %d".printf ((int)child.is_last ()));
|
||||
|
||||
while ((child = child.next_sibling ()) != null) {
|
||||
of.action ("next sibling", child.name);
|
||||
of.echo (child.to_string ());
|
||||
of.echo ("is last ? %d".printf ((int)child.is_last ()));
|
||||
}
|
||||
}
|
||||
|
||||
of.action ("get child via names from cloned", f2.name);
|
||||
foreach (string g in f2.child_names ()) {
|
||||
of.echo (f2.item (g).to_string ());
|
||||
}
|
||||
|
||||
gp.add (f2);
|
||||
gp.display_childs ();
|
||||
|
||||
var dq = new Yaml.Node (null, Yaml.NODE_TYPE.ROOT, "PluieYamlRoot");
|
||||
dq.add (gp);
|
||||
of.echo (dq.to_string ());
|
||||
dq.display_childs ();
|
||||
|
||||
of.rs (n.is_last ());
|
||||
of.echo ();
|
||||
return (int) done;
|
||||
|
||||
}
|
|
@ -41,7 +41,6 @@ int main (string[] args)
|
|||
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
|
||||
Pluie.Yaml.Scanner.DEBUG = false;
|
||||
var config = new Yaml.Config (path, true);
|
||||
var spath = "bo.host{0}";
|
||||
var node = config.root_node ();
|
||||
if ((done = node != null)) {
|
||||
node.display_childs ();
|
||||
|
@ -50,12 +49,12 @@ int main (string[] args)
|
|||
var child = config.get("product");
|
||||
of.echo (child.to_string (false));
|
||||
of.action("retriew sequence last child node", child.name);
|
||||
var nchild = child.last_child ();
|
||||
var nchild = child.last ();
|
||||
if (nchild != null) {
|
||||
of.echo (nchild.to_string ());
|
||||
}
|
||||
of.action("retriew sequence first child node", child.name);
|
||||
nchild = child.first_child ();
|
||||
nchild = child.first ();
|
||||
if (nchild != null) {
|
||||
of.echo (nchild.to_string ());
|
||||
of.action("retriew sequence next sibling node", nchild.name);
|
||||
|
@ -76,32 +75,36 @@ int main (string[] args)
|
|||
child = config.get("ship-to");
|
||||
of.echo (child.to_string (false));
|
||||
of.action("retriew mapping last child node", child.name);
|
||||
nchild = child.last_child ();
|
||||
nchild = child.last ();
|
||||
if (nchild != null) {
|
||||
of.echo (nchild.to_string ());
|
||||
}
|
||||
of.action("retriew mapping first child node", child.name);
|
||||
nchild = child.first_child ();
|
||||
nchild = child.first ();
|
||||
if (nchild != null) {
|
||||
of.echo (nchild.to_string ());
|
||||
}
|
||||
of.action("loop throught mapping next sibling", child.name);
|
||||
while (!child.is_last_child()) {
|
||||
while (child!=null && !child.is_last()) {
|
||||
child = child.next_sibling ();
|
||||
if (child != null) {
|
||||
of.echo (child.to_string (false));
|
||||
}
|
||||
}
|
||||
of.action("loop throught mapping previous sibling", child.name);
|
||||
while (!child.is_first_child()) {
|
||||
while (!child.is_first()) {
|
||||
child = child.previous_sibling ();
|
||||
if (child != null) {
|
||||
of.echo (child.to_string (false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
of.echo("\n ================================ ");
|
||||
|
||||
of.action ("current node is ", child.name);
|
||||
of.echo ("switch node : next_sibling ().next_sibling ().first_child ()");
|
||||
child = child.next_sibling ().next_sibling ().first_child ();
|
||||
child = child.next_sibling ().next_sibling ().first ();
|
||||
|
||||
of.action ("current node is ", child.name);
|
||||
of.echo ("use finder to retriew parent node");
|
||||
|
@ -112,7 +115,7 @@ int main (string[] args)
|
|||
}
|
||||
of.action ("current node is ", child.name);
|
||||
of.echo ("switch node : parent.next_sibling ().next_sibling ().first_child ().first_child ()");
|
||||
child = child.parent.next_sibling ().next_sibling ().first_child ().first_child ();
|
||||
child = child.parent.next_sibling ().next_sibling ().first ().first ();
|
||||
of.action ("current node is ", child.name);
|
||||
of.echo ("use finder to retriew parent node");
|
||||
n = config.get ("product{0}");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||
* @version : 0.3
|
||||
* @version : 0.4
|
||||
* @date : 2018
|
||||
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
|
||||
* @author : a-Sansara <[dev]at[pluie]dot[org]>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||
* @version : 0.3
|
||||
* @version : 0.4
|
||||
* @date : 2018
|
||||
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
|
||||
* @author : a-Sansara <[dev]at[pluie]dot[org]>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||
* @version : 0.3
|
||||
* @version : 0.4
|
||||
* @date : 2018
|
||||
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
|
||||
* @author : a-Sansara <[dev]at[pluie]dot[org]>
|
||||
|
|
135
src/vala/Pluie/Yaml.AbstractChild.vala
Normal file
135
src/vala/Pluie/Yaml.AbstractChild.vala
Normal file
|
@ -0,0 +1,135 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @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 abstract class Pluie.Yaml.AbstractChild : Yaml.AbstractNode
|
||||
{
|
||||
/**
|
||||
* current representation level
|
||||
*/
|
||||
public int level { get; internal set; default = 0; }
|
||||
|
||||
/**
|
||||
* parent node
|
||||
*/
|
||||
public Yaml.Node? parent { get; internal set; default = null; }
|
||||
|
||||
/**
|
||||
* anchor
|
||||
*/
|
||||
public string? anchor { get; internal set; default = null; }
|
||||
|
||||
/**
|
||||
* default Yaml.Node constructor
|
||||
* @param parent the parent node
|
||||
* @param type the NODE_TYPE of Yaml.Node to create
|
||||
*/
|
||||
public AbstractChild (Yaml.Node ? parent = null, Yaml.NODE_TYPE type = Yaml.NODE_TYPE.UNDEFINED, string? name = null)
|
||||
{
|
||||
base (type, name);
|
||||
this.parent = parent;
|
||||
if (this.has_parent ()) {
|
||||
this.parent.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check if has parent
|
||||
*/
|
||||
public bool has_parent ()
|
||||
{
|
||||
return this.parent != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if first chikd
|
||||
*/
|
||||
public bool is_first ()
|
||||
{
|
||||
return !this.has_parent () ? false : this.same_node (this.parent.first ());
|
||||
}
|
||||
|
||||
/**
|
||||
* check if first chikd
|
||||
*/
|
||||
public bool is_last ()
|
||||
{
|
||||
return !this.has_parent () ? false : this.same_node (this.parent.last ());
|
||||
}
|
||||
|
||||
/**
|
||||
* check if first chikd
|
||||
*/
|
||||
public Yaml.Node? next_sibling ()
|
||||
{
|
||||
return !this.has_parent () ? null : this.parent.child_next_sibling (this as Yaml.Node);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if first chikd
|
||||
*/
|
||||
public Yaml.Node? previous_sibling ()
|
||||
{
|
||||
return !this.has_parent () ? null : this.parent.child_previous_sibling (this as Yaml.Node);
|
||||
}
|
||||
|
||||
/**
|
||||
* stuff on changing parent node
|
||||
* @param child the childto add
|
||||
*/
|
||||
protected virtual bool on_change_parent (bool levelUpdate = true)
|
||||
{
|
||||
bool done = true;
|
||||
if (this.parent != null && !this.parent.empty ()) {
|
||||
done = this.parent.remove_child (this as Yaml.Node, levelUpdate);
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
public virtual int count ()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected virtual void set_anchor_id (string id)
|
||||
{
|
||||
this.anchor = id;
|
||||
}
|
||||
|
||||
|
||||
}
|
97
src/vala/Pluie/Yaml.AbstractNode.vala
Normal file
97
src/vala/Pluie/Yaml.AbstractNode.vala
Normal file
|
@ -0,0 +1,97 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @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;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public abstract class Pluie.Yaml.AbstractNode : Object
|
||||
{
|
||||
/**
|
||||
* universal unique identifier
|
||||
*/
|
||||
public string uuid { get; internal set; }
|
||||
|
||||
/**
|
||||
* current node name (key)
|
||||
*/
|
||||
public string? name { get; internal set; default = null; }
|
||||
|
||||
/**
|
||||
* current node data for Yaml.NodeScalar node
|
||||
*/
|
||||
public string? data { get; internal set; default = null; }
|
||||
|
||||
/**
|
||||
* node type related to Yaml.NODE_TYPE
|
||||
*/
|
||||
public Yaml.NODE_TYPE ntype { get; internal set; default = NODE_TYPE.UNDEFINED; }
|
||||
|
||||
/**
|
||||
* default Yaml.Node constructor
|
||||
* @param parent the parent node
|
||||
* @param type the NODE_TYPE of Yaml.Node to create
|
||||
*/
|
||||
public AbstractNode (Yaml.NODE_TYPE type = Yaml.NODE_TYPE.UNDEFINED, string? name = null)
|
||||
{
|
||||
this.with_name(type, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* constructor for standard Yaml.Node
|
||||
* @param parent the parent node
|
||||
* @param type the NODE_TYPE of Yaml.Node to create
|
||||
*/
|
||||
public AbstractNode.with_name (Yaml.NODE_TYPE type = Yaml.NODE_TYPE.UNDEFINED, string? name = null, string? data = null)
|
||||
{
|
||||
this.ntype = type;
|
||||
this.name = name;
|
||||
this.data = data;
|
||||
this.uuid = Yaml.uuid ();
|
||||
}
|
||||
|
||||
/**
|
||||
* test if specifiyed node is current node
|
||||
* @param child the Yaml.Node node to test
|
||||
*/
|
||||
public virtual bool same_node (Yaml.AbstractNode? node)
|
||||
{
|
||||
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){
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,366 +0,0 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||
* @version : 0.3
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* parent class representing a Yaml Node whenether was his type
|
||||
*/
|
||||
public class Pluie.Yaml.BaseNode : Object, Pluie.Yaml.Node, Pluie.Yaml.NodeCollection
|
||||
{
|
||||
/**
|
||||
* universal unique identifier
|
||||
*/
|
||||
public string uuid { get; internal set; }
|
||||
|
||||
/**
|
||||
* anchor
|
||||
*/
|
||||
public string anchor { get; internal set; }
|
||||
|
||||
/**
|
||||
* find mode related to Yaml.FIND_MODE, default is Yaml.FIND_MODE.SQUARE_BRACKETS
|
||||
*/
|
||||
public static Yaml.FIND_MODE mode { get; set; default = Yaml.FIND_MODE.DOT; }
|
||||
|
||||
/**
|
||||
* node type related to Yaml.NODE_TYPE
|
||||
*/
|
||||
public Yaml.NODE_TYPE node_type { get; internal set; }
|
||||
|
||||
/**
|
||||
* current representation level
|
||||
*/
|
||||
public int level { get; internal set; }
|
||||
|
||||
/**
|
||||
* parent node
|
||||
*/
|
||||
public Yaml.Node? parent { get; internal set; }
|
||||
|
||||
/**
|
||||
* current node data for Yaml.NodeScalar node
|
||||
*/
|
||||
public string? data { get; internal set; default = null; }
|
||||
|
||||
/**
|
||||
* current node name (key)
|
||||
*/
|
||||
public string? name { get; internal set; default = null; }
|
||||
|
||||
/**
|
||||
* default Yaml.Node constructor
|
||||
* @param parent the parent node
|
||||
* @param type the NODE_TYPE of Yaml.Node to create
|
||||
*/
|
||||
public BaseNode (Yaml.Node? parent = null, NODE_TYPE type = NODE_TYPE.UNDEFINED)
|
||||
{
|
||||
this.standard (parent, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* constructor for root Yaml.Node
|
||||
*/
|
||||
public BaseNode.root () {
|
||||
this.standard (null, NODE_TYPE.ROOT);
|
||||
this.name = "PluieYamlRootNode";
|
||||
}
|
||||
|
||||
/**
|
||||
* constructor for standard Yaml.Node
|
||||
* @param parent the parent node
|
||||
* @param type the NODE_TYPE of Yaml.Node to create
|
||||
*/
|
||||
internal BaseNode.standard (Yaml.Node? parent = null, NODE_TYPE type = NODE_TYPE.UNDEFINED)
|
||||
{
|
||||
this.parent = parent;
|
||||
this.node_type = type;
|
||||
this.level = parent!=null ? parent.level + 1 : 0;
|
||||
this.uuid = Yaml.uuid ();
|
||||
}
|
||||
|
||||
/**
|
||||
* test if specifiyed node is current node
|
||||
* @param child the Yaml.Node node to test
|
||||
*/
|
||||
public virtual bool same_node (Yaml.Node? node)
|
||||
{
|
||||
return node != null && node.uuid != this.uuid;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected virtual void set_anchor_id (string id)
|
||||
{
|
||||
this.anchor = id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public string? val ()
|
||||
{
|
||||
string v = null;
|
||||
if (this.node_type.is_single_pair ()) {
|
||||
v = (this as Yaml.NodeSinglePair).scalar ().data;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* clone current node
|
||||
* @param the name of clone
|
||||
*/
|
||||
public virtual Yaml.Node clone_node (string? name = null)
|
||||
{
|
||||
return new BaseNode.standard (this.parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* stuff on changing parent node
|
||||
* @param child the childto add
|
||||
*/
|
||||
protected virtual bool on_change_parent ()
|
||||
{
|
||||
bool done = true;
|
||||
if (this.parent != null) {
|
||||
done = this.parent.remove_child (this);
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
/**
|
||||
* add a child
|
||||
* @param child the childto add
|
||||
*/
|
||||
public virtual bool add (Yaml.Node child)
|
||||
{
|
||||
child.parent = this;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* remove a child
|
||||
* @param child the child to remove
|
||||
*/
|
||||
protected virtual bool remove_child (Yaml.Node child)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public bool is_last (Yaml.Node child) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public bool is_first (Yaml.Node child) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public virtual Yaml.Node? first_child ()
|
||||
{
|
||||
Yaml.Node? child = (this as Yaml.NodeCollection).first_child ();
|
||||
return child;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public virtual Yaml.Node? last_child ()
|
||||
{
|
||||
Yaml.Node? child = (this as Yaml.NodeCollection).last_child ();
|
||||
return child;
|
||||
}
|
||||
|
||||
/**
|
||||
* give the next sibling node
|
||||
*/
|
||||
public virtual Yaml.Node? next_sibling ()
|
||||
{
|
||||
Yaml.Node? sibling = null;
|
||||
if (this.parent != null) {
|
||||
sibling = (this.parent as Yaml.NodeCollection).child_next_sibling (this);
|
||||
if (sibling == this) sibling = null;
|
||||
}
|
||||
return sibling;
|
||||
}
|
||||
|
||||
/**
|
||||
* give the previous sibling node
|
||||
*/
|
||||
public virtual Yaml.Node? previous_sibling ()
|
||||
{
|
||||
Yaml.Node? sibling = null;
|
||||
if (this.parent != null) {
|
||||
sibling = (this.parent as Yaml.NodeCollection).child_previous_sibling (this);
|
||||
}
|
||||
return sibling;
|
||||
}
|
||||
|
||||
/**
|
||||
* give the root parent node
|
||||
*/
|
||||
public virtual Yaml.Node? get_root_node ()
|
||||
{
|
||||
Yaml.Node? parent = this.parent;
|
||||
if (parent != null) {
|
||||
while(parent.parent != null) {
|
||||
parent = parent.parent;
|
||||
}
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* retriew the previous sibling of specifiyed child node
|
||||
* @param child
|
||||
*/
|
||||
public virtual Yaml.Node? child_previous_sibling (Yaml.Node child)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* retriew the next sibling of specifiyed child node
|
||||
* @param child
|
||||
*/
|
||||
public virtual Yaml.Node? child_next_sibling (Yaml.Node child)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public virtual int get_size () {
|
||||
return this.node_type.is_collection () ? (this as Yaml.NodeCollection).get_size () : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if node has child nodes
|
||||
*/
|
||||
public virtual bool has_child_nodes ()
|
||||
{
|
||||
return this.node_type.is_collection () && (this as Yaml.NodeCollection).get_size () > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if first chikd
|
||||
*/
|
||||
public virtual bool is_first_child ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if last chikd
|
||||
*/
|
||||
public virtual bool is_last_child ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if current node contains the specifiyed child node
|
||||
* @param child
|
||||
*/
|
||||
public virtual bool contains (Yaml.Node child)
|
||||
{
|
||||
bool has = false;
|
||||
if (this.node_type.is_collection ()) {
|
||||
has = (this as Yaml.NodeCollection).contains (child);
|
||||
}
|
||||
return has;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public virtual void update_level()
|
||||
{
|
||||
this.level = this.parent != null ? this.parent.level + 1 : 0;
|
||||
switch (this.node_type) {
|
||||
case NODE_TYPE.SINGLE_PAIR :
|
||||
(this as Yaml.NodeSinglePair).scalar ().update_level ();
|
||||
break;
|
||||
case NODE_TYPE.ROOT :
|
||||
case NODE_TYPE.MAPPING :
|
||||
foreach (var child in (this as Yaml.NodeMap).map.values) {
|
||||
child.update_level ();
|
||||
}
|
||||
break;
|
||||
case NODE_TYPE.SEQUENCE :
|
||||
foreach (var child in (this as Yaml.NodeSequence).list) {
|
||||
child.update_level ();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get a presentation string of current Yaml.Node
|
||||
*/
|
||||
public string to_string (bool indentFormat = true, bool withParent = false, bool withUuid = false, bool withLevel = false, bool withRefCount = false)
|
||||
{
|
||||
return "%s%s%s%s%s%s%s%s".printf (
|
||||
this.node_type.is_root () ? "" : of.s_indent ((int8) (indentFormat ? (this.level-1)*4 : 0)),
|
||||
of.c (ECHO.OPTION).s ("["),
|
||||
this.name != null && !this.node_type.is_scalar ()
|
||||
? of.c (ECHO.TIME).s ("%s".printf (this.name))
|
||||
: (
|
||||
this.node_type.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
|
||||
? ""
|
||||
: of.c (ECHO.SECTION).s (" "+this.parent.name)+(
|
||||
withLevel ? of.c (ECHO.NUM).s (" %d".printf (this.level)) : " "
|
||||
),
|
||||
of.c (ECHO.OPTION_SEP).s (" %s".printf(this.node_type.infos ())),
|
||||
withUuid ? of.c (ECHO.COMMENT).s (" %s".printf(this.uuid[0:8]+"...")) : "",
|
||||
//~ of.c (ECHO.NUM).s ("%d".printf (this.level)),
|
||||
of.c (ECHO.OPTION).s ("]")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||
* @version : 0.3
|
||||
* @version : 0.4
|
||||
* @date : 2018
|
||||
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
|
||||
* @author : a-Sansara <[dev]at[pluie]dot[org]>
|
||||
|
@ -28,19 +28,56 @@
|
|||
*/
|
||||
|
||||
using GLib;
|
||||
using Gee;
|
||||
using Pluie;
|
||||
|
||||
/**
|
||||
* a class representing a mapping node
|
||||
* interface representing a collection node
|
||||
*/
|
||||
public interface Pluie.Yaml.NodeCollection
|
||||
public interface Pluie.Yaml.Collection
|
||||
{
|
||||
|
||||
/**
|
||||
* retriew the previous sibling of specifiyed child node
|
||||
* retriew the child at index
|
||||
* @param child
|
||||
*/
|
||||
public abstract Yaml.Node? child_previous_sibling (Yaml.Node child);
|
||||
public abstract Yaml.Node? item (int index);
|
||||
|
||||
/**
|
||||
* check if contains specifyed child node
|
||||
* @param child
|
||||
*/
|
||||
public abstract bool contains (Yaml.Node child);
|
||||
|
||||
/**
|
||||
* count children
|
||||
* @param child
|
||||
*/
|
||||
public abstract int count ();
|
||||
|
||||
/**
|
||||
* check if empty
|
||||
* @param child
|
||||
*/
|
||||
public abstract bool empty ();
|
||||
|
||||
/**
|
||||
* check if empty
|
||||
* @param child
|
||||
*/
|
||||
public abstract Gee.Iterator<Yaml.Node> iterator ();
|
||||
|
||||
|
||||
/**
|
||||
* retriew the first child
|
||||
* @param child
|
||||
*/
|
||||
public abstract Yaml.Node? first ();
|
||||
|
||||
/**
|
||||
* retriew the last child
|
||||
* @param child
|
||||
*/
|
||||
public abstract Yaml.Node? last ();
|
||||
|
||||
/**
|
||||
* retriew the next sibling of specifiyed child node
|
||||
|
@ -52,32 +89,6 @@ public interface Pluie.Yaml.NodeCollection
|
|||
* retriew the previous sibling of specifiyed child node
|
||||
* @param child
|
||||
*/
|
||||
public abstract Yaml.Node? first_child ();
|
||||
public abstract Yaml.Node? child_previous_sibling (Yaml.Node child);
|
||||
|
||||
/**
|
||||
* retriew the next sibling of specifiyed child node
|
||||
* @param child
|
||||
*/
|
||||
public abstract Yaml.Node? last_child ();
|
||||
|
||||
/**
|
||||
* check if first chikd
|
||||
*/
|
||||
public abstract bool is_first (Yaml.Node child);
|
||||
|
||||
/**
|
||||
* check if last chikd
|
||||
*/
|
||||
public abstract bool is_last (Yaml.Node child);
|
||||
|
||||
/**
|
||||
* count childnodes
|
||||
*/
|
||||
public abstract int get_size ();
|
||||
|
||||
/**
|
||||
* check if current node contains the specifiyed child node
|
||||
* @param child
|
||||
*/
|
||||
public abstract bool contains (Yaml.Node node);
|
||||
}
|
|
@ -1,3 +1,32 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @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 class to manage Yaml configuration files
|
||||
*/
|
||||
|
@ -43,12 +72,12 @@ public class Pluie.Yaml.Config
|
|||
*/
|
||||
public Config (string? path = null, bool displayFile = false, Yaml.FIND_MODE mode = Yaml.FIND_MODE.DOT)
|
||||
{
|
||||
Yaml.BaseNode.mode = mode;
|
||||
Yaml.MODE = mode;
|
||||
this.path = path;
|
||||
this.displayFile = displayFile;
|
||||
if (this.path != null) {
|
||||
this.loader = new Yaml.Loader (this.path, displayFile, false);
|
||||
Yaml.NodeRoot? root = this.loader.get_nodes ();
|
||||
Yaml.Node? root = this.loader.get_nodes ();
|
||||
if (root != null) {
|
||||
this.finder = new Yaml.Finder(root);
|
||||
this.get_imports ();
|
||||
|
@ -71,9 +100,9 @@ public class Pluie.Yaml.Config
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public Yaml.NodeRoot root_node ()
|
||||
public Yaml.Node root_node ()
|
||||
{
|
||||
return this.finder.context as Yaml.NodeRoot;
|
||||
return this.finder.context;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,10 +110,10 @@ public class Pluie.Yaml.Config
|
|||
*/
|
||||
public void get_imports ()
|
||||
{
|
||||
var node = this.get("^imports") as Yaml.NodeMap;
|
||||
var node = this.get("^imports");
|
||||
if (node != null) {
|
||||
var root = node.parent as Yaml.NodeRoot;
|
||||
if (root != null && root.node_type.is_root ()) {
|
||||
var root = node.parent;
|
||||
if (root != null && root.ntype.is_root ()) {
|
||||
this.get_imports_var(node);
|
||||
var dir = this.strip_path(Path.get_dirname (this.path));
|
||||
if (this.varmap.has_key ("path")) {
|
||||
|
@ -102,38 +131,38 @@ public class Pluie.Yaml.Config
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private void import_files (Yaml.NodeRoot root)
|
||||
private void import_files (Yaml.Node root)
|
||||
{
|
||||
Yaml.NodeMap? sub = null;
|
||||
Yaml.NodeMap? n = null;
|
||||
Yaml.Node? sub = null;
|
||||
Yaml.Node? n = null;
|
||||
Yaml.Config? conf = null;
|
||||
foreach(var entry in this.paths.entries) {
|
||||
conf = new Yaml.Config(entry.value, this.displayFile);
|
||||
sub = conf.loader.get_nodes ();
|
||||
n = new Yaml.NodeMap (root, entry.key);
|
||||
foreach(var subnode in sub.map.values) {
|
||||
n = new Yaml.Mapping (root, entry.key);
|
||||
foreach(var subnode in sub.list) {
|
||||
subnode.parent = null;
|
||||
n.add(subnode);
|
||||
}
|
||||
root.add (n);
|
||||
//~ root.add (n);
|
||||
}
|
||||
root.update_level();
|
||||
//~ root.update_level();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void update_var (Yaml.NodeMap node, string path)
|
||||
private void update_var (Yaml.Node node, string path)
|
||||
{
|
||||
this.varmap.set ("path", path);
|
||||
string? file = null;
|
||||
foreach (var entry in node.map.entries) {
|
||||
if (entry.key[0] != IMPORTS_SPE) {
|
||||
var val = entry.value.val ();
|
||||
foreach (var child in node.list) {
|
||||
if (child.name[0] != IMPORTS_SPE) {
|
||||
var val = child.first().data;
|
||||
if (!Path.is_absolute (val)) {
|
||||
val = Path.build_filename(path, val);
|
||||
}
|
||||
this.resolve_var (entry.key, val);
|
||||
this.resolve_var (child.name, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -154,13 +183,13 @@ public class Pluie.Yaml.Config
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private void get_imports_var (Yaml.NodeMap node)
|
||||
private void get_imports_var (Yaml.Node node)
|
||||
{
|
||||
this.varmap = new Gee.HashMap<string, string> ();
|
||||
this.paths = new Gee.HashMap<string, string> ();
|
||||
foreach (var entry in node.map.entries) {
|
||||
if (entry.key[0] == IMPORTS_SPE) {
|
||||
this.varmap.set (entry.key.substring (1), entry.value.val ());
|
||||
foreach (var child in node.list) {
|
||||
if (child.name[0] == IMPORTS_SPE) {
|
||||
this.varmap.set (child.name.substring (1), child.first().data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||
* @version : 0.3
|
||||
* @version : 0.4
|
||||
* @date : 2018
|
||||
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
|
||||
* @author : a-Sansara <[dev]at[pluie]dot[org]>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||
* @version : 0.3
|
||||
* @version : 0.4
|
||||
* @date : 2018
|
||||
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
|
||||
* @author : a-Sansara <[dev]at[pluie]dot[org]>
|
||||
|
@ -69,28 +69,31 @@ public class Pluie.Yaml.Finder : Object
|
|||
string search = this.find_path (path);
|
||||
bool match = false;
|
||||
Yaml.Node? node = context == null ? this.context : context;
|
||||
Yaml.Mapping? m = null;
|
||||
Regex reg = /(\[|\{)([^\]\}]*)(\]|\})/;
|
||||
MatchInfo mi;
|
||||
try {
|
||||
//~ of.echo ("find node %s".printf (path));
|
||||
//~ of.echo ("search %s".printf (search));
|
||||
//of.echo ("find node %s".printf (path));
|
||||
// of.echo ("search %s".printf (search));
|
||||
for (reg.match (search, 0, out mi) ; mi.matches () ; mi.next ()) {
|
||||
//~ of.echo ("=> %s%s%s".printf (mi.fetch (1), mi.fetch (2), mi.fetch (3)));
|
||||
// of.echo ("=> %s%s%s".printf (mi.fetch (1), mi.fetch (2), mi.fetch (3)));
|
||||
if (this.is_collection_path (mi)) {
|
||||
if (!match) match = true;
|
||||
if (this.is_collection_path (mi, true)) {
|
||||
node = (node as Yaml.NodeMap).map[mi.fetch (FIND_COLLECTION.KEY)];
|
||||
var n = node as Yaml.Mapping;
|
||||
if (n !=null && !n.empty ()) {
|
||||
node = n.item (mi.fetch (FIND_COLLECTION.KEY));
|
||||
}
|
||||
}
|
||||
else {
|
||||
int index = int.parse (mi.fetch (FIND_COLLECTION.KEY));
|
||||
if (index == 0 && node.node_type.is_single_pair ()) {
|
||||
var n = node as Yaml.NodeSinglePair;
|
||||
node = n.scalar ();
|
||||
if (index == 0 && !node.empty() && node.first().ntype.is_scalar ()) {
|
||||
node = node.first ();
|
||||
}
|
||||
// assume sequence
|
||||
else {
|
||||
var n = node as Yaml.NodeSequence;
|
||||
if (index < n.list.size && index >= 0) {
|
||||
var n = node as Yaml.Sequence;
|
||||
if (n != null && !n.empty () && index >= 0 && index < n.count ()) {
|
||||
node = n.list.get (index);
|
||||
}
|
||||
else node = null;
|
||||
|
@ -118,7 +121,7 @@ public class Pluie.Yaml.Finder : Object
|
|||
{
|
||||
MatchInfo? mi = null;
|
||||
string search = "";
|
||||
if (BaseNode.mode.is_dot ()) {
|
||||
if (Yaml.MODE.is_dot ()) {
|
||||
var stk = /([^.]*)\./.split (path);
|
||||
foreach (var s in stk) {
|
||||
if (s.strip() != "") {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||
* @version : 0.3
|
||||
* @version : 0.4
|
||||
* @date : 2018
|
||||
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
|
||||
* @author : a-Sansara <[dev]at[pluie]dot[org]>
|
||||
|
@ -79,7 +79,7 @@ public class Pluie.Yaml.Loader
|
|||
/**
|
||||
* return resulting Yaml root node
|
||||
*/
|
||||
public Yaml.NodeRoot? get_nodes ()
|
||||
public Yaml.Node? get_nodes ()
|
||||
{
|
||||
return this.scanner.get_nodes ();
|
||||
}
|
||||
|
|
146
src/vala/Pluie/Yaml.Mapping.vala
Normal file
146
src/vala/Pluie/Yaml.Mapping.vala
Normal file
|
@ -0,0 +1,146 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @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.Mapping : Yaml.Node
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
Gee.ArrayList<string>? keys { internal get; internal set; default = null; }
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Mapping (Yaml.Node? parent = null, string? name = null)
|
||||
{
|
||||
base (parent, NODE_TYPE.MAPPING, name);
|
||||
this.keys = new ArrayList<string> ();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Mapping.with_scalar (Yaml.Node? parent = null, string? name = null, string? data = null)
|
||||
{
|
||||
base (parent, NODE_TYPE.MAPPING, name);
|
||||
var s = new Scalar (null, data);
|
||||
this.add (s);
|
||||
}
|
||||
|
||||
/**
|
||||
* add a child node to current collection (mapping or sequence) node
|
||||
* @param child the Yaml.Node child to add
|
||||
*/
|
||||
protected override void before_add (Yaml.Node child) throws Yaml.AddNodeError
|
||||
{
|
||||
if (!this.empty ()) {
|
||||
if (this.first().ntype.is_scalar ()) {
|
||||
var msg = "can't add child %s to %s (mapping is single pair)".printf (child.uuid[0:8], this.name);
|
||||
throw new Yaml.AddNodeError.MAPPING_IS_SINGLE_PAIR (msg);
|
||||
}
|
||||
else if (child.ntype.is_scalar ()) {
|
||||
var msg = "can't add scalar %s to %s (mapping not single pair)".printf (child.uuid[0:8], this.name);
|
||||
throw new Yaml.AddNodeError.MAPPING_NOT_SINGLE_PAIR (msg);
|
||||
}
|
||||
else if (this.keys != null && this.keys.contains(child.name)) {
|
||||
var msg = "can't add %s to %s (mapping already contains key)".printf (child.name, this.name);
|
||||
throw new Yaml.AddNodeError.MAPPING_CONTAINS_CHILD (msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add a child node to current collection (mapping or sequence) node
|
||||
* @param child the Yaml.Node child to add
|
||||
*/
|
||||
protected override void on_added (Yaml.Node child)
|
||||
{
|
||||
base.on_added (child);
|
||||
if (this.keys != null) {
|
||||
this.keys.add(child.name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add a child node to current collection (mapping or sequence) node
|
||||
* @param child the Yaml.Node child to add
|
||||
*/
|
||||
protected override void on_removed (Yaml.Node child, bool levelUpdate = true)
|
||||
{
|
||||
base.on_removed (child, levelUpdate);
|
||||
if (!this.empty () && this.keys.contains(child.name)) {
|
||||
this.keys.remove(child.name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* retriew a child node throught specifiyed index
|
||||
* @param index index of searched child
|
||||
* @return the child node
|
||||
*/
|
||||
public new Yaml.Node? item (string name)
|
||||
{
|
||||
Yaml.Node? child = null;
|
||||
if (!this.empty ()) {
|
||||
int i = this.keys.index_of (name);
|
||||
if (i >= 0 && i < this.count ()) {
|
||||
child = this.list.get (i);
|
||||
}
|
||||
}
|
||||
return child;
|
||||
}
|
||||
|
||||
/**
|
||||
* clone current node
|
||||
* @param the name of clone
|
||||
*/
|
||||
public override Yaml.Node clone_node (string? name = null)
|
||||
{
|
||||
var key = name != null ? name : this.name;
|
||||
Yaml.Mapping clone = new Yaml.Mapping (null, key);
|
||||
if (!this.empty()) {
|
||||
foreach (Yaml.Node child in this.list) {
|
||||
clone.add(child.clone_node());
|
||||
}
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
||||
public Gee.ArrayList<string>? child_names ()
|
||||
{
|
||||
return this.keys;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||
* @version : 0.3
|
||||
* @version : 0.4
|
||||
* @date : 2018
|
||||
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
|
||||
* @author : a-Sansara <[dev]at[pluie]dot[org]>
|
||||
|
@ -28,111 +28,273 @@
|
|||
*/
|
||||
|
||||
using GLib;
|
||||
using Pluie;
|
||||
using Gee;
|
||||
|
||||
public interface Pluie.Yaml.Node : Object, Yaml.NodeCollection
|
||||
/**
|
||||
* a class representing a mapping node
|
||||
*/
|
||||
public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
|
||||
{
|
||||
/**
|
||||
* universal unique identifier
|
||||
* sequence collection for Yaml.NodeSequence node
|
||||
*/
|
||||
public abstract string uuid { get; internal set; }
|
||||
public ArrayList<Yaml.Node> list { get; internal set; }
|
||||
|
||||
bool container { get; internal set; default = true; }
|
||||
|
||||
/**
|
||||
* node type related to Yaml.NODE_TYPE
|
||||
* default Yaml.Node constructor
|
||||
* @param parent the parent node
|
||||
* @param type the NODE_TYPE of Yaml.Node to create
|
||||
*/
|
||||
public abstract Yaml.NODE_TYPE node_type { get; internal set; }
|
||||
public Node (Yaml.Node? parent = null, Yaml.NODE_TYPE type = Yaml.NODE_TYPE.UNDEFINED, string? name = null)
|
||||
{
|
||||
|
||||
public abstract int level { get; internal set; }
|
||||
|
||||
/**
|
||||
* parent node
|
||||
*/
|
||||
public abstract Yaml.Node? parent { get; internal set; }
|
||||
|
||||
/**
|
||||
* current node data for Yaml.NodeScalar node
|
||||
*/
|
||||
public abstract string? data { get; internal set; default = null; }
|
||||
|
||||
/**
|
||||
* current node name (key)
|
||||
*/
|
||||
public abstract string? name { get; internal set; default = null; }
|
||||
|
||||
/**
|
||||
* test if specifiyed node is current node
|
||||
* @param child the Yaml.Node node to test
|
||||
*/
|
||||
public abstract bool same_node (Yaml.Node? node);
|
||||
base (parent, type, name);
|
||||
this.list = new ArrayList<Yaml.Node> ();
|
||||
}
|
||||
|
||||
/**
|
||||
* add a child node to current collection (mapping or sequence) node
|
||||
* @param child the Yaml.Node child to add
|
||||
*/
|
||||
public abstract bool add (Yaml.Node node);
|
||||
public virtual bool add (Yaml.AbstractChild node)
|
||||
{
|
||||
bool done = false;
|
||||
try {
|
||||
var child = node as Yaml.Node;
|
||||
if (this.container && child != null) {
|
||||
child.on_change_parent (false);
|
||||
child.level = this.level + 1;
|
||||
child.parent = this;
|
||||
this.before_add (child);
|
||||
if ((done = this.list.add (child))) {
|
||||
this.on_added (child);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Yaml.AddNodeError e) {
|
||||
of.warn (e.message);
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
/**
|
||||
* add a child node to current collection (mapping or sequence) node
|
||||
* @param child the Yaml.Node child to add
|
||||
*/
|
||||
public abstract string? val ();
|
||||
protected virtual void before_add (Yaml.Node child) throws Yaml.AddNodeError
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* stuff on changing parent node
|
||||
* @param child the childto add
|
||||
* add a child node to current collection (mapping or sequence) node
|
||||
* @param child the Yaml.Node child to add
|
||||
*/
|
||||
protected abstract bool on_change_parent ();
|
||||
protected virtual void on_added (Yaml.Node child)
|
||||
{
|
||||
this.update_level ();
|
||||
}
|
||||
|
||||
/**
|
||||
* remove a child
|
||||
* @param child the child to remove
|
||||
*/
|
||||
protected abstract bool remove_child (Yaml.Node child);
|
||||
public bool remove_child (Yaml.Node child, bool levelUpdate = true)
|
||||
{
|
||||
bool done = false;
|
||||
if (this.container && !this.empty() && this.list.contains (child)) {
|
||||
if ((done = this.list.remove (child))) {
|
||||
this.on_removed (child, levelUpdate);
|
||||
}
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
/**
|
||||
* clone curent node
|
||||
* @param name the name of clone node
|
||||
* add a child node to current collection (mapping or sequence) node
|
||||
* @param child the Yaml.Node child to add
|
||||
*/
|
||||
public abstract Yaml.Node clone_node (string? name = null);
|
||||
protected virtual void on_removed (Yaml.Node child, bool levelUpdate = true)
|
||||
{
|
||||
if (levelUpdate) {
|
||||
child.level = 0;
|
||||
child.update_level ();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check if node has child nodes
|
||||
* retriew a child node throught specifiyed index
|
||||
* @param index index of searched child
|
||||
* @return the child node
|
||||
*/
|
||||
public abstract bool has_child_nodes ();
|
||||
public virtual Yaml.Node? item (int index)
|
||||
{
|
||||
return this.list.get (index);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if first chikd
|
||||
* check if current node contains the specifiyed child node
|
||||
* @param child
|
||||
*/
|
||||
public abstract bool is_first_child ();
|
||||
public bool contains (Yaml.Node child) {
|
||||
return !this.empty () && this.list.contains (child);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if last chikd
|
||||
* count childnodes
|
||||
*/
|
||||
public abstract bool is_last_child ();
|
||||
public int count () {
|
||||
return !this.empty () ? this.list.size : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* give the next sibling node
|
||||
* check if empty
|
||||
*/
|
||||
public abstract Yaml.Node? next_sibling ();
|
||||
public bool empty () {
|
||||
return this.list == null || this.list.size == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* give the previous sibling node
|
||||
* get an iterator
|
||||
*/
|
||||
public abstract Yaml.Node? previous_sibling ();
|
||||
public Gee.Iterator<Yaml.Node> iterator () {
|
||||
return this.list.iterator ();
|
||||
}
|
||||
|
||||
/**
|
||||
* give the root parent node
|
||||
* retriew the first child node
|
||||
* @return the first child node
|
||||
*/
|
||||
public abstract Yaml.Node? get_root_node ();
|
||||
public virtual Yaml.Node? first ()
|
||||
{
|
||||
return this.list.first ();
|
||||
}
|
||||
|
||||
/**
|
||||
* update node level and all childs level
|
||||
* retriew the last child node
|
||||
* @return the last child node
|
||||
*/
|
||||
public abstract void update_level ();
|
||||
public Yaml.Node? last ()
|
||||
{
|
||||
return this.list.last ();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Yaml.Node? child_sibling (Yaml.Node child, bool forward)
|
||||
{
|
||||
Yaml.Node? node = null;
|
||||
if (!this.empty () && this.list.contains (child)) {
|
||||
int index = this.list.index_of (child) + (forward ? 1 : -1);
|
||||
if (index >= 0 && index < this.count ()) {
|
||||
node = this.list.get(index);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Yaml.Node? child_next_sibling (Yaml.Node child)
|
||||
{
|
||||
return this.child_sibling (child, true);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Yaml.Node? child_previous_sibling (Yaml.Node child)
|
||||
{
|
||||
return this.child_sibling (child, false);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public virtual void update_level()
|
||||
{
|
||||
this.level = this.parent != null ? this.parent.level + 1 : 0;
|
||||
if (!this.empty ()) {
|
||||
foreach (var child in this.list) {
|
||||
if (child != null) child.update_level ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* clone current node
|
||||
* @param the name of clone
|
||||
*/
|
||||
public virtual Yaml.Node clone_node (string? name = null)
|
||||
{
|
||||
var key = name != null ? name : this.name;
|
||||
Yaml.Node clone = this.get_cloned_instance (key);
|
||||
if (!this.empty()) {
|
||||
foreach (Yaml.Node child in this.list) {
|
||||
clone.add(child.clone_node(null));
|
||||
}
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
||||
/**
|
||||
* clone current node
|
||||
* @param the name of clone
|
||||
*/
|
||||
public virtual Yaml.Node get_cloned_instance (string? name = null)
|
||||
{
|
||||
return new Yaml.Node (null, this.ntype, name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* display childs
|
||||
*/
|
||||
public void display_childs (bool withTitle = true)
|
||||
{
|
||||
if (withTitle) {
|
||||
of.action ("display_childs", this.name);
|
||||
}
|
||||
of.echo (this.to_string ());
|
||||
if (!this.empty ()) {
|
||||
foreach (Yaml.Node child in this.list) {
|
||||
child.display_childs (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get a presentation string of current Yaml.Node
|
||||
*/
|
||||
public abstract string to_string (bool indentFormat = true, bool withParent = false, bool withUuid = false, bool withIndent = true, bool withRefCount = false);
|
||||
|
||||
public 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 (
|
||||
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 (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
|
||||
? ""
|
||||
: of.c (ECHO.SECTION).s (" "+this.parent.name)+(
|
||||
withLevel ? of.c (ECHO.NUM).s (" %d".printf (this.level)) : " "
|
||||
),
|
||||
of.c (ECHO.OPTION_SEP).s (" %s".printf(
|
||||
!this.ntype.is_mapping () || this.count () >= 1 && !this.first().ntype.is_scalar () ? this.ntype.infos () : NODE_TYPE.SINGLE_PAIR.infos ()
|
||||
)),
|
||||
withCount ? of.c (ECHO.MICROTIME).s (" %d".printf(this.count ())) : "",
|
||||
withUuid ? of.c (ECHO.COMMENT).s (" %s".printf(this.uuid[0:8]+"...")) : "",
|
||||
//~ of.c (ECHO.NUM).s ("%d".printf (this.level)),
|
||||
of.c (ECHO.OPTION).s ("]")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,227 +0,0 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||
* @version : 0.3
|
||||
* @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.NodeMap : Yaml.BaseNode, Yaml.NodeCollection
|
||||
{
|
||||
/**
|
||||
* map collection for Yaml.NodeMap node
|
||||
*/
|
||||
public Gee.HashMap<string, Yaml.Node> map { get; internal set; }
|
||||
|
||||
private Gee.ArrayList<string> keys { get; internal set; }
|
||||
|
||||
/**
|
||||
* construct a mapping node
|
||||
* @param parent the parent node
|
||||
* @param name the current name (key) of mapping node
|
||||
*/
|
||||
public NodeMap (Yaml.Node? parent = null, string? name = null)
|
||||
{
|
||||
base (parent, NODE_TYPE.MAPPING);
|
||||
this.map = new HashMap<string, Yaml.Node> ();
|
||||
this.keys = new ArrayList<string> ();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* remove a child
|
||||
* @param child the child to remove
|
||||
*/
|
||||
protected override bool remove_child (Yaml.Node child)
|
||||
{
|
||||
bool done = true;
|
||||
if (this.map != null && this.map.has_key (child.name)) {
|
||||
done = this.map.unset(child.name);
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
/**
|
||||
* add a child node to current collection (mapping or sequence) node
|
||||
* @param child the Yaml.Node child to add
|
||||
*/
|
||||
public override bool add (Yaml.Node node)
|
||||
{
|
||||
node.on_change_parent ();
|
||||
node.level = this.level + 1;
|
||||
node.parent = this;
|
||||
if (this.keys == null) {
|
||||
this.keys = new ArrayList<string> ();
|
||||
}
|
||||
if (this.keys.contains(node.name)) {
|
||||
this.keys.remove(node.name);
|
||||
}
|
||||
this.keys.add(node.name);
|
||||
if (this.map == null) {
|
||||
this.map = new HashMap<string, Yaml.Node> ();
|
||||
}
|
||||
this.map.set (node.name, node);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* display childs
|
||||
*/
|
||||
public void display_childs (bool root=true)
|
||||
{
|
||||
if (root == true) {
|
||||
of.action ("display childs\n");
|
||||
}
|
||||
of.echo (this.to_string ());
|
||||
if (this.keys != null && this.keys.size > 0) {
|
||||
foreach (string key in this.keys) {
|
||||
var n = this.map.get(key);
|
||||
if (n.node_type.is_mapping ()) (n as Yaml.NodeMap).display_childs (false);
|
||||
else if (n.node_type.is_sequence ()) (n as Yaml.NodeSequence).display_childs (false);
|
||||
else if (n.node_type.is_single_pair ()) {
|
||||
of.echo (n.to_string ());
|
||||
of.echo ((n as Yaml.NodeSinglePair).scalar ().to_string ());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
of.echo (of.s_indent ()+"node has no childs");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* count childnodes
|
||||
*/
|
||||
public int get_size () {
|
||||
return this.keys.size;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if current node contains the specifiyed child node
|
||||
* @param child
|
||||
*/
|
||||
public override bool contains (Yaml.Node child) {
|
||||
bool has = false;
|
||||
foreach (Yaml.Node entry in map.values) {
|
||||
if (child.uuid == entry.uuid) {
|
||||
has = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return has;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public bool is_last (Yaml.Node child) {
|
||||
return this.keys.last() == child.name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public bool is_first (Yaml.Node child) {
|
||||
return this.keys.first() == child.name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private string? next_key (string skey)
|
||||
{
|
||||
string? mkey = this.keys.last() != skey ? this.keys.get (this.keys.index_of (skey)+1) : null;
|
||||
return mkey;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private string? previous_key (string skey)
|
||||
{
|
||||
string? mkey = this.keys.first() != skey ? this.keys.get (this.keys.index_of (skey)-1) : null;
|
||||
return mkey;
|
||||
}
|
||||
|
||||
/**
|
||||
* retriew the next sibling of specifiyed child node
|
||||
* @param child
|
||||
*/
|
||||
public virtual Yaml.Node? child_next_sibling (Yaml.Node child)
|
||||
{
|
||||
var key = this.next_key (child.name);
|
||||
var target = key != null ? this.map[key] : null;
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* retriew the next sibling of specifiyed child node
|
||||
* @param child
|
||||
*/
|
||||
public virtual Yaml.Node? child_previous_sibling (Yaml.Node child)
|
||||
{
|
||||
var key = this.previous_key (child.name);
|
||||
var target = key != null ? this.map[key] : null;
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public override Yaml.Node? first_child ()
|
||||
{
|
||||
return this.map[this.keys.first()];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public override Yaml.Node? last_child ()
|
||||
{
|
||||
return this.map[this.keys.last()];
|
||||
}
|
||||
|
||||
/**
|
||||
* clone current node
|
||||
* @param the name of clone
|
||||
*/
|
||||
public override Yaml.Node clone_node (string? name = null)
|
||||
{
|
||||
var key = name != null ? name : this.name;
|
||||
Yaml.Node clone = new Yaml.NodeMap (this.parent, key);
|
||||
foreach (string k in this.map.keys) {
|
||||
var n = this.map.get(k).clone_node();
|
||||
n.parent = clone;
|
||||
clone.add(n);
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
}
|
|
@ -1,230 +0,0 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||
* @version : 0.3
|
||||
* @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 Pluie;
|
||||
using Gee;
|
||||
|
||||
/**
|
||||
* a class representing a sequence node
|
||||
*/
|
||||
public class Pluie.Yaml.NodeSequence : Yaml.BaseNode, Yaml.NodeCollection
|
||||
{
|
||||
|
||||
/**
|
||||
* sequence collection for Yaml.NodeSequence node
|
||||
*/
|
||||
public ArrayList<Yaml.Node> list { get; internal set; }
|
||||
|
||||
/**
|
||||
* construct a sequence node
|
||||
* @param parent the parent node
|
||||
* @param name the current name (key) of sequence node
|
||||
*/
|
||||
public NodeSequence (Yaml.Node? parent = null, string? name = null)
|
||||
{
|
||||
base (parent, NODE_TYPE.SEQUENCE);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* remove a child
|
||||
* @param child the child to remove
|
||||
*/
|
||||
protected override bool remove_child (Yaml.Node child)
|
||||
{
|
||||
bool done = true;
|
||||
if (this.list.contains (child)) {
|
||||
done = this.list.remove (child);
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
/**
|
||||
* add a child node to current collection (mapping or sequence) node
|
||||
* @param child the Yaml.Node child to add
|
||||
*/
|
||||
public override bool add (Yaml.Node node)
|
||||
{
|
||||
if (this.list == null) {
|
||||
this.list = new ArrayList<Yaml.Node> ();
|
||||
}
|
||||
node.on_change_parent ();
|
||||
node.level = this.level + 1;
|
||||
node.parent = this;
|
||||
return this.list.add (node);
|
||||
}
|
||||
|
||||
/**
|
||||
* add a child Yaml.NodeScalar containing specifiyed data
|
||||
* @param data the scalar data
|
||||
* @return the scalar node
|
||||
*/
|
||||
public Yaml.Node add_scalar (string? data = null)
|
||||
{
|
||||
Yaml.Node scalar = new Yaml.NodeScalar (this, data);
|
||||
this.add (scalar);
|
||||
return scalar;
|
||||
}
|
||||
|
||||
/**
|
||||
* retriew a child node throught specifiyed index
|
||||
* @param index index of searched child
|
||||
* @return the child node
|
||||
*/
|
||||
public Yaml.Node item (int index)
|
||||
{
|
||||
return this.list.get (index);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public new bool is_last (Yaml.Node child) {
|
||||
return child.same_node(this.last_child());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public new bool is_first (Yaml.Node child) {
|
||||
return child.same_node(this.first_child());
|
||||
}
|
||||
|
||||
/**
|
||||
* count childnodes
|
||||
*/
|
||||
public new int get_size () {
|
||||
return this.list == null ? 0 : this.list.size;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if current node contains the specifiyed child node
|
||||
* @param child
|
||||
*/
|
||||
public override bool contains (Yaml.Node child) {
|
||||
return this.list.contains (child);
|
||||
}
|
||||
|
||||
/**
|
||||
* retriew the first child node
|
||||
* @return the first child node
|
||||
*/
|
||||
public override Yaml.Node? first_child ()
|
||||
{
|
||||
return this.list.first ();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* retriew the last child node
|
||||
* @return the last child node
|
||||
*/
|
||||
public override Yaml.Node? last_child ()
|
||||
{
|
||||
return this.list.last ();
|
||||
}
|
||||
|
||||
/**
|
||||
* display childs
|
||||
*/
|
||||
public void display_childs (bool root = true)
|
||||
{
|
||||
if (root) {
|
||||
of.action ("display_childs sequence\n");
|
||||
}
|
||||
of.echo (this.to_string ());
|
||||
if (this.list!= null && this.list.size > 0) {
|
||||
foreach (Yaml.Node child in this.list) {
|
||||
if (child.node_type.is_mapping ()) (child as Yaml.NodeMap).display_childs (false);
|
||||
else if (child.node_type.is_sequence ()) (child as Yaml.NodeSequence).display_childs (false);
|
||||
else if (child.node_type.is_single_pair ()) {
|
||||
of.echo (child.to_string ());
|
||||
of.echo ((child as Yaml.NodeSinglePair).scalar ().to_string ());
|
||||
}
|
||||
else {
|
||||
of.echo (child.to_string ());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
of.echo (of.s_indent ()+"node has no childs");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* retriew the next sibling of specifiyed child node
|
||||
* @param child
|
||||
*/
|
||||
public Yaml.Node? child_next_sibling (Yaml.Node child)
|
||||
{
|
||||
Yaml.Node? target = null;
|
||||
if (this.list.size > 0 && this.list.contains (child)) {
|
||||
int index = this.list.index_of (child);
|
||||
target = this.list.get(index+1);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* retriew the previous sibling of specifiyed child node
|
||||
* @param child
|
||||
*/
|
||||
public Yaml.Node? child_previous_sibling (Yaml.Node child)
|
||||
{
|
||||
Yaml.Node? target = null;
|
||||
if (this.list.size > 0 && this.list.contains (child)) {
|
||||
int index = this.list.index_of (child);
|
||||
if (index > 0) {
|
||||
target = this.list.get(index-1);
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* clone current node
|
||||
* @param the name of clone
|
||||
*/
|
||||
public override Yaml.Node clone_node (string? name = null)
|
||||
{
|
||||
var key = name != null ? name : this.name;
|
||||
Yaml.Node clone = new Yaml.NodeSequence (this.parent, key);
|
||||
if (this.list!= null && this.list.size > 0) {
|
||||
foreach (Yaml.Node child in this.list) {
|
||||
var n = child.clone_node();
|
||||
n.parent = clone;
|
||||
clone.add(n);
|
||||
}
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||
* @version : 0.3
|
||||
* @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 Pluie;
|
||||
|
||||
/**
|
||||
* a class representing a single/pair mapping node
|
||||
*/
|
||||
public class Pluie.Yaml.NodeSinglePair : Yaml.NodeMap
|
||||
{
|
||||
/**
|
||||
* construct a single/pair mapping node
|
||||
* @param parent the parent node
|
||||
* @param name the current name (key) of sequence node
|
||||
* @param data the current scalar data
|
||||
*/
|
||||
public NodeSinglePair (Yaml.Node? parent = null, string? name = null, string? data = null)
|
||||
{
|
||||
this.standard (parent, NODE_TYPE.SINGLE_PAIR);
|
||||
this.name = name;
|
||||
if (data != null) {
|
||||
var scalar = new Yaml.NodeScalar (this, data);
|
||||
scalar.name = "singlepair";
|
||||
this.add (scalar);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get child scalar node
|
||||
* @return the scalar node
|
||||
*/
|
||||
public Yaml.Node? scalar ()
|
||||
{
|
||||
return this.map["singlepair"];
|
||||
}
|
||||
|
||||
/**
|
||||
* clone current node
|
||||
* @param the name of clone
|
||||
*/
|
||||
public override Yaml.Node clone_node (string? name = null)
|
||||
{
|
||||
var key = name != null ? name : this.name;
|
||||
Yaml.Node clone = new Yaml.NodeSinglePair (this.parent, key, this.scalar ().data);
|
||||
return clone;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||
* @version : 0.3
|
||||
* @version : 0.4
|
||||
* @date : 2018
|
||||
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
|
||||
* @author : a-Sansara <[dev]at[pluie]dot[org]>
|
||||
|
@ -190,7 +190,8 @@ public class Pluie.Yaml.Processor
|
|||
*/
|
||||
private void reset ()
|
||||
{
|
||||
this.root = new Yaml.NodeRoot ();
|
||||
this.root = new Yaml.Mapping (null, "PluieYamlRoot");
|
||||
this.root.ntype = Yaml.NODE_TYPE.ROOT;
|
||||
this.prev_node = this.root;
|
||||
this.parent_node = this.root;
|
||||
this.iterator = this.events.iterator ();
|
||||
|
@ -302,12 +303,12 @@ public class Pluie.Yaml.Processor
|
|||
{
|
||||
if (!entry) {
|
||||
if (this.ckey != null) {
|
||||
this.node = new Yaml.NodeSinglePair (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"]);
|
||||
this.change = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.node = new Yaml.NodeScalar (this.parent_node, this.event.data["data"]);
|
||||
this.node = new Yaml.Scalar (this.parent_node, this.event.data["data"]);
|
||||
this.change = true;
|
||||
}
|
||||
}
|
||||
|
@ -340,7 +341,7 @@ public class Pluie.Yaml.Processor
|
|||
*/
|
||||
private void on_sequence_start ()
|
||||
{
|
||||
this.node = new Yaml.NodeSequence (this.parent_node, this.ckey);
|
||||
this.node = new Yaml.Sequence (this.parent_node, this.ckey);
|
||||
this.change = true;
|
||||
this.beginFlowSeq = true;
|
||||
}
|
||||
|
@ -363,9 +364,9 @@ public class Pluie.Yaml.Processor
|
|||
private void create_mapping (bool entry = false)
|
||||
{
|
||||
if (entry) {
|
||||
this.ckey = "_%d".printf((this.parent_node as Yaml.NodeSequence).get_size());
|
||||
this.ckey = "_%d".printf(this.parent_node.count());
|
||||
}
|
||||
this.node = new Yaml.NodeMap (this.parent_node, this.ckey);
|
||||
this.node = new Yaml.Mapping (this.parent_node, this.ckey);
|
||||
this.change = true;
|
||||
}
|
||||
|
||||
|
@ -388,10 +389,12 @@ public class Pluie.Yaml.Processor
|
|||
private void on_update ()
|
||||
{
|
||||
if (this.change) {
|
||||
this.parent_node.add (this.node);
|
||||
if (this.node.node_type.is_collection ()) {
|
||||
if (this.node.ntype.is_collection () && (this.node.empty() || (!this.node.first().ntype.is_scalar ()))) {
|
||||
this.parent_node = this.node;
|
||||
}
|
||||
else {
|
||||
this.parent_node = this.node.parent;
|
||||
}
|
||||
this.prev_node = this.node;
|
||||
this.node = null;
|
||||
this.change = false;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||
* @version : 0.3
|
||||
* @version : 0.4
|
||||
* @date : 2018
|
||||
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
|
||||
* @author : a-Sansara <[dev]at[pluie]dot[org]>
|
||||
|
@ -27,19 +27,24 @@
|
|||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*/
|
||||
|
||||
using GLib;
|
||||
using Pluie;
|
||||
using Gee;
|
||||
|
||||
/**
|
||||
* a class representing a scalar node
|
||||
* a class representing a mapping node
|
||||
*/
|
||||
public class Pluie.Yaml.NodeScalar : Yaml.BaseNode
|
||||
public class Pluie.Yaml.Scalar : Yaml.Node
|
||||
{
|
||||
|
||||
bool container { get; internal set; default = false; }
|
||||
|
||||
/**
|
||||
* construct a scalar node
|
||||
* default Yaml.Node constructor
|
||||
* @param parent the parent node
|
||||
* @param data the current scalar data
|
||||
* @param type the NODE_TYPE of Yaml.Node to create
|
||||
*/
|
||||
public NodeScalar (Yaml.Node? parent = null, string? data = null)
|
||||
public Scalar (Yaml.Node ? parent = null, string? data = null)
|
||||
{
|
||||
base (parent, NODE_TYPE.SCALAR);
|
||||
this.data = data;
|
||||
|
@ -51,6 +56,8 @@ public class Pluie.Yaml.NodeScalar : Yaml.BaseNode
|
|||
*/
|
||||
public override Yaml.Node clone_node (string? name = null)
|
||||
{
|
||||
return new Yaml.NodeScalar (this.parent, this.data);
|
||||
Yaml.Scalar clone = new Yaml.Scalar (null, this.data);
|
||||
return clone;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||
* @version : 0.3
|
||||
* @version : 0.4
|
||||
* @date : 2018
|
||||
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
|
||||
* @author : a-Sansara <[dev]at[pluie]dot[org]>
|
||||
|
@ -120,9 +120,9 @@ public class Pluie.Yaml.Scanner
|
|||
/**
|
||||
* return resulting Yaml root node
|
||||
*/
|
||||
public Yaml.NodeRoot? get_nodes ()
|
||||
public Yaml.Node? get_nodes ()
|
||||
{
|
||||
return (this.processor.root as Yaml.NodeRoot);
|
||||
return this.processor.root;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||
* @version : 0.3
|
||||
* @version : 0.4
|
||||
* @date : 2018
|
||||
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
|
||||
* @author : a-Sansara <[dev]at[pluie]dot[org]>
|
||||
|
@ -27,22 +27,24 @@
|
|||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*/
|
||||
|
||||
using GLib;
|
||||
using Pluie;
|
||||
using Gee;
|
||||
|
||||
/**
|
||||
* a class representing a single/pair mapping node
|
||||
* a class representing a mapping node
|
||||
*/
|
||||
public class Pluie.Yaml.NodeRoot : Yaml.NodeMap
|
||||
public class Pluie.Yaml.Sequence : Yaml.Node
|
||||
{
|
||||
|
||||
/**
|
||||
* construct a single/pair mapping node
|
||||
* default Yaml.Node constructor
|
||||
* @param parent the parent node
|
||||
* @param name the current name (key) of sequence node
|
||||
* @param data the current scalar data
|
||||
* @param type the NODE_TYPE of Yaml.Node to create
|
||||
*/
|
||||
public NodeRoot (Yaml.Node? parent = null, string? name = null, string? data = null)
|
||||
public Sequence (Yaml.Node? parent = null, string? name = null)
|
||||
{
|
||||
this.standard (null, NODE_TYPE.ROOT);
|
||||
this.name = "PluieYamlRootNode";
|
||||
base (parent, NODE_TYPE.SEQUENCE, name);
|
||||
this.list = new ArrayList<Yaml.Node> ();
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
|
||||
* @version : 0.3
|
||||
* @version : 0.4
|
||||
* @date : 2018
|
||||
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
|
||||
* @author : a-Sansara <[dev]at[pluie]dot[org]>
|
||||
|
@ -31,6 +31,23 @@ namespace Pluie
|
|||
{
|
||||
namespace Yaml
|
||||
{
|
||||
public static bool DBG_SHOW_INDENT = true;
|
||||
public static bool DBG_SHOW_PARENT = true;
|
||||
public static bool DBG_SHOW_UUID = true;
|
||||
public static bool DBG_SHOW_LEVEL = true;
|
||||
public static bool DBG_SHOW_REF = true;
|
||||
public static bool DBG_SHOW_COUNT = true;
|
||||
|
||||
/**
|
||||
* ParseError
|
||||
*/
|
||||
public errordomain AddNodeError
|
||||
{
|
||||
MAPPING_CONTAINS_CHILD,
|
||||
MAPPING_IS_SINGLE_PAIR,
|
||||
MAPPING_NOT_SINGLE_PAIR
|
||||
}
|
||||
|
||||
/**
|
||||
* haxadecimal sequence
|
||||
*/
|
||||
|
@ -190,6 +207,8 @@ namespace Pluie
|
|||
}
|
||||
}
|
||||
|
||||
public static FIND_MODE MODE = FIND_MODE.DOT;
|
||||
|
||||
/**
|
||||
* enum MatchInfo keys of Yaml.Mode.find method related to mode FIND_MODE.SQUARE_BRACKETS of Yaml.Node
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue
Block a user