Compare commits

...

54 Commits
0.30 ... master

Author SHA1 Message Date
a-sansara
3794af72b2 add minimal Gee.HashMap support 2018-09-06 18:46:44 +02:00
a-Sansara
626e88b37f update readme amend valadoc 2018-09-05 03:02:32 +02:00
a-Sansara
6d58329670 version 0.60 2018-09-05 02:33:21 +02:00
a-Sansara
83e6aa5729 fix processor 2018-09-05 02:07:59 +02:00
a-Sansara
c019ff1749 update gitignore, hide local mess 2018-09-05 02:06:58 +02:00
a-Sansara
3f8c77ebd7 fix & automated valadoc deployment 2018-09-05 02:06:06 +02:00
a-Sansara
3b915dcc92 add LOCAL build option 2018-09-05 02:04:22 +02:00
a-sansara
36f7cdcc6f fix processor 2018-09-04 18:47:16 +02:00
a-sansara
1ef7559309 fix error on Processor for nested mapping entries 2018-08-31 18:14:20 +02:00
a-sansara
48c00f3ae5 improve doc 2018-08-29 18:42:10 +02:00
a-sansara
f73d7d8545 amend readme 2018-08-29 16:59:06 +02:00
a-sansara
c840747e18 version 0.55 2018-08-29 16:37:11 +02:00
a-sansara
2acc2930ce extract samples classes from lib 2018-08-29 16:27:04 +02:00
a-sansara
487a5cd107 use berel to write files header 2018-08-28 14:57:04 +02:00
a-Sansara
ca6a46421d fix error loading bad file 2018-08-28 01:58:14 +02:00
a-Sansara
efe4a48d8f fix lines count in yaml_root 2018-08-24 21:03:56 +02:00
a-sansara
8dc1e7e436 amend 2018-08-24 18:50:32 +02:00
a-sansara
91aab4ab5c improve doc 2018-08-24 18:43:19 +02:00
a-sansara
2b11962eb6 add Yaml.serialize & Yaml.deserialize 2018-08-24 14:11:19 +02:00
a-Sansara
7dde273ef7 clean traces 2018-08-24 04:13:01 +02:00
a-Sansara
c9f17fbef9 fix processor nested map in seq + enhance dumper 2018-08-24 03:59:54 +02:00
a-sansara
a6d16dee96 add dumper + attempt debug next value entry on processor 2018-08-23 18:57:24 +02:00
a-Sansara
37f5e43720 refact Register 2018-08-23 11:11:58 +02:00
a-sansara
8e2b1a92d2 tmp - remove Yaml.Object dependency for Yaml.Builder 2018-08-22 18:55:25 +02:00
a-Sansara
1366bcea29 tmp 2018-08-22 11:17:29 +02:00
a-sansara
804edebbee tmp 2018-08-21 18:54:47 +02:00
a-Sansara
bce93d2027 tmp 2018-08-21 15:29:35 +02:00
a-Sansara
b80ad982c9 tmp 2018-08-21 02:34:25 +02:00
a-sansara
4ac9c387b4 tmp 2018-08-20 18:45:50 +02:00
a-Sansara
93ed254f8c update readme 2018-08-20 03:53:06 +02:00
a-Sansara
6b77c25111 add resolve_namespace_type + use va_list in register.add_type 2018-08-20 03:38:31 +02:00
a-Sansara
7315d2cba2 permit build one sample 2018-08-20 03:07:35 +02:00
a-Sansara
4d6ad37810 cleaning events resources file for Scanner 2018-08-20 01:30:58 +02:00
a-Sansara
87664f31b4 provide Yaml.Object to Yaml.Node conversion 2018-08-19 23:15:24 +02:00
a-sansara
6c6d8db513 Merge branch 'tag-impl' of pluie/lib-yaml into master 2018-08-18 23:26:49 +00:00
a-Sansara
c4a4bd5590 version 0.5 2018-08-19 01:23:39 +02:00
a-Sansara
f22997c622 amend 2018-08-19 00:28:26 +02:00
a-Sansara
f620de7980 update readme 2018-08-18 23:25:03 +02:00
a-Sansara
e4c554df3d add Yaml.Builder, provide mechanism to populate structure and other GLib.Object derived type 2018-08-18 23:22:08 +02:00
a-sansara
68d2c026d4 fix set enum value 2018-08-18 22:21:13 +02:00
a-Sansara
2692c633ae update meson.build 2018-08-14 02:35:38 +02:00
a-Sansara
7a597188de tag directives & tag partially managed 2018-08-11 03:03:58 +02:00
a-Sansara
6c1e4d0251 suite tag impl 2018-08-10 16:40:27 +02:00
a-Sansara
3de39868e6 suite tag impl 2018-08-10 02:22:01 +02:00
a-sansara
18ceff507f suite tag impl 2018-08-09 18:47:49 +02:00
a-Sansara
7bb36efe51 suite tag impl 2018-08-09 03:47:35 +02:00
a-sansara
e98c7c070f update readme 2018-08-08 18:14:57 +02:00
a-sansara
a3ba700140 begin tag impl 2018-08-08 18:10:38 +02:00
a-Sansara
79a5c4704c update readme 2018-08-08 00:56:38 +02:00
a-Sansara
6987884c0a update meson.build & samples for docker pluie/libyaml image 2018-08-07 21:07:15 +02:00
a-sansara
3a6a3faf98 fix warning + add doc script 2018-08-07 16:07:13 +02:00
a-Sansara
6cad99df70 big refacto - version 0.40 2018-08-05 15:39:49 +02:00
a-sansara
e6518a32de update traversing 2018-08-03 18:47:46 +02:00
a-Sansara
7796fb2c5c refact Yaml Processor, Scanner, Loader & Config 2018-08-03 03:09:38 +02:00
66 changed files with 6411 additions and 1989 deletions

74
.berel.yml Normal file
View File

@ -0,0 +1,74 @@
%YAML 1.2
%TAG !v! tag:pluie.org,2018:vala/
---
!v!Pluie.Berel.Meta meta :
keys :
software : pluie-yaml; <https://git.pluie.org/pluie/lib-yaml>
version : 0.60
type : library
date : 2018
license : GPLv3.0; <http://www.gnu.org/licenses/>
author : a-Sansara; <[dev]at[pluie]dot[org]>
copyright : pluie.org; <http://www.pluie.org>
headers :
- sh :
file :
- build.sh
- valadoc.sh
startline : 2 # to embed shebang before header tpl
sepline :
motif : "# "
repeat : 40
comment :
start : "#^#"
end : "#^#"
begin : "# "
- meson :
file :
- meson.build
- src/meson.build
sepline :
motif : "# "
repeat : 40
comment :
start : "#^#"
end : "#^#"
begin : "# "
- vala :
dir :
- src
- samples
extension :
- .vala
- .c
sepline :
motif : " *"
repeat : 40
comment :
start : "/*^"
end : "^*/"
begin : " * "
tpl : |
^sepline^
^keys^
^sepline^
This file is part of ^software.name^.
^software.name^ 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.
^software.name^ 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 ^software.name^. If not, see ^license.address^.
^sepline^

6
.gitignore vendored
View File

@ -1,2 +1,8 @@
build/
bin/
doc/
pluie-yaml-*.tar.gz
.geany
docfix*
docsvg.tar.gz
tag-generated.yml

359
README.md
View File

@ -4,19 +4,33 @@
As json is now a valid subset of yaml, you can use this lib to load json files too.
The purpose of this project is to make vala able to load and deal with yaml configuration files.
So, currently the lib deal only with one yaml document, but you can use a special `^imports` clause (nodemap)
to load a subset of yaml files in the main yaml document.
So, currently the lib deal only with one yaml document (it's not recommended to use multiples doc),
but you can use a special `^imports` clause (special mapping node) to load a subset of yaml files
in the main yaml document.
The lib partially manage tag directives and tag values (basic types and Yaml.Object extended objects types).
with version 0.5, **pluie-yaml** is now able to :
* parse yaml file with vala tags => transform to Yaml.Node
* Build Yaml.Object from Yaml.Node (with some glue for struct and non Yaml.Object derived types)
* Build Yaml.Node from Yaml.Object (with some glue for struct and non Yaml.Object derived types)
the lib does not manage yet tag directives and tag values.
**pluie-yaml** use the ![libyaml c library](https://github.com/yaml/libyaml) (License MIT, many thanks to Kirill Simonov) to parse and retriew related yaml events.
![pluie-yaml-1](https://www.meta-tech.academy/img/pluie-yaml-1.png?tmp=1)
![pluie-yaml-2](https://www.meta-tech.academy/img/pluie-yaml-2.png)
## License
GNU GPL v3
## Prerequisites
`valac meson ninja glib gee gobject pluie-echo`
`valac meson ninja libyaml glib gobject gmodule gio gee pluie-echo`
see https://git.pluie.org/pluie/libpluie-echo in order to install pluie-echo-0.2 pkg
## Install
@ -31,26 +45,54 @@ 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 glib-2.0 \
--pkg gobject-2.0 \
--pkg gmodule-2.0 \
--pkg gio-2.0 \
--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
You can use `./build.sh` to rebuild/install the **pluie-yaml** lib and compile samples files
you can use `./build.sh` to rebuild/install the **pluie-yaml** lib and compile samples files
```
# rebuild lib + build all samples
./build.sh
# rebuild lib + build only single sample (give sample file name without extension)
./build.sh yaml-serialize
# rebuild lib in local mode
# local mode avoid to rebuild when modifying yaml files in resources dir
# must be in the root directory
./build.sh yaml-serialize 1
```
## Api / Documentation
https://pluie.org/pluie-yaml-0.3/index.htm
(comming soon)
https://pluie.org/pluie-yaml-0.6/index.htm
## Docker
a demo image will be available soon on docker hub. you will be able to run a container with :
A demo image is now available on docker hub. To run a container :
```
docker run --rm -it pluie/libyaml
```
Then you can execute any samples, for example :
```
./json-loader
```
![pluie-yaml-json](https://www.meta-tech.academy/img/pluie-yaml-json.png)
see ![pluie/docker-images repository](https://github.com/pluie-org/docker-images)
for more details
## Usage
-------------------
@ -66,6 +108,8 @@ docker run --rm -it pluie/libyaml
}
```
see Finder below to get precisions about config.get parameter (search path definition)
-------------------
### config with ^imports clause
@ -91,6 +135,34 @@ docker run --rm -it pluie/libyaml
db : db.yml
```
![pluie-yaml](https://www.meta-tech.academy/img/pluie-yaml-imports2.png)
__legend display_childs__ :
```
[ node.name [refCount] node.parent.name node.level node.ntype.infos () node.count () node.uuid node.tag]
```
You can easily manage display tracing of yaml nodes by setting these var according to your needs :
```vala
using Pluie
...
// general debug display usefull informations
Yaml.DEBUG = false;
// drive display_childs method :
Yaml.DBG_SHOW_INDENT = true;
Yaml.DBG_SHOW_PARENT = false;
Yaml.DBG_SHOW_UUID = true;
Yaml.DBG_SHOW_LEVEL = false;
Yaml.DBG_SHOW_REF = false;
Yaml.DBG_SHOW_COUNT = true;
Yaml.DBG_SHOW_TAG = true;
Yaml.DBG_SHOW_TYPE = true;
...
```
-------------------
### loader
@ -101,10 +173,10 @@ load a single document.
```vala
var path = "./config/main.yml";
// uncomment to enable debug
// Pluie.Yaml.Scanner.DEBUG = true;
// Pluie.Yaml.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 ();
}
```
@ -112,7 +184,7 @@ load a single document.
### finder
**lib-yaml** provide a `Yaml.Finder` to easily retriew a particular yaml node.
**pluie-yaml** provide a `Yaml.Finder` to easily retriew a particular yaml node.
Search path definition has two mode.
The default mode is `Yaml.FIND_MODE.DOT`
- child mapping node are separated by dot
@ -141,12 +213,252 @@ vala code :
```vala
...
Yaml.NodeRoot root = loader.get_nodes ();
Yaml.Node? node = null;
if ((node = finder.find ("product{0}.description")) != null) {
var val = node.val ();
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
```vala
var config = new Yaml.Config (path);
var root = config.root_node ();
if (root != null && !root.empty ()) {
foreach (var child in root) {
// do stuff
of.echo (child.to_string ());
}
}
```
or
```vala
var config = new Yaml.Config (path);
var root = config.root_node ();
if (root != null && root.count () > 0) {
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 ();
// do stuff
of.echo (child.to_string ());
}
}
```
#### other
```vala
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 ();
}
}
```
```vala
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 ();
}
}
```
-------------------
### Tag Directives & Tag values
an example is available with `samples/yaml-tag.vala` sample
and `resources/tag.yml` file
on yaml side, proceed like that :
```yaml
%YAML 1.2
%TAG !v! tag:pluie.org,2018:vala/
---
!v!Pluie.Samples.YamlObject test1 :
myname : test1object
type_int : !v!int 3306
type_bool : !v!bool false
type_char : !v!char c
type_string : !v!string mystring1
type_uchar : !v!uchar L
type_uint : !v!uint 62005
type_float : !v!float 42.36
type_double : !v!double 95542123.4579512128
type_enum : !v!Pluie.Yaml.NODE_TYPE scalar # or int
!v!Pluie.Samples.YamlChild type_object :
toto : totovalue1
tata : tatavalue1
titi : 123
tutu : 1
!v!Pluie.Samples.YamlStruct type_struct :
red : !v!uint8 214
green : !v!uint8 78
blue : 153
!v!Gee.ArrayList type_gee_al :
- ab_1
- ab_2
- ab_3
- ab_4
```
**note :**
only the first level of yaml node matching a vala object need a tag.
**pluie-yaml** has mechanisms to retriew properties types of a Yaml.Object.
So basic vala types tag, enum tag, struct tag and derived Yaml.Object (here Samples.YamlObject & Samples.YamlChild)
or GLib.Object.
vala tags are not necessary inside a Yaml.Object.
on vala side :
```vala
using pluie;
...
var obj = (Samples.YamlObject) Yaml.Builder.from_node (root.first ());
of.echo("obj.type_int : %d".printf (obj.type_int));
// calling Samples.YamlChild method
obj.type_object.method_a ()
```
![pluie-yaml-tag](https://www.meta-tech.academy/img/pluie-yaml-tag-directives-yaml-node.png?tmp=2)
### Builder
**pluie-yaml** provide a Yaml.Builder which has automatic mechanisms to build Yaml.Object instances (and derived classes)
and set basics types properties, enum properties and based Yaml.Object properties from Yaml.node.
Other types like struct or native GLib.Object (Gee.ArrayList for example) properties need some stuff in order to be populated appropriately
We cannot do introspection on Structure's properties, so you need to implement a method which will do the job.
First at all, in the static construct of your class, you need to register (properties) types that need some glue for instanciation.
```vala
using Pluie;
public class Pluie.Samples.YamlObject : Yaml.Object
{
static construct
{
Yaml.Register.add_type (
typeof (Samples.YamlObject), // owner type
typeof (Samples.YamlStruct), // property type
typeof (Gee.ArrayList) // property type
);
}
...
```
Secondly you must override the `public void populate_from_node (Glib.Type, Yaml.Node node)` Yaml.Object original method.
`populate_from_node` is automatically called by the Yaml.Builder if the type property is prealably registered.
Example of implementation from `src/vala/Pluie/Samples.YamlObject.vala` :
```vala
public override void populate_from_node(GLib.Type type, Yaml.Node node)
{
if (type == typeof (Samples.YamlStruct)) {
this.type_struct = Samples.YamlStruct.from_yaml_node (node);
}
else if (type == typeof (Gee.ArrayList)) {
this.type_gee_al = new Gee.ArrayList<string> ();
if (!node.empty ()) {
foreach (var child in node) {
this.type_gee_al.add(child.data);
}
}
}
}
```
Once your class has this glue, you can deal with complex object and populate them
directly from yaml files.
for more details see :
* `src/vala/Pluie/Samples.YamlObject.vala`
* `src/vala/Pluie/Samples.YamlChild.vala`
* `src/vala/Pluie/Samples.YamlStruct.vala`
* `samples/yaml-tag.vala`
code from samples/yaml-tag.vala :
![pluie-yaml-tag](https://www.meta-tech.academy/img/pluie-yaml-sample-tag-code.png)
output from samples/yaml-tag.vala :
![pluie-yaml-tag](https://www.meta-tech.academy/img/pluie-yaml-sample-tag-output.png?tmp=53)
### Build Yaml.Node from Yaml.Object
reverse build mechanism is also possible but have the same limitation.
```vala
var config = new Yaml.Config (path, true);
var root = config.root_node ();
root.display_childs ();
of.action ("Yaml.Builder.from_node", root.first ().name);
var obj = (Samples.YamlObject) Yaml.Builder.from_node (root.first ());
obj.type_object.method_a ();
of.action ("Yaml.Builder.to_node", obj.get_type ().name ());
var n = Yaml.Builder.to_node (obj);
if ((done = n !=null)) {
n.display_childs ();
}
```
you need to override the `public Yaml.Node? populate_to_node(GLib.Type type, string name)` Yaml.Object original method
`populate_to_node` is also automatically called by the Yaml.Builder if the type property is prealably registered.
Example of implementation from `src/vala/Pluie/Samples.YamlObject.vala` :
```vala
public override Yaml.Node? populate_to_node(GLib.Type type, string name)
{
Yaml.Node? node = base.populate_to_node (type, name);
// non Yaml.Object type & registered type
if (node == null) {
if (type == typeof (Samples.YamlStruct)) {
node = this.type_struct.to_yaml_node (name);
}
else if (type == typeof (Gee.ArrayList)) {
node = new Yaml.Sequence (null, name);
foreach (var data in this.type_gee_al) {
new Yaml.Scalar (node, data);
}
}
}
return node;
}
```
### Serialize/Deserialize
-------------------
### more samples
@ -158,7 +470,14 @@ see samples files in ./samples directory
### todo
* ~~imports clause~~
* fix nodes traversing
* dumper
* manage tag directives & tag
* ~~fix nodes traversing~~
* ~~rewrite nodes classes~~
* ~~put doc online~~
* ~~add docker image~~
* ~~transform Yaml.Node nodes to Yaml.Object objects~~
* ~~transform Yaml.Object objects to Yaml.Node nodes~~
* ~~dumper~~
* ~~serialize/deserialize~~
* manage tag directives & tag (partially done)
* improve doc

View File

@ -1,42 +1,45 @@
#!/bin/bash
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#^# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
# @version : 0.60
# @type : library
# @date : 2018
# @license : GPLv3.0 <http://www.gnu.org/licenses/>
# @author : a-Sansara <[dev]at[pluie]dot[org]>
# @copyright : pluie.org <http://www.pluie.org>
#
# @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
# This file is part of pluie-yaml.
#
# pluie-yaml is free software (free as in speech) : you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# lib-yaml is distributed in the hope that it will be useful, but WITHOUT
#
# pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License
# along with lib-yaml. If not, see <http://www.gnu.org/licenses/>.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# You should have received a copy of the GNU General Public License
# along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #^#
# --------------------------------------------------------
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
lib="pluie-yaml-0.3"
c1="\033[1;38;5;215m"
c2="\033[1;38;5;97m"
cok="\033[1;38;5;37m"
cko="\033[1;38;5;204m"
off="\033[m"
resume=
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
lib="pluie-yaml-0.6"
samples=" src/vala/Pluie/Samples.YamlObject.vala \
src/vala/Pluie/Samples.YamlChild.vala \
src/vala/Pluie/Samples.YamlStruct.vala "
c1="\033[1;38;5;215m"
c2="\033[1;38;5;97m"
cok="\033[1;38;5;37m"
cko="\033[1;38;5;204m"
off="\033[m"
resume=
# --------------------------------------------------------
function build.title()
{
@ -51,7 +54,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
@ -61,9 +64,17 @@ function build.lib()
{
cd "$DIR"
build.title "$lib LIB BUILD"
echo
meson --prefix=/usr ./ build
sudo ninja -v install -C build
if [ "$1" -eq 1 ]; then
meson configure -DLOCAL=true build
else
meson configure -DLOCAL=false build
fi
if [ "$UID" != "0" ]; then
sudo ninja -v install -C build
else
ninja -v install -C build
fi
local rs=$?
build.title "$lib LIB BUILD" $rs
return $rs
@ -74,13 +85,16 @@ function build.samples()
for file in ./samples/*.vala
do
if [[ -f $file ]]; then
build.sample "$file"
if [ -z "$1" ] || [ "$1" == "$file" ]; then
build.sample "$file"
fi
fi
done
echo -e "\n RESUME : "
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()
@ -88,9 +102,9 @@ function build.sample()
local f="$(basename $1)"
local fx="${f:0:-5}"
local state="FAILED"
local cmd="valac -v --pkg gee-0.8 --pkg pluie-echo-0.2 --pkg $lib $1 -o ./bin/$fx"
local cmd="valac -v -X -Wno-discarded-qualifiers -X -Wno-deprecated-declarations --pkg gee-0.8 --pkg gio-2.0 --pkg pluie-echo-0.2 --pkg $lib $samples $1 -o ./bin/$fx"
build.title "$f SAMPLE BUILD"
echo -e "\n$cmd"
echo
$cmd
local done=$?
resume="$resume$done$f "
@ -99,10 +113,14 @@ function build.sample()
# --------------------------------------------------------
function build.main()
{
build.lib
local onefile=""
if [ ! -z "$1" ]; then
onefile="./samples/$1.vala"
fi
build.lib "$2"
if [ $? -eq 0 ]; then
build.samples
build.samples $onefile
fi
}
build.main
build.main "$1" "${2:-0}"

View File

@ -1,37 +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/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
namespace Pluie
{
namespace Yaml
{
protected const string INSTALL_PATH = "@INSTALL_PATH@";
protected const string DATA_PATH = "@DATA_PATH@";
public const string VERSION = "@VERSION@";
}
}

View File

@ -1,100 +1,96 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#^# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
# @version : 0.60
# @type : library
# @date : 2018
# @license : GPLv3.0 <http://www.gnu.org/licenses/>
# @author : a-Sansara <[dev]at[pluie]dot[org]>
# @copyright : pluie.org <http://www.pluie.org>
#
# @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
# This file is part of pluie-yaml.
#
# pluie-yaml is free software (free as in speech) : you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# lib-yaml is distributed in the hope that it will be useful, but WITHOUT
#
# pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License
# along with lib-yaml. If not, see <http://www.gnu.org/licenses/>.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
project('libpluie-yaml', 'vala', 'c')
# You should have received a copy of the GNU General Public License
# along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #^#
project('pluie-yaml', ['vala', 'c'], version:'0.6')
cc = meson.get_compiler('c')
dep_glib = dependency('glib-2.0')
dep_gobject = dependency('gobject-2.0')
dep_gio = dependency('gio-2.0')
dep_gee = dependency('gee-0.8')
dep_echo = dependency('pluie-echo-0.2')
dep_m = cc.find_library('m', required : false)
dep_yaml = cc.find_library('yaml', required : true)
#~ add_global_link_arguments('-lyaml', language : 'c')
version = '0.3'
version = meson.project_version()
bindir = join_paths(get_option('prefix'), get_option('bindir'))
datadir = join_paths(get_option('prefix'), get_option('datadir'), 'pluie')
datadir = join_paths(get_option('prefix'), get_option('datadir'), 'pluie/yaml')
libdir = join_paths(get_option('prefix'), get_option('libdir'), 'pkgconfig')
incdir = join_paths(get_option('prefix'), get_option('includedir'), 'pluie')
conf = configuration_data()
conf.set('VERSION' , version)
conf.set('INSTALL_PATH', bindir)
conf.set('DATA_PATH' , datadir)
if get_option('LOCAL')
conf.set('DATA_PATH' , './resources')
else
conf.set('DATA_PATH' , datadir)
endif
configure_file(
input: 'install.vala.in',
input: 'src/vala/install.vala.in',
output: 'install.vala',
configuration: conf
)
sources = [
'build/install.vala',
'src/vala/Pluie/Io.Reader.vala',
'src/vala/Pluie/Io.StreamLineMark.vala',
'src/vala/Pluie/Yaml.global.vala',
'src/vala/Pluie/Yaml.Config.vala',
'src/vala/Pluie/Yaml.Document.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.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/c/yaml.c'
]
install_data([
'resources/main.yml',
'resources/tag.yml',
'resources/bug.yml',
'resources/test.yml',
'resources/test.json'
],
install_dir : datadir
)
install_data('resources/config/db.yml', install_dir : join_paths(datadir, 'config'))
install_data('resources/config/subdir/test.yml', install_dir : join_paths(datadir, 'config/subdir'))
subdir('src')
add_global_arguments('-D DEBUG', language : 'valac')
install_data('resources/test.yml', install_dir : datadir)
libpluie_yaml = library(
'pluie-yaml-' + version,
sources,
src_files,
vala_header : 'pluie_yaml.h',
vala_vapi : 'pluie-yaml-' +version+'.vapi',
dependencies : [dep_glib, dep_gobject, dep_gio, dep_gee, dep_echo, dep_m, dep_yaml],
dependencies : [
dependency('glib-2.0'),
dependency('gobject-2.0'),
dependency('gmodule-2.0'),
dependency('gio-2.0'),
dependency('gee-0.8'),
dependency('pluie-echo-0.2'),
cc.find_library('m', required : false),
cc.find_library('yaml', required : true)
],
install : true,
version : version,
install_dir : [get_option('libdir'), incdir, true]
)
pkgconfig = import('pkgconfig')
pkgconfig.generate(
libraries : libpluie_yaml,
requires : 'glib-2.0 gobject-2.0 gio-2.0 gee-0.8 pluie-echo-0.2',
requires : 'glib-2.0 gmodule-2.0 gobject-2.0 gio-2.0 gee-0.8 pluie-echo-0.2',
variables : 'datarootdir='+join_paths('${prefix}', get_option('datadir'))+'\ndatadir='+join_paths('${datarootdir}', 'pluie'),
version : version,
name : 'libpluie-yaml',

1
meson_options.txt Normal file
View File

@ -0,0 +1 @@
option('LOCAL', type : 'boolean', value : false)

82
resources/bug.yml Normal file
View File

@ -0,0 +1,82 @@
%YAML 1.2
%TAG !v! tag:pluie.org,2018:vala/
---
!v!Pluie.Berel.Meta meta :
!v!Gee.ArrayList keys :
- software : berel; <https://git.pluie.org/pluie/berel>
- version : 0.24
- type : program
- date : 2018
- license : GPLv3.0; <http://www.gnu.org/licenses/>
- author : a-Sansara; <[dev]at[pluie]dot[org]>
- copyright : pluie.org; <http://www.pluie.org>
!v!Gee.ArrayList headers :
- !v!Pluie.Berel.HeaderDef sh :
file :
- build.sh
startline : 2 # to embed shebang before header tpl
sepline :
motif : "# "
repeat : 40
comment :
start : "#^#"
end : "#^#"
begin : "# "
- !v!Pluie.Berel.HeaderDef meson :
file :
- meson.build
- src/meson.build
sepline :
motif : "# "
repeat : 40
comment :
start : "#^#"
end : "#^#"
begin : "# "
- !v!Pluie.Berel.HeaderDef vala :
dir :
- src
extension :
- .vala
sepline :
motif : " *"
repeat : 40
comment :
start : "/*^"
end : "^*/"
begin : " * "
tpl : |
^sepline^
^keys^
^sepline^
This file is part of ^software.name^.
^software.name^ 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.
^software.name^ 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 ^software.name^. If not, see <http://www.gnu.org/licenses/>.
^sepline^
product:
- sku : BL394D
quantity : 5
description : Basketball
price : 450.00
- sku : BL394D
quantity : 5
description : Basketball
price : 450.00

View File

@ -5,6 +5,7 @@ bo :
user : dev
password : mysql
charset : utf8
port : 3306
therapy :
driver : mysql
@ -13,3 +14,4 @@ therapy :
user : dev
password : mysql
charset : utf8
port : 3306

56
resources/doc-scripts.js Normal file
View File

@ -0,0 +1,56 @@
/* markupwriter.vala
*
* Copyright (C) 2008-2009 Florian Brosch
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author:
* Florian Brosch <flo.brosch@gmail.com>
*/
function get_path (path) {
var pos = path.lastIndexOf ('/');
if (pos < 0) {
return '';
}
return path.substring (pos, -1) + '/';
}
function toggle_box (self, id) {
var element = document.getElementById (id);
if (element == null) {
return ;
}
var style = self.currentStyle || window.getComputedStyle (self, false);
var orig_path = /url[ \t]*\(('(.*)'|"(.*)")\)/.exec (style.backgroundImage)[1].slice(1, -1);
var orig_dir = get_path (orig_path);
if (element.style.display == 'block') {
element.style.display = 'none';
self.style.backgroundImage = "url('" + orig_dir + 'coll_open.svg' + "')";
} else {
element.style.display = 'block';
self.style.backgroundImage = "url('" + orig_dir + 'coll_close.svg' + "')";
}
}
window.onload = function() {
var nav = document.querySelector('.site_navigation');
nav.innerHTML = '<div id="nav_content">'+nav.innerHTML+'</div>';
var header = document.querySelector('.site_header');
var data = header.innerHTML.split("");
header.innerHTML = data[0] + (data[1] ? '<div align="right" style="padding-right:20px; font-size:18px;">'+data[1]+'</div>' : '');
}

4
resources/doc-style.css Normal file

File diff suppressed because one or more lines are too long

77
resources/tag.yml Normal file
View File

@ -0,0 +1,77 @@
%YAML 1.2
%TAG !v! tag:pluie.org,2018:vala/
---
!v!Pluie.Samples.YamlObject test1 :
myname : test1object
type_int : !v!int 3306
type_bool : !v!bool false
type_char : !v!char c
type_string : !v!string mystring1
type_uchar : !v!uchar L
type_uint : !v!uint 62005
type_float : !v!float 42.36
type_double : !v!double 95542123.4579512128
type_enum : !v!Pluie.Yaml.NODE_TYPE scalar # or int
!v!Pluie.Samples.YamlChild type_object :
toto : totovalue1
tata : tatavalue1
titi : 123
tutu : 1
!v!Pluie.Samples.YamlStruct type_struct :
red : !v!uint8 214
green : !v!uint8 78
blue : 153
!v!Gee.ArrayList type_gee_al :
- 1.2
- 2.2
- 3.2
- 4.2
!v!Gee.ArrayList type_gee_alobject :
- toto : totovalue1
tata : tatavalue1
titi : 789
tutu : true
- toto : totovalue2
tata : tatavalue2
titi : 456
tutu : false
- toto : totovalue3
tata : tatavalue3
titi : 123
tutu : 1
- toto : totovalue4
tata : tatavalue4
titi : 44
tutu : 0
!v!Gee.HashMap type_gee_hmap :
- key : key1
!v!Pluie.Samples.YamlChild val :
toto : key1toto
tata : kay1tata
titi : 5
tutu : 0
- key : key2
val :
toto : key2toto
tata : kay2tata
titi : 46
tutu : 1
!v!Gee.HashMap type_gee_hmap2 :
- !v!Pluie.Samples.YamlStruct key :
red : !v!uint8 214
green : !v!uint8 78
blue : 153
!v!Pluie.Samples.YamlChild val :
toto : key1toto
tata : kay1tata
titi : 5
tutu : 0
- key :
red : !v!uint8 82
green : !v!uint8 109
blue : 35
val :
toto : key2toto
tata : kay2tata
titi : 46
tutu : 1

View File

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

View File

@ -1,7 +1,37 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.3
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.5
* @type : library
* @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
@ -9,20 +39,20 @@
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of lib-yaml.
* This file is part of pluie-yaml.
*
* lib-yaml is free software (free as in speech) : you can redistribute it
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* lib-yaml is distributed in the hope that it will be useful, but WITHOUT
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with lib-yaml. If not, see <http://www.gnu.org/licenses/>.
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
@ -35,14 +65,15 @@ int main (string[] args)
{
Echo.init(false);
var path = "resources/test.json";
var path = Yaml.DATA_PATH + "/test.json";
var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
Pluie.Yaml.Scanner.DEBUG = false;
Pluie.Yaml.DEBUG = true;
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);

85
samples/yaml-bug.vala Normal file
View File

@ -0,0 +1,85 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.5
* @type : library
* @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
using GLib;
using Gee;
using Pluie;
int main (string[] args)
{
Echo.init(false);
var path = Yaml.DATA_PATH + "/bug.yml";
var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
Pluie.Yaml.DEBUG = false;
Yaml.Loader.PACK_NESTED_ENTRIES = true;
var loader = new Yaml.Loader (path, true, true);
if ((done = loader.done)) {
var root = loader.get_nodes ();
done = root != null;
}
of.rs (done);
of.echo ();
return (int) done;
}

View File

@ -1,7 +1,37 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.3
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.5
* @type : library
* @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
@ -9,20 +39,20 @@
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of lib-yaml.
* This file is part of pluie-yaml.
*
* lib-yaml is free software (free as in speech) : you can redistribute it
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* lib-yaml is distributed in the hope that it will be useful, but WITHOUT
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with lib-yaml. If not, see <http://www.gnu.org/licenses/>.
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
@ -35,13 +65,15 @@ int main (string[] args)
{
Echo.init(false);
var path = "resources/config/db.yml";
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;
Pluie.Yaml.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);

89
samples/yaml-dump.vala Normal file
View File

@ -0,0 +1,89 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.5
* @type : library
* @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
using GLib;
using Gee;
using Pluie;
int main (string[] args)
{
Echo.init(false);
var path = Yaml.DATA_PATH + "/tag.yml";
var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
Pluie.Yaml.DEBUG = false;
var config = new Yaml.Config (path, true);
var root = config.root_node () as Yaml.Root;
if ((done = root != null)) {
root.display_childs ();
of.action("Yaml.Node", "to_yaml_string");
string genpath = "./tag-generated.yml";
var writter = new Io.Writter (genpath, true);
long written = 0;
writter.write (root.to_yaml_string ().data, out written);
of.echo ("write %ld bytes in `%s`".printf ((long) written, genpath));
Yaml.Dumper.show_yaml_string (root, true, true, true);
}
return (int) done;
}

View File

@ -1,7 +1,37 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.3
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.5
* @type : library
* @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
@ -9,20 +39,20 @@
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of lib-yaml.
* This file is part of pluie-yaml.
*
* lib-yaml is free software (free as in speech) : you can redistribute it
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* lib-yaml is distributed in the hope that it will be useful, but WITHOUT
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with lib-yaml. If not, see <http://www.gnu.org/licenses/>.
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
@ -35,14 +65,14 @@ int main (string[] args)
{
Echo.init(false);
var path = "resources/test.yml";
var path = Yaml.DATA_PATH + "/test.yml";
var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
//~ Pluie.Yaml.Scanner.DEBUG = false;
//~ Pluie.Yaml.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 +81,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 +101,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]";

View File

@ -1,7 +1,37 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.3
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.5
* @type : library
* @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
@ -9,24 +39,25 @@
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of lib-yaml.
* This file is part of pluie-yaml.
*
* lib-yaml is free software (free as in speech) : you can redistribute it
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* lib-yaml is distributed in the hope that it will be useful, but WITHOUT
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with lib-yaml. If not, see <http://www.gnu.org/licenses/>.
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
using GLib;
using Gee;
using Pluie;
@ -35,14 +66,12 @@ int main (string[] args)
{
Echo.init(false);
var pwd = Environment.get_variable ("PWD");
//~ var path = Path.build_filename (pwd, "resources/main.yml");
var path = "./resources/main.yml";
var path = Yaml.DATA_PATH + "/main.yml";
var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
Pluie.Yaml.Scanner.DEBUG = false;
Pluie.Yaml.DEBUG = false;
var config = new Yaml.Config (path, true);
var spath = "^imports";
var node = config.get (spath);
@ -59,10 +88,6 @@ int main (string[] args)
of.rs (done);
of.echo ();
of.echo (pwd);
return (int) done;
}

View File

@ -1,7 +1,37 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.3
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.5
* @type : library
* @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
@ -9,24 +39,25 @@
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of lib-yaml.
* This file is part of pluie-yaml.
*
* lib-yaml is free software (free as in speech) : you can redistribute it
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* lib-yaml is distributed in the hope that it will be useful, but WITHOUT
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with lib-yaml. If not, see <http://www.gnu.org/licenses/>.
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
using GLib;
using Gee;
using Pluie;
@ -35,14 +66,15 @@ int main (string[] args)
{
Echo.init(false);
var path = "resources/test.yml";
var path = Yaml.DATA_PATH + "/test.yml";
var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
Pluie.Yaml.Scanner.DEBUG = false;
Pluie.Yaml.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);

172
samples/yaml-node.vala Normal file
View File

@ -0,0 +1,172 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.5
* @type : library
* @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
using GLib;
using Gee;
using Pluie;
int main (string[] args)
{
Echo.init(false);
var 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;
}

132
samples/yaml-serialize.vala Normal file
View File

@ -0,0 +1,132 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Gee;
using Pluie;
public void test_object(Samples.YamlObject obj)
{
of.action ("Test Object", obj.yaml_name);
obj.type_object.method_a ();
if (obj.type_gee_al != null) {
of.keyval("yaml_name" , "%s" .printf(obj.yaml_name));
of.keyval("type_int" , "%d" .printf(obj.type_int));
of.keyval("type_bool" , "%s" .printf(obj.type_bool.to_string ()));
of.keyval("type_char" , "%c" .printf(obj.type_char));
of.keyval("type_string" , "%s" .printf(obj.type_string));
of.keyval("type_uchar" , "%u" .printf(obj.type_uchar));
of.keyval("type_uint" , "%u" .printf(obj.type_uint));
of.keyval("type_float" , "%f" .printf(obj.type_float));
of.keyval("type_double" , "%f" .printf(obj.type_double));
of.keyval("type_struct" , "%s" .printf(obj.type_struct.to_string ()));
of.keyval("type_enum" , "%d (%s)" .printf(obj.type_enum, obj.type_enum.infos()));
of.keyval("type_gee_al", "(%s<%s>)" .printf(obj.type_gee_al.get_type ().name (), obj.type_gee_al.element_type.name ()));
foreach (var v in obj.type_gee_al) {
of.echo(" - item : %g".printf (v));
}
of.keyval("type_object", "(%s)" .printf(obj.type_object.get_type ().name ()));
of.keyval(" toto" , "%s (string)" .printf(obj.type_object.toto));
of.keyval(" tapa" , "%s (string)" .printf(obj.type_object.tata));
of.keyval(" titi" , "%d (int)" .printf(obj.type_object.titi));
of.keyval(" tutu" , "%s (bool)" .printf(obj.type_object.tutu.to_string ()));
obj.type_object.method_a ();
of.keyval("type_gee_alobject", "(%s<%s>)" .printf(obj.type_gee_alobject.get_type ().name (), obj.type_gee_alobject.element_type.name ()));
foreach (var child in obj.type_gee_alobject) {
of.echo(" == entry (%s) ==".printf(child.get_type ().name ()));
of.keyval(" toto" , "%s (string)" .printf(child.toto));
of.keyval(" tapa" , "%s (string)" .printf(child.tata));
of.keyval(" titi" , "%d (int)" .printf(child.titi));
of.keyval(" tutu" , "%s (bool)" .printf(child.tutu.to_string ()));
child.method_a ();
}
if (obj.type_gee_hmap != null) {
of.keyval("type_gee_hmap", "(%s<%s, %s>)" .printf(obj.type_gee_hmap.get_type ().name (), obj.type_gee_hmap.key_type.name (), obj.type_gee_hmap.value_type.name ()));
foreach (var child in obj.type_gee_hmap.entries) {
of.echo(" == entry (%s) ==".printf(child.key));
of.keyval(" toto" , "%s (string)" .printf(child.value.toto));
of.keyval(" tapa" , "%s (string)" .printf(child.value.tata));
of.keyval(" titi" , "%d (int)" .printf(child.value.titi));
of.keyval(" tutu" , "%s (bool)" .printf(child.value.tutu.to_string ()));
}
}
if (obj.type_gee_hmap2 != null) {
of.keyval("type_gee_hmap", "(%s<%s, %s>)" .printf(obj.type_gee_hmap2.get_type ().name (), obj.type_gee_hmap2.key_type.name (), obj.type_gee_hmap2.value_type.name ()));
foreach (var child in obj.type_gee_hmap2.entries) {
of.echo(" == key ==");
of.keyval(" obj :" , "%s" .printf(child.key.to_string ()));
of.echo(" == val (%s) ==".printf(child.value.get_type ( ).name ()));
of.keyval(" toto" , "%s (string)" .printf(child.value.toto));
of.keyval(" tapa" , "%s (string)" .printf(child.value.tata));
of.keyval(" titi" , "%d (int)" .printf(child.value.titi));
of.keyval(" tutu" , "%s (bool)" .printf(child.value.tutu.to_string ()));
}
}
else {
of.echo ("hmap2 null");
}
}
}
int main (string[] args)
{
Echo.init(false);
var path = Yaml.DATA_PATH + "/tag.yml";
var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
Pluie.Yaml.DEBUG = false;
var config = new Yaml.Config (path, true);
var root = config.root_node ();
if ((done = root != null)) {
root.display_childs ();
of.action ("Yaml build first child", root.first ().name);
var obj = (Samples.YamlObject) Yaml.Builder.from_node (root.first ());
test_object (obj);
of.action ("Serialize", obj.yaml_name);
uint8[] zdata = Yaml.serialize (obj);
of.echo ("zdata size : %ld".printf (zdata.length));
for (var i = 0; i < zdata.length; i++) {
print ("%02x", zdata[i]);
}
of.action ("Deserialize zdata from", obj.yaml_name);
root = Yaml.deserialize (zdata);
root.display_childs ();
of.action ("Yaml build first child", obj.yaml_name);
obj = (Samples.YamlObject) Yaml.Builder.from_node (root.first ());
test_object (obj);
}
return (int) done;
}

164
samples/yaml-tag.vala Normal file
View File

@ -0,0 +1,164 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.5
* @type : library
* @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
using GLib;
using Gee;
using Pluie;
int main (string[] args)
{
Echo.init(false);
var path = Yaml.DATA_PATH + "/tag.yml";
var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
Pluie.Yaml.DEBUG = false;
Yaml.Object? obj = null;
var config = new Yaml.Config (path, true);
var root = config.root_node ();
root.display_childs ();
var list = new Gee.HashMap<string, Yaml.Object> ();
if ((done = root != null)) {
foreach (var node in root) {
of.action ("Yaml.Object from node", node.name);
of.echo (node.to_string (false));
if ((obj = (Yaml.Object) Yaml.Builder.from_node (node)) != null) {
list[node.name] = obj;
}
else {
of.error ("cannot set Yaml.Object from node : %s".printf (node.name), true);
}
node = node.next_sibling ();
}
}
// hard code
Samples.YamlObject? o = null;
foreach (var entry in list.entries) {
if ((o = (Samples.YamlObject) entry.value)!=null) {
of.action ("Getting Hard coded values for Samples.YamlObject %s".printf (of.c (ECHO.MICROTIME).s (o.get_type().name ())), entry.key);
of.keyval("yaml_name" , "%s" .printf(o.yaml_name));
of.keyval("type_int" , "%d" .printf(o.type_int));
of.keyval("type_bool" , "%s" .printf(o.type_bool.to_string ()));
of.keyval("type_char" , "%c" .printf(o.type_char));
of.keyval("type_string" , "%s" .printf(o.type_string));
of.keyval("type_uchar" , "%u" .printf(o.type_uchar));
of.keyval("type_uint" , "%u" .printf(o.type_uint));
of.keyval("type_float" , "%f" .printf(o.type_float));
of.keyval("type_double" , "%f" .printf(o.type_double));
of.keyval("type_struct" , "%s" .printf(o.type_struct.to_string ()));
of.keyval("type_enum" , "%d (%s)" .printf(o.type_enum, o.type_enum.infos()));
of.keyval("type_object" , "%s" .printf(o.type_object.get_type ().name ()));
of.keyval(" toto" , "%s (string)" .printf(o.type_object.toto));
of.keyval(" tapa" , "%s (string)" .printf(o.type_object.tata));
of.keyval(" titi" , "%d (int)" .printf(o.type_object.titi));
of.keyval(" tutu" , "%s (bool)" .printf(o.type_object.tutu.to_string ()));
o.type_object.method_a ();
if (o.type_gee_al!= null) {
of.keyval("type_gee_al", "(%s)" .printf(o.type_gee_al.get_type ().name ()));
foreach (var v in o.type_gee_al) {
of.echo(" - item : %g".printf (v));
}
}
if (o.type_gee_alobject != null) {
of.keyval("type_gee_alobject", "(%s<%s>)" .printf(o.type_gee_alobject.get_type ().name (), o.type_gee_alobject.element_type.name ()));
foreach (var child in o.type_gee_alobject) {
of.echo(" == entry (%s) ==".printf(child.get_type ().name ()));
of.keyval(" toto" , "%s (string)" .printf(child.toto));
of.keyval(" tapa" , "%s (string)" .printf(child.tata));
of.keyval(" titi" , "%d (int)" .printf(child.titi));
of.keyval(" tutu" , "%s (bool)" .printf(child.tutu.to_string ()));
child.method_a ();
}
}
if (o.type_gee_hmap != null) {
of.keyval("type_gee_hmap", "(%s<%s, %s>)" .printf(o.type_gee_hmap.get_type ().name (), o.type_gee_hmap.key_type.name (), o.type_gee_hmap.value_type.name ()));
foreach (var child in o.type_gee_hmap.entries) {
of.echo(" == entry (%s) ==".printf(child.key));
of.keyval(" toto" , "%s (string)" .printf(child.value.toto));
of.keyval(" tapa" , "%s (string)" .printf(child.value.tata));
of.keyval(" titi" , "%d (int)" .printf(child.value.titi));
of.keyval(" tutu" , "%s (bool)" .printf(child.value.tutu.to_string ()));
}
}
if (o.type_gee_hmap2 != null) {
of.keyval("type_gee_hmap", "(%s<%s, %s>)" .printf(o.type_gee_hmap2.get_type ().name (), o.type_gee_hmap2.key_type.name (), o.type_gee_hmap2.value_type.name ()));
foreach (var child in o.type_gee_hmap2.entries) {
of.echo(" == key ==");
of.keyval(" obj :" , "%s" .printf(child.key.to_string ()));
of.echo(" == val (%s) ==".printf(child.value.get_type ( ).name ()));
of.keyval(" toto" , "%s (string)" .printf(child.value.toto));
of.keyval(" tapa" , "%s (string)" .printf(child.value.tata));
of.keyval(" titi" , "%d (int)" .printf(child.value.titi));
of.keyval(" tutu" , "%s (bool)" .printf(child.value.tutu.to_string ()));
}
}
else {
of.echo ("hmap2 null");
}
}
}
of.rs (done);
of.echo ();
return (int) done;
}

114
samples/yaml-test.vala Normal file
View File

@ -0,0 +1,114 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.5
* @type : library
* @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
using GLib;
using Gee;
using Pluie;
int main (string[] args)
{
Echo.init(false);
var path = Yaml.DATA_PATH + "/tag.yml";
var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
Pluie.Yaml.DEBUG = false;
var config = new Yaml.Config (path, true);
var root = config.root_node () as Yaml.Root;
root.first ().display_childs ();
of.action ("with signal Yaml.Builder.from_node", root.first ().name);
Samples.YamlObject obj = (Samples.YamlObject) Yaml.Builder.from_node (root.first ());
obj.type_object.method_a ();
if (obj.type_gee_al != null) {
of.keyval("type_gee_al", "(%s<%s>)" .printf(obj.type_gee_al.get_type ().name (), obj.type_gee_al.element_type.name ()));
foreach (var v in obj.type_gee_al) {
of.echo(" - item : %g".printf (v));
}
of.keyval("type_object", "(%s)" .printf(obj.type_object.get_type ().name ()));
of.keyval(" toto" , "%s (string)" .printf(obj.type_object.toto));
of.keyval(" tapa" , "%s (string)" .printf(obj.type_object.tata));
of.keyval(" titi" , "%d (int)" .printf(obj.type_object.titi));
of.keyval(" tutu" , "%s (bool)" .printf(obj.type_object.tutu.to_string ()));
obj.type_object.method_a ();
of.keyval("type_gee_alobject", "(%s<%s>)" .printf(obj.type_gee_alobject.get_type ().name (), obj.type_gee_alobject.element_type.name ()));
foreach (var child in obj.type_gee_alobject) {
of.echo(" == entry (%s) ==".printf(child.get_type ().name ()));
of.keyval(" toto" , "%s (string)" .printf(child.toto));
of.keyval(" tapa" , "%s (string)" .printf(child.tata));
of.keyval(" titi" , "%d (int)" .printf(child.titi));
of.keyval(" tutu" , "%s (bool)" .printf(child.tutu.to_string ()));
child.method_a ();
}
}
of.action ("with signal Yaml.Builder.to_node", obj.yaml_name);
var n = Yaml.Builder.to_node (obj);
if ((done = n !=null)) {
n.display_childs ();
}
of.rs (done);
of.echo ();
return (int) done;
}

160
samples/yaml-tonode.vala Normal file
View File

@ -0,0 +1,160 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.5
* @type : library
* @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
using GLib;
using Gee;
using Pluie;
public void inspect_type (GLib.Type type, ...)
{
var l = va_list();
while (true) {
var obj = l.arg<GLib.Object> ();
if (obj == null) {
break; // end of the list
}
print ("%s\n", type.name ());
print ("%s\n", type.name ());
print (" is-obj: %s\n", type.is_object ().to_string ());
print (" is-abstr: %s\n", type.is_abstract ().to_string ());
print (" is-classed: %s\n", type.is_classed ().to_string ());
print (" is-derivable: %s\n", type.is_derivable ().to_string ());
print (" is-derived: %s\n", type.is_derived ().to_string ());
print (" is-fund: %s\n", type.is_fundamental ().to_string ());
print (" is-inst: %s\n", type.is_instantiatable ().to_string ());
print (" is-iface: %s\n", type.is_interface ().to_string ());
print (" is-enum: %s\n", type.is_enum ().to_string ());
print (" is-flags: %s\n", type.is_object ().to_string ());
// Output:
// `` Children:``
print (" Children:\n");
foreach (unowned Type ch in type.children ()) {
print (" - %s\n", ch.name ());
}
// `` Interfaces:``
// `` - Interface``
print (" Interfaces:\n");
foreach (unowned Type ch in type.interfaces ()) {
if ( ch == typeof(Gee.Traversable)) {
var t = (obj as Gee.Traversable).element_type;
print (" --- !!! element type is %s\n", (obj as Gee.Traversable).element_type.name ());
print (" is-obj: %s\n", t.is_object ().to_string ());
print (" is-abstr: %s\n", t.is_abstract ().to_string ());
print (" is-classed: %s\n", t.is_classed ().to_string ());
print (" is-derivable: %s\n", t.is_derivable ().to_string ());
print (" is-derived: %s\n", t.is_derived ().to_string ());
print (" is-fund: %s\n", t.is_fundamental ().to_string ());
print (" is-inst: %s\n", t.is_instantiatable ().to_string ());
print (" is-iface: %s\n", t.is_interface ().to_string ());
print (" is-enum: %s\n", t.is_enum ().to_string ());
print (" is-flags: %s\n", t.is_object ().to_string ());
if ((obj as Gee.Traversable).element_type == typeof (Gee.Map.Entry)) {
print (" --- !!! key type is %s\n", (obj as Gee.Map).key_type.name ());
print (" --- !!! value type is %s\n", (obj as Gee.Map).value_type.name ());
}
}
print (" - %s\n", ch.name ());
}
// Output:
// `` Parents:``
// `` - GObject``
print (" Parents:\n");
for (Type p = type.parent (); p != 0 ; p = p.parent ()) {
print (" - %s\n", p.name ());
}
}
}
int main (string[] args)
{
Echo.init(false);
var path = Yaml.DATA_PATH + "/tag.yml";
var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
Pluie.Yaml.DEBUG = false;
var config = new Yaml.Config (path, true);
var root = config.root_node ();
root.display_childs ();
root.first ().display_childs ();
of.action ("Yaml.Builder.from_node", root.first ().name);
Samples.YamlObject obj = (Samples.YamlObject) Yaml.Builder.from_node (root.first ());
obj.type_object.method_a ();
if (obj.type_gee_al != null) {
of.keyval("type_gee_al", "(%s)" .printf(obj.type_gee_al.get_type ().name ()));
foreach (double v in obj.type_gee_al as Gee.ArrayList<double?>) {
of.echo(" - item : %f".printf (v));
}
}
var n = Yaml.Builder.to_node (obj);
if ((done = n !=null)) {
n.display_childs ();
}
of.rs (done);
of.echo ();
return (int) done;
}

View File

@ -0,0 +1,164 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.5
* @type : library
* @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
using GLib;
using Gee;
using Pluie;
int main (string[] args)
{
Echo.init(false);
var path = Yaml.DATA_PATH + "/test.yml";
var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
Pluie.Yaml.DEBUG = false;
var config = new Yaml.Config (path, true);
var node = config.root_node ();
if ((done = node != null)) {
node.display_childs ();
of.action("retriew child sequence node", "product");
var child = config.get("product");
of.echo (child.to_string (false));
of.action("retriew sequence last child node", child.name);
var nchild = child.last ();
if (nchild != null) {
of.echo (nchild.to_string ());
}
of.action("retriew sequence first child node", child.name);
nchild = child.first ();
if (nchild != null) {
of.echo (nchild.to_string ());
of.action("retriew sequence next sibling node", nchild.name);
nchild = nchild.next_sibling ();
if (nchild != null) {
of.echo (nchild.to_string ());
of.action("retriew sequence previous sibling node", nchild.name);
nchild = nchild.previous_sibling ();
if (nchild != null) {
of.echo (nchild.to_string ());
}
}
}
of.echo("\n ================================ ");
of.action("retriew mapping child node", "ship-to");
child = config.get("ship-to");
of.echo (child.to_string (false));
of.action("retriew mapping last child node", child.name);
nchild = child.last ();
if (nchild != null) {
of.echo (nchild.to_string ());
}
of.action("retriew mapping first child node", child.name);
nchild = child.first ();
if (nchild != null) {
of.echo (nchild.to_string ());
}
of.action("loop throught mapping next sibling", child.name);
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 = 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 ();
of.action ("current node is ", child.name);
of.echo ("use finder to retriew parent node");
var n = config.get ("bill-to");
if (n!= null) {
of.echo (n.to_string (false));
of.echo ("parent (mapping) contains child ? %d".printf ((int) n.contains (child)));
}
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 ().first ();
of.action ("current node is ", child.name);
of.echo ("use finder to retriew parent node");
n = config.get ("product{0}");
if (n!= null) {
of.echo (n.to_string (false));
of.echo ("parent (sequence) contains child ? %d".printf ((int) n.contains (child)));
}
}
of.rs (done);
of.echo ();
return (int) done;
}

View File

@ -1,31 +1,31 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* @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
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* lib-yaml is distributed in the hope that it will be useful, but WITHOUT
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*
* You should have received a copy of the GNU General Public License
* along with lib-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
#include <stdio.h>
#include <yaml.h>
@ -100,6 +100,10 @@ void yaml_parse_file(const char *srcPath, const char *destPath)
fprintf(wh, "%lu, %d, %d, %d\n", line, token.type, token.data.version_directive.major, token.data.version_directive.minor);
break;
case YAML_TAG_DIRECTIVE_TOKEN :
fprintf(wh, "%lu, %d, \"%s\", \"%s\"\n", line, token.type, token.data.tag_directive.handle, token.data.tag_directive.prefix);
break;
case YAML_NO_TOKEN :
fprintf(wh, "%lu, %d, \"%s\"\n", line, token.type, escape_string((char *)parser.problem));
stop = 1;

58
src/meson.build Normal file
View File

@ -0,0 +1,58 @@
#^# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
# @version : 0.60
# @type : library
# @date : 2018
# @license : GPLv3.0 <http://www.gnu.org/licenses/>
# @author : a-Sansara <[dev]at[pluie]dot[org]>
# @copyright : pluie.org <http://www.pluie.org>
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# This file is part of pluie-yaml.
#
# pluie-yaml is free software (free as in speech) : you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License
# along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #^#
src_files = [
'src/c/yaml.c',
'build/install.vala',
'src/vala/Pluie/Io.Reader.vala',
'src/vala/Pluie/Io.InputChunkStream.vala',
'src/vala/Pluie/Io.StreamLineMark.vala',
'src/vala/Pluie/Io.Writter.vala',
'src/vala/Pluie/Yaml.global.vala',
'src/vala/Pluie/Yaml.AbstractChild.vala',
'src/vala/Pluie/Yaml.AbstractNode.vala',
'src/vala/Pluie/Yaml.Builder.vala',
'src/vala/Pluie/Yaml.Collection.vala',
'src/vala/Pluie/Yaml.Config.vala',
'src/vala/Pluie/Yaml.Dumper.vala',
'src/vala/Pluie/Yaml.Event.vala',
'src/vala/Pluie/Yaml.Finder.vala',
'src/vala/Pluie/Yaml.GeeBuilder.vala',
'src/vala/Pluie/Yaml.Loader.vala',
'src/vala/Pluie/Yaml.Mapping.vala',
'src/vala/Pluie/Yaml.Node.vala',
'src/vala/Pluie/Yaml.Object.vala',
'src/vala/Pluie/Yaml.Processor.vala',
'src/vala/Pluie/Yaml.Register.vala',
'src/vala/Pluie/Yaml.Root.vala',
'src/vala/Pluie/Yaml.Scalar.vala',
'src/vala/Pluie/Yaml.Scanner.vala',
'src/vala/Pluie/Yaml.Sequence.vala',
'src/vala/Pluie/Yaml.Tag.vala'
]

View File

@ -0,0 +1,126 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
/**
* basic class to read file by chunk
*/
class Pluie.Io.InputChunkStream : Object
{
/**
*
*/
protected ulong chunk_index;
/**
*
*/
protected uint8 chunk_size;
/**
*
*/
protected uint8 buffer_size;
/**
*
*/
protected uint8[] buffer;
/**
*
*/
protected FileStream fs;
/**
* default constructor
* @param path the path to read
* @param chunk_size the chunk size
*/
public InputChunkStream (string path, uint8 chunk_size)
{
this.chunk_size = chunk_size;
this.buffer = new uint8[this.chunk_size];
this.fs = FileStream.open (path, "r");
this.chunk_index = 0;
}
/**
* indicate if end of file of readed file is reached
*/
public bool eof ()
{
bool stop = this.fs.eof ();
if (stop) {
this.buffer = null;
}
return stop;
}
/**
* read chunk_size
*/
public unowned uint8[] read ()
{
if (!this.eof ()) {
this.buffer_size = (uint8) this.fs.read (this.buffer);
this.chunk_index++;
}
return this.buffer;
}
/**
* retriew the buffer size (chunk_size)
*/
public unowned uint8 get_buffer_size ()
{
return this.buffer_size;
}
/**
* retriew content of buffer
*/
public unowned uint8[] get_buffer ()
{
return this.buffer;
}
/**
* retriew chunk index
*/
public ulong get_chunk_index ()
{
return this.chunk_index-1;
}
/**
* retriew chunk size
*/
public uint8 get_chunk_size ()
{
return this.chunk_size;
}
}

View File

@ -1,31 +1,32 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* @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
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* lib-yaml is distributed in the hope that it will be useful, but WITHOUT
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*
* You should have received a copy of the GNU General Public License
* along with lib-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Gee;
using Pluie;
@ -140,4 +141,18 @@ public class Pluie.Io.Reader
return this.readable;
}
/**
* get content of loaded file
*/
public string? get_contents ()
{
string? read = null;
try {
FileUtils.get_contents (this.path, out read);
}
catch(GLib.Error e) {
of.error (e.message);
}
return read;
}
}

View File

@ -1,31 +1,31 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* @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
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* lib-yaml is distributed in the hope that it will be useful, but WITHOUT
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*
* You should have received a copy of the GNU General Public License
* along with lib-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
/**
* a class representing a stream mark recording a line and it's position in the stream

View File

@ -0,0 +1,115 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Gee;
using Pluie;
/**
* basic writter class
*/
public class Pluie.Io.Writter
{
/**
* current file path
*/
public string path { get; internal set; }
/**
* current file
*/
public File file { get; internal set; }
/**
* stream used to read the file
*/
DataOutputStream stream;
/**
* construct a writter
* @param path the path to write
* @param delete_if_exists flag indicating if existing file must be removed first
*/
public Writter (string path, bool delete_if_exists = false)
{
this.path = path;
this.file = File.new_for_path (path);
try {
if (delete_if_exists) {
this.delete_file(this.file);
}
this.file = File.new_for_path (path);
this.stream = new DataOutputStream(file.create (FileCreateFlags.NONE));
if (!file.query_exists ()) {
of.error ("cannot create file '%s'".printf (path));
}
}
catch (GLib.Error e) {
of.error (e.message);
}
}
/**
* write specified data to current file
* @param data the data to write
* @param written the written data size
*/
public bool write (uint8[] data, out long? written = null)
{
bool done = false;
long w = 0;
try {
while (w < data.length) {
// sum of the bytes that already have been written to the stream
w += stream.write (data[w:data.length]);
}
done = w == data.length;
}
catch (GLib.Error e) {
of.error (e.message);
}
written = w;
return done;
}
/**
* delete current or specified file
* @param file the file to delete (current file if null)
*/
public bool delete_file(File? file = null)
{
bool done = false;
try {
((file == null) ? this.file : file).delete ();
done = true;
}
catch (GLib.Error e) {
of.error (e.message);
}
return done;
}
}

View File

@ -0,0 +1,44 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
/**
* a YamlCHild test class
*/
public class Pluie.Samples.YamlChild : Yaml.Object
{
public string toto { get; set; }
public string tata { get; set; }
public int titi { get; set; }
public bool tutu { get; set; }
public void method_a ()
{
of.echo (" called method from object %s builded via yaml".printf (this.get_type().name ()));
}
}

View File

@ -0,0 +1,204 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Gee;
using Pluie;
/**
* a YamlObject test class
*/
public class Pluie.Samples.YamlObject : Yaml.Object
{
public string myname { get; set; }
public string type_string { get; set; }
public int type_int { get; set; }
public uint type_uint { get; set; }
public float type_float { get; set; }
public double type_double { get; set; }
public char type_char { get; set; }
public uchar type_uchar { get; set; }
public unichar type_unichar { get; set; }
public short type_short { get; set; }
public ushort type_ushort { get; set; }
public long type_long { get; set; }
public ulong type_ulong { get; set; }
public size_t type_size_t { get; set; }
public ssize_t type_ssize_t { get; set; }
public int8 type_int8 { get; set; }
public uint8 type_uint8 { get; set; }
public int16 type_int16 { get; set; }
public uint16 type_uint16 { get; set; }
public int32 type_int32 { get; set; }
public uint32 type_uint32 { get; set; }
public int64 type_int64 { get; set; }
public uint64 type_uint64 { get; set; }
public bool type_bool { get; set; }
public Samples.YamlChild type_object { get; set; }
public Yaml.NODE_TYPE type_enum { get; set; }
public Samples.YamlStruct type_struct { get; set; }
public Gee.ArrayList<double?> type_gee_al { get; set; }
public Gee.ArrayList<Samples.YamlChild> type_gee_alobject { get; set; }
public Gee.HashMap<string, Samples.YamlChild> type_gee_hmap { get; set; }
public Gee.HashMap<YamlStruct?, Samples.YamlChild> type_gee_hmap2 { get; set; }
/**
*
*/
static construct
{
Yaml.Register.add_type (
typeof (Samples.YamlObject),
typeof (Samples.YamlChild),
typeof (Samples.YamlStruct),
typeof (Gee.ArrayList),
typeof (Gee.HashMap)
);
}
/**
*
*/
protected override void yaml_construct ()
{
this.type_gee_al = new Gee.ArrayList<double?> ();
this.type_gee_alobject = new Gee.ArrayList<Samples.YamlChild> ();
this.type_gee_hmap = new Gee.HashMap<string, Samples.YamlChild> ();
this.type_gee_hmap2 = new Gee.HashMap<Samples.YamlStruct?, Samples.YamlChild> ();
Yaml.Register.add_namespace("Gee", "Pluie.Samples");
Dbg.msg ("%s (%s) instantiated".printf (this.yaml_name, this.get_type().name ()), Log.LINE, Log.FILE);
}
/**
*
*/
protected override void yaml_init ()
{
Dbg.msg ("%s (%s) initialized".printf (this.yaml_name, this.get_type().name ()), Log.LINE, Log.FILE);
}
/**
*
*/
public override void populate_from_node (string name, GLib.Type type, Yaml.Node node) {
if (type == typeof (Samples.YamlStruct)) {
this.type_struct = Samples.YamlStruct.from_yaml_node (node);
}
else if (type == typeof (Gee.ArrayList)) {
foreach (var child in node) {
switch (name) {
case "type_gee_al":
this.type_gee_al.add(double.parse(child.data));
break;
case "type_gee_alobject":
this.type_gee_alobject.add((Samples.YamlChild) Yaml.Builder.from_node (child, typeof (Samples.YamlChild)));
break;
}
}
}
else if (type == typeof (Gee.HashMap)) {
Yaml.Mapping? c;
foreach (var child in node) {
c = child as Yaml.Mapping;
switch (name) {
case "type_gee_hmap":
Value key = c.item ("key").val (typeof (string));
var entry = (Samples.YamlChild) Yaml.Builder.from_node (c.item ("val"), typeof (Samples.YamlChild));
this.type_gee_hmap.set((string) key, entry);
break;
case "type_gee_hmap2":
var key = Samples.YamlStruct.from_yaml_node (c.item ("key"));
var entry = (Samples.YamlChild) Yaml.Builder.from_node (c.item ("val"), typeof (Samples.YamlChild));
this.type_gee_hmap2.set(key, entry);
break;
}
}
}
else {
var obj = Yaml.Builder.from_node(node, type);
if (name == "type_object") {
this.set (node.name, (Samples.YamlChild) obj);
}
else {
this.set (node.name, obj);
}
}
}
/**
*
*/
public override Yaml.Node? populate_to_node (string name, GLib.Type type, Yaml.Node parent) {
Yaml.Node? node = null;
if (type == typeof (Samples.YamlStruct)) {
node = this.type_struct.to_yaml_node (name);
}
else if (type == typeof (Gee.ArrayList)) {
switch (name) {
case "type_gee_al" :
Yaml.GeeBuilder.fundamental_arraylist_to_node (this.type_gee_al, name, parent);
break;
case "type_gee_alobject" :
Yaml.Object.objects_collection_to_node (this.type_gee_alobject, name, parent);
break;
}
}
else if (type == typeof (Gee.HashMap)) {
switch (name) {
case "type_gee_hmap" :
Yaml.Object.objects_mapkstr_to_node (this.type_gee_hmap, name, parent);
break;
case "type_gee_hmap2" :
this.hmap2_to_node (name, parent);
break;
}
}
else {
base.populate_to_node (name, type, parent);
}
return node;
}
/**
*
*/
public void hmap2_to_node (string name, Yaml.Node? parent = null)
{
of.echo (Log.METHOD);
var node = new Yaml.Sequence (parent, name);
node.tag = new Yaml.Tag (Yaml.Register.resolve_namespace_type(this.type_gee_hmap2.get_type ()), "v");
var i = 0;
foreach (var child in this.type_gee_hmap2.entries) {
var entryNode = new Yaml.Mapping (node, "_%d".printf (i));
entryNode.add (child.key.to_yaml_node ("key"));
Yaml.Builder.to_node ((GLib.Object) child.value, entryNode, false, null, "val");
}
}
}

View File

@ -0,0 +1,85 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
/**
* YamlStruct test structure
*/
public struct Pluie.Samples.YamlStruct
{
/**
*
*/
public uint red;
/**
*
*/
public uint green;
/**
*
*/
public uint blue;
/**
* get a new YamlStruct populated by specified node
* @param node the source Yaml.Node
*/
public static YamlStruct from_yaml_node (Yaml.Node node)
{
YamlStruct s = {};
foreach (var child in node) {
var v = child.val (typeof (uint));
switch (child.name) {
case "red" : s.red = v.get_uint (); break;
case "green" : s.green = v.get_uint (); break;
case "blue" : s.blue = v.get_uint (); break;
}
}
return s;
}
/**
*
*/
public Yaml.Node to_yaml_node (string name)
{
var node = new Yaml.Mapping (null, name);
new Yaml.Mapping.with_scalar (node, "red" , this.red.to_string ());
new Yaml.Mapping.with_scalar (node, "green", this.green.to_string ());
new Yaml.Mapping.with_scalar (node, "blue" , this.blue.to_string ());
return node;
}
/**
*
*/
public string to_string ()
{
return "%s(red:%u,green:%u,blue:%u)".printf ((typeof (YamlStruct)).name (), this.red, this.green, this.blue);
}
}

View File

@ -0,0 +1,141 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Pluie;
using Gee;
/**
* abstract class representing a child 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; }
/**
*
*/
public Yaml.Tag? tag { 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 last chikd
*/
public bool is_last ()
{
return !this.has_parent () ? false : this.same_node (this.parent.last ());
}
/**
* get nextt sibling node
*/
public Yaml.Node? next_sibling ()
{
return !this.has_parent () ? null : this.parent.child_next_sibling (this as Yaml.Node);
}
/**
* get previous sibling node
*/
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 levelUpdate flag indicating if update level is needed
*/
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;
}
/**
* coutn childs. return 0
*/
public virtual int count ()
{
return 0;
}
/**
*
*/
protected virtual void set_anchor_id (string id)
{
this.anchor = id;
}
}

View File

@ -0,0 +1,138 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Gee;
using Pluie;
/**
* abstract class representing a node
*/
public abstract class Pluie.Yaml.AbstractNode : GLib.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 type the NODE_TYPE of Yaml.Node to create
* @param name the node name
*/
public AbstractNode (Yaml.NODE_TYPE type = Yaml.NODE_TYPE.UNDEFINED, string? name = null)
{
this.with_name(type, name);
}
/**
* @param type the NODE_TYPE of Yaml.Node to create
* @param name the node name
* @param data the node data
*/
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 node the Yaml.Node node to test
*/
public virtual bool same_node (Yaml.AbstractNode? node)
{
return node != null && node.uuid == this.uuid;
}
/**
* get a presentation string of current Yaml.Node
* @param withIndent display indentation formating
* @param withParent display parent node name
* @param withUuid display node uuid
* @param withCount display number of childs
* @param withRefCount display number of reference
* @param withTag display tag information
* @param withType display node type
*/
public virtual string to_string (
bool withIndent = Yaml.DBG_SHOW_INDENT,
bool withParent = Yaml.DBG_SHOW_PARENT,
bool withUuid = Yaml.DBG_SHOW_UUID,
bool withLevel = Yaml.DBG_SHOW_LEVEL,
bool withCount = Yaml.DBG_SHOW_COUNT,
bool withRefCount = Yaml.DBG_SHOW_REF,
bool withTag = Yaml.DBG_SHOW_TAG,
bool withType = Yaml.DBG_SHOW_TYPE
)
{
return "";
}
/**
* get a gracefull yaml presentation of current Yaml.Node
* @param indent number of space for indentation
* @param show_doc flag indicating if the document start must be print
* @param show_tags flag indicating if tags must be print
* @param show_fullkeys flag indicating if full key definition must be print
*
*/
public string to_yaml_string (
int indent = Yaml.Dumper.DEFAULT_INDENT,
bool show_doc = Yaml.Dumper.SHOW_DOC,
bool show_tags = Yaml.Dumper.SHOW_TAGS,
bool show_fullkeys = Yaml.Dumper.SHOW_FULL_KEYS
)
{
return Yaml.Dumper.dump (
(Yaml.Node) this,
indent,
show_doc,
show_tags,
show_fullkeys
);
}
}

View File

@ -1,279 +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
{
/**
* universal unique identifier
*/
public string uuid { get; internal set; }
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 ();
}
/**
*
*/
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;
}
/**
* 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);
}
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;
}
/**
* 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 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 ("]")
);
}
}

View File

@ -0,0 +1,398 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Gee;
using Pluie;
/**
* a Yaml.Builder class helping to build vala Yaml.Object from Yaml.Node
*/
public class Pluie.Yaml.Builder
{
/**
*
*/
private static GLib.Module? p_module;
/**
*
*/
private static unowned GLib.Module p_open_module ()
{
if (p_module == null) {
p_module = Module.open (null, 0);
}
return p_module;
}
/**
* retriew GLib.Type related to specified vala name
* type must be registered
*/
public static GLib.Type? type_from_string (string name)
{
Type? type = Type.from_name (name.replace(".", ""));
return type;
}
/**
* retriew GLib.Type related to specified vala name
* type may be not registered
* @param name a valid vala identifier name
*/
public static Type type_from_vala (string name)
{
void * s;
p_open_module ();
if (!p_module.symbol (resolve_c_name(@"$(name).get_type"), out s)) {
of.error ("cannot resolve type %s (not found)".printf (name));
}
return ((dlgType) s)();
}
/**
* retriew GLib.Type related to specified tag value.
* Type may not be registered yet
*/
public static Type? type_from_tag (string tagValue)
{
var type = type_from_string (tagValue);
if(type != null && type == Type.INVALID) {
type = type_from_vala (tagValue);
}
return type;
}
/**
*
*/
private static string resolve_c_subname (string name) throws GLib.RegexError
{
MatchInfo? mi = null;
bool update = false;
var reg = new Regex ("([A-Z]{1}[a-z]+)");
string? str = null;
var sb = new StringBuilder();
for (reg.match (name, 0, out mi) ; mi.matches () ; mi.next ()) {
if ((str = mi.fetch (1)) != null && str.length > 0) {
sb.append ("%s%s%s".printf (update ? "_" : "", str[0].tolower ().to_string (), str.substring(1)));
if (!update) update = true;
}
}
return update ? sb.str : name;
}
/**
* retriew corresponding c name related to specified vala name
* @param name a valid vala identifier name
*/
public static string resolve_c_name (string name)
{
string? str = null;
MatchInfo? mi = null;
StringBuilder sb = new StringBuilder ();
bool begin = true;
try {
var reg = new Regex ("([^.]*).?");
for (reg.match (name, 0, out mi) ; mi.matches () ; mi.next ()) {
str = Yaml.Builder.resolve_c_subname(mi.fetch (1));
if (str != null && str.length > 0) {
if (!begin) sb.append_unichar ('_');
else begin = false;
sb.append_unichar (str[0].tolower ());
sb.append (str.substring(1));
}
}
}
catch (RegexError e) {
of.error (e.message, true);
}
return !begin ? sb.str : name;
}
[CCode (has_target = false)]
private delegate Type dlgType();
/**
* Build an Object from a YYaml.Node
* @param node the source Yaml.Node
* @param otype used for recursion only
*/
public static GLib.Object? from_node (Yaml.Node node, Type otype = GLib.Type.INVALID)
{
GLib.Object? obj = null;
Type type = node.tag != null ? type_from_tag (node.tag.value) : otype;
if (type != Type.INVALID) {
Yaml.dbg_action ("vala type founded", "%s (%s)".printf (type.name (), type.to_string ()));
if (type.is_object ()) {
obj = GLib.Object.new (type);
if (type.is_a (typeof (Yaml.Object))) {
(obj as Yaml.Object).set ("yaml_name", node.name);
(obj as Yaml.Object).yaml_construct ();
}
if (node!= null && !node.empty ()) {
GLib.ParamSpec? def = null;
Yaml.Node? scalar = null;
foreach (var child in node) {
if ((def = obj.get_class ().find_property (child.name)) != null) {
Yaml.dbg ("== prop [%s] type is : %s".printf (child.name, def.value_type.name ()));
if (child.ntype.is_single_pair () && (scalar = child.first ()) != null) {
set_from_scalar (ref obj, def.name, def.value_type, scalar.data);
}
else if (child.ntype.is_collection ()) {
set_from_collection (ref obj, type, child, def.value_type);
}
}
else {
of.warn ("property %s not found".printf (child.name));
}
}
}
}
}
if (obj == null) {
of.warn ("searched type not found : %s".printf (type.name ()));
}
else {
if (type.is_a (typeof (Yaml.Object))) {
(obj as Yaml.Object).yaml_init ();
}
}
return obj;
}
/**
*
*/
private static void set_from_collection (ref GLib.Object obj, Type parentType, Yaml.Node node, Type type)
{
Yaml.dbg (" > set_from_collection %s (%s)".printf (node.name, type.name ()));
if (type.is_a (typeof (Yaml.Object)) || Yaml.Register.is_registered_type (parentType, type)) {
(obj as Yaml.Object).populate_from_node (node.name, type, node);
}
else {
of.error ("%s is not registered and cannot be populated".printf (type.name ()));
}
}
/**
*
*/
private static void set_from_scalar (ref GLib.Object obj, string name, GLib.Type type, string data)
{
GLib.Value v = GLib.Value(type);
Yaml.dbg_action ("Auto setting property value %s".printf (of.c (ECHO.MICROTIME).s (type.name ())), name);
Yaml.dbg (data);
if (type.is_a(Type.ENUM))
set_enum_value (ref v, type, data);
else
set_basic_type_value(ref v, type, data);
obj.set_property(name, v);
}
/**
*
*/
public static void set_basic_type_value (ref Value v, GLib.Type type, string data)
{
switch (type)
{
case Type.STRING :
v.set_string(data);
break;
case Type.CHAR :
v.set_schar((int8)data.data[0]);
break;
case Type.UCHAR :
v.set_uchar((uint8)data.data[0]);
break;
case Type.BOOLEAN :
v.set_boolean (data == "1" || data.down () == "true");
break;
case Type.INT :
v.set_int(int.parse(data));
break;
case Type.UINT :
v.set_uint((uint)long.parse(data));
break;
case Type.LONG :
case Type.INT64 :
v.set_long((long)int64.parse(data));
break;
case Type.ULONG :
case Type.UINT64 :
v.set_ulong((ulong)uint64.parse(data));
break;
case Type.FLOAT :
v.set_float((float)double.parse(data));
break;
case Type.DOUBLE :
v.set_double(double.parse(data));
break;
}
}
/**
*
*/
public static string? get_basic_type_value (GLib.Object obj, GLib.Type type, string name)
{
GLib.Value v = GLib.Value(Type.STRING);
switch (type)
{
case Type.STRING :
string s;
obj.get (name, out s);
v = s;
break;
case Type.CHAR :
char c;
obj.get (name, out c);
v = c.to_string ();
break;
case Type.UCHAR :
uchar c;
obj.get (name, out c);
break;
case Type.UINT64 :
case Type.UINT :
uint64 i;
obj.get (name, out i);
break;
case Type.INT64 :
case Type.INT :
int64 i;
obj.get (name, out i);
v = i.to_string ();
break;
case Type.BOOLEAN :
bool b;
obj.get (name, out b);
v = b.to_string ();
break;
case Type.DOUBLE :
double d;
obj.get (name, out d);
v = "%g".printf (d);
break;
case Type.FLOAT :
float f;
obj.get (name, out f);
v = "%f".printf (f);
break;
}
return (string) v;
}
/**
*
*/
private static void set_enum_value (ref Value v, GLib.Type type, string data)
{
EnumClass kenum = (EnumClass) type.class_ref();
unowned EnumValue? enumval = kenum.get_value_by_name(data);
if (enumval == null) {
enumval = kenum.get_value_by_nick(data.down());
int64 e = 0;
if(enumval == null) {
if(!int64.try_parse(data, out e)) {
Dbg.error ("invalid enum value %s".printf(data), Log.METHOD, Log.LINE);
}
else enumval = kenum.get_value((int)e);
}
}
v.set_enum(enumval.value);
//~ of.echo ("enumValue : %d".printf (enumval.value));
}
private static string transform_param_name (string name)
{
return name.replace("-", "_");
}
/**
*
*/
private static Yaml.Tag add_tag (GLib.Type type)
{
return new Yaml.Tag (Yaml.Register.resolve_namespace_type(type), Yaml.YAML_VALA_PREFIX);
}
/**
* transform an Yaml.Object to his corresponding Yaml.Node
* @param obj the obj to transform
* @param parent the parent node
* @param root indicates if node must be add to a root node, if true a Yaml.Root node is return
* @param index for sequence entry anonymous mapping block
* @param property_name name of property name related to obj
*/
public static Yaml.Node to_node (GLib.Object obj, Yaml.Node? parent = null, bool root = true, int? index = null, string? property_name = null)
{
string node_name = "";
if (obj.get_type ().is_a (typeof (Yaml.Object))) {
node_name = (obj as Yaml.Object).yaml_name;
}
else {
node_name = parent.ntype.is_sequence () && index != null ? "_%d".printf (index+1) : (property_name != null ? property_name : obj.get_type ().name ());
}
var node = new Yaml.Mapping (parent, node_name);
string? name = null;
foreach (var def in obj.get_class ().list_properties ()){
name = Yaml.Builder.transform_param_name(def.name);
if (name != null && name != "yaml_name") {
if (def.value_type.is_a (typeof (Yaml.Object)) || Yaml.Register.is_registered_type(obj.get_type (), def.value_type)) {
var child = (obj as Yaml.Object).populate_to_node(name, def.value_type, node);
if (child != null) {
child.tag = Yaml.Builder.add_tag (def.value_type);
node.add (child);
}
}
else if (def.value_type.is_enum ()) {
EnumValue enumval;
obj.get (name, out enumval);
string data = enumval.value.to_string ();
var n = new Yaml.Mapping.with_scalar (node, name, (string) data);
n.tag = Yaml.Builder.add_tag (def.value_type);
}
else if (def.value_type.is_fundamental ()) {
string data = Yaml.Builder.get_basic_type_value(obj, def.value_type, name);
if (data != null) {
new Yaml.Mapping.with_scalar (node, name, (string) data);
}
}
else {
of.error ("type %s for property %s is not registered".printf (def.value_type.name (), name));
}
}
}
node.tag = Yaml.Builder.add_tag (obj.get_type ());
return root ? new Yaml.Root(null, true, node) : node;
}
}

View File

@ -0,0 +1,92 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Gee;
using Pluie;
/**
* interface representing a collection node
*/
public interface Pluie.Yaml.Collection
{
/**
* retriew a child node throught specifiyed index
* @param index index of searched child
* @return the matching child node
*/
public abstract Yaml.Node? item (int index);
/**
* check if current node contains the specifiyed child node
* @param child the child to check
*/
public abstract bool contains (Yaml.Node child);
/**
* count children
*/
public abstract int count ();
/**
* check if empty
*/
public abstract bool empty ();
/**
* get a Yaml.Node Iterator
*/
public abstract Gee.Iterator<Yaml.Node> iterator ();
/**
* retriew the first child
* @return the first child node
*/
public abstract Yaml.Node? first ();
/**
* retriew the last child
* @return the last child node
*/
public abstract Yaml.Node? last ();
/**
* retriew the next sibling of specifiyed child node
* @param child the the reference child node
*/
public abstract Yaml.Node? child_next_sibling (Yaml.Node child);
/**
* retriew the previous sibling of specifiyed child node
* @param child the the reference child node
*/
public abstract Yaml.Node? child_previous_sibling (Yaml.Node child);
}

View File

@ -1,53 +1,135 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
/**
* a class to manage Yaml configuration files
* Yaml.Config class to manage Yaml configuration files and provide a Yaml.Root node.
*
* Yaml.Config use a Yaml.Finder to easily retriew a particular node. <<BR>>
* The Yaml.Config.get method is bind to the Yaml.Finder.find method with <<BR>>
* the root node as context. (more details on {@link Yaml.Finder})
*
* {{{
* var config = new Yaml.Config (path);
* var node = config.get ("ship-to.address.city{0}");
* if (node != null) {
* of.echo (node.data)
* }
* }}}
*
* You can use a special import clause to embed a set of yaml files into your current document.
*
* {{{
* # | use special key word '^imports' to import other yaml config files in
* # | current yaml document
* # | '^imports' must be uniq and a direct child of root node
* # | imported files are injected as mapping nodes at top document level
* # | so you cannot use keys that already exists in the document
* ^imports :
* # you can redefine default import path with the special key '^path'
* # if you do not use it, the default path value will be the current directory
* # redefined path values are relative to the current directory (if a relative path
* # is provided)
* ^path : ./config
* # you can also define any other var by prefixing key with ^
* ^dir : subdir
* # and use it enclosed by ^
* # here final test path will be "./config/subdir/test.yml"
* test : ^dir^/test.yml
* # here final db path will be "./config/db.yml"
* db : db.yml
* }}}
*
* {{doc/img/pluie-yaml-imports2.png}}
*/
public class Pluie.Yaml.Config
{
const char IMPORTS_SPE = '^';
/**
* special char use in imports clause & imports var
*/
const char IMPORTS_SPE = '^';
/**
* current path
*/
public string? path { get; internal set; default = null; }
public string? path { get; internal set; default = null; }
/**
*
*/
public bool display_file { get; internal set; }
/**
* Yaml Loader
*/
public Yaml.Loader loader { internal get; internal set; }
public Yaml.Loader loader { internal get; internal set; }
/**
* Yaml Finder
*/
public Yaml.Finder finder { internal get; internal set; }
public Yaml.Finder finder { internal get; internal set; }
/**
* imports var
*/
Gee.HashMap<string, string> varmap { get; internal set; }
Gee.HashMap<string, string> varmap { get; internal set; }
/**
* imports paths
*/
Gee.HashMap<string, string> paths { get; internal set; }
Gee.HashMap<string, string> paths { get; internal set; }
/**
* construct a Yaml Config for specifiyed path
* @param path the yaml path file to load
* @param display_file flag to display file
* @param mode Yaml.FIND_MODE to apply to finder
*/
public Config (string? path = null, bool displayFile = false, Yaml.FIND_MODE mode = Yaml.FIND_MODE.DOT)
public Config (string? path = null, bool display_file = false, Yaml.FIND_MODE mode = Yaml.FIND_MODE.DOT)
{
Yaml.BaseNode.mode = mode;
Yaml.MODE = mode;
this.path = path;
this.display_file = display_file;
if (this.path != null) {
this.loader = new Yaml.Loader (this.path, displayFile, false);
Yaml.NodeRoot? root = this.loader.get_nodes ();
if (root != null) {
this.finder = new Yaml.Finder(root);
this.get_imports ();
this.loader = new Yaml.Loader (this.path, display_file, false);
if (this.loader.done) {
Yaml.Node? root = this.loader.get_nodes ();
if (root != null) {
this.finder = new Yaml.Finder(root);
this.get_imports ();
}
}
}
}
/**
* find node matching specifiyed keyPath
* see {@link Yaml.Finder} for precisions
*/
public new Yaml.Node? get (string keyPath)
{
@ -59,22 +141,22 @@ public class Pluie.Yaml.Config
}
/**
*
* retriew the corresponding Yaml.Root node for loaded yaml file
*/
public Yaml.NodeRoot root_node ()
public Yaml.Root? root_node ()
{
return this.finder.context as Yaml.NodeRoot;
return this.finder!=null ? this.finder.context as Yaml.Root : null;
}
/**
* find node matching specifiyed keyPath
*
*/
public void get_imports ()
protected 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")) {
@ -84,18 +166,7 @@ public class Pluie.Yaml.Config
}
}
this.update_var (node, dir);
foreach(var entry in this.paths.entries) {
var config = new Yaml.Config(entry.value);
Yaml.NodeMap sub = config.loader.get_nodes ();
Yaml.NodeMap n = new Yaml.NodeMap (root, entry.key);
foreach(var subnode in sub.map.values) {
subnode.parent = null;
n.add(subnode);
}
root.add (n);
}
root.update_level();
this.import_files(root);
}
}
}
@ -103,24 +174,36 @@ public class Pluie.Yaml.Config
/**
*
*/
private void update_var (Yaml.NodeMap node, string path)
private void import_files (Yaml.Node root)
{
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.display_file);
sub = conf.loader.get_nodes ();
n = new Yaml.Mapping (root, entry.key);
foreach(var subnode in sub.list) {
subnode.parent = null;
n.add(subnode);
}
}
}
/**
*
*/
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);
}
// update var
foreach (var v in this.varmap.entries) {
if (v.key != "path") {
entry.value.data = val.replace ("^%s^".printf (v.key), v.value);
this.paths[entry.key] = entry.value.data;
of.keyval (entry.key, entry.value.data);
}
}
this.paths[(string)child.name] = val;
this.resolve_var (child.name, val);
}
}
}
@ -128,13 +211,26 @@ public class Pluie.Yaml.Config
/**
*
*/
private void get_imports_var (Yaml.NodeMap node)
private void resolve_var (string key, string val)
{
foreach (var v in this.varmap.entries) {
if (v.key != "path") {
this.paths[key] = val.replace ("^%s^".printf (v.key), v.value);
Yaml.dbg_keyval (key, this.paths[key]);
}
}
}
/**
*
*/
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);
}
}
}

View File

@ -1,48 +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.Document : 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 Document (Yaml.Node? parent = null, string? name = null, string? data = null)
{
this.standard (null, NODE_TYPE.ROOT);
this.name = "PluieYamlRootNode";
}
}

View File

@ -0,0 +1,232 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Gee;
using Pluie;
/**
* a Yaml.Dumper to dump a Yaml.Node to his file representation
*/
public class Pluie.Yaml.Dumper
{
/**
* default number space indentation to apply for all nodes. default : 4
*/
public static int DEFAULT_INDENT { get; internal set; default = 4; }
/**
* flag indicating if the document start must be print
*/
public static bool SHOW_DOC { get; internal set; default = true; }
/**
* flag indicating if tags must be print
*/
public static bool SHOW_TAGS { get; internal set; default = true; }
/**
* flag indicating if full key definition must be print
*/
public static bool SHOW_FULL_KEYS { get; internal set; default = false; }
/**
* flag indicating if enable printing colors
*/
static bool SHOW_COLOR { get; internal set; default = false; }
/**
* flag indicating if line number must be print
*/
static bool SHOW_LINE { get; internal set; default = false; }
/**
* a line counter
*/
static int line { get; internal set; default = 0; }
/**
*
*/
internal Dumper ()
{
}
/**
* get a gracefull yaml presentation of current Yaml.Node
* @param node the node to dump
* @param show_line flag indicating if line number must be print
* @param show_color flag indicating if enable printing colors
* @param show_tags flag indicating if tags must be print
* @param show_doc flag indicating if the document start must be print
* @param indent number of space for indentation
* @param show_fullkeys flag indicating if full key definition must be print
*/
public static void show_yaml_string (
Yaml.Node? node,
bool show_line = true,
bool show_color = true,
bool show_tags = Yaml.Dumper.SHOW_TAGS,
bool show_doc = Yaml.Dumper.SHOW_DOC,
int indent = Yaml.Dumper.DEFAULT_INDENT,
bool show_fullkeys = Yaml.Dumper.SHOW_FULL_KEYS
)
{
SHOW_LINE = show_line;
SHOW_COLOR = show_color;
string yaml = dump (node, indent, show_doc, show_tags, show_fullkeys);
SHOW_LINE = false;
SHOW_COLOR = false;
of.action ("Yaml string representation for", node!= null ? node.name : "null");
print ("%s%s%s", "\n", yaml, "\n");
}
/**
* get a yaml presentation of specified Yaml.Node
* @param node the node to dump
* @param indent number of space for indentation
* @param show_doc flag indicating if the document start must be print
* @param show_tags flag indicating if tags must be print
* @param show_fullkeys flag indicating if full key definition must be print
*/
public static string dump (
Yaml.Node? node,
int indent = Yaml.Dumper.DEFAULT_INDENT,
bool show_doc = Yaml.Dumper.SHOW_DOC,
bool show_tags = Yaml.Dumper.SHOW_TAGS,
bool show_fullkeys = Yaml.Dumper.SHOW_FULL_KEYS
)
{
var yaml = new StringBuilder("");
if (node != null) {
if (node.ntype.is_root ()) {
line = 0;
yaml_root (ref yaml, node as Yaml.Root, show_doc);
foreach (var child in node) {
yaml.append (Yaml.Dumper.dump (child, indent, show_doc, show_tags, show_fullkeys));
}
}
else if (node.ntype.is_single_pair ()) {
yaml_key (ref yaml, node, indent, show_tags);
yaml_scalar (ref yaml, node.first (), indent, show_tags);
}
else if (node.ntype.is_collection ()) {
yaml_key (ref yaml, node, indent, show_tags);
foreach (var child in node) {
yaml.append (Yaml.Dumper.dump (child, indent, show_doc, show_tags, show_fullkeys));
}
}
else if (node.ntype.is_scalar ()) {
yaml_scalar (ref yaml, node, indent, show_tags);
}
}
line++;
return yaml.str;
}
/**
*
*/
private static void yaml_indent (ref StringBuilder yaml, Yaml.Node node, int indent, bool wrapchild = false)
{
yaml.append("%s%s".printf (
! SHOW_LINE ? "" : of.c (ECHO.NUM).s ("%03d %s".printf (line, of.c (ECHO.FILE).s ("|"))),
string.nfill ((node.level-1) * indent - (wrapchild ? 2 : 0), ' ')
));
}
/**
*
*/
private static void yaml_tag (ref StringBuilder yaml, Yaml.Node node, bool show_tags)
{
if (node.tag != null && show_tags) {
if (SHOW_COLOR) yaml.append (of.c (ECHO.COMMAND).to_string ());
yaml.append ("!%s!%s".printf (
node.tag.handle,
node.tag.value
));
yaml.append ("%s ".printf (SHOW_COLOR ? Color.off () : ""));
}
}
/**
*
*/
private static void yaml_root (ref StringBuilder yaml, Yaml.Root node, bool show_doc)
{
yaml.append(! SHOW_LINE ? "" : of.c (ECHO.NUM).s ("%03d %s".printf (line++, of.c (ECHO.FILE).s ("|"))));
yaml.append("%YAML %s\n".printf (Yaml.YAML_VERSION));
foreach (var entry in node.tag_directives.entries) {
yaml.append(! SHOW_LINE ? "" : of.c (ECHO.NUM).s ("%03d %s".printf (line++, of.c (ECHO.FILE).s ("|"))));
yaml.append ("%TAG %s %s\n".printf (entry.key, entry.value));
}
if (show_doc) {
yaml.append(! SHOW_LINE ? "" : of.c (ECHO.NUM).s ("%03d %s".printf (line++, of.c (ECHO.FILE).s ("|"))));
yaml.append ("---\n");
}
}
/**
*
*/
private static void yaml_key (ref StringBuilder yaml, Yaml.Node node, int indent, bool show_tags)
{
bool wrapseq = node.parent.ntype.is_sequence () && node.ntype.is_mapping () && node.name[0]=='_';
bool childwrap = node.parent != null && node.parent.parent != null && node.parent.parent.ntype.is_sequence () && node.parent.ntype.is_mapping () && node.parent.name[0]=='_';
if (!childwrap) yaml_indent (ref yaml, node, indent);
else if (!node.is_first ()) {
yaml_indent (ref yaml, node, indent, true);
}
if (node.parent != null && node.parent.ntype.is_sequence ()) yaml.append (!SHOW_COLOR ? "- " : of.c (ECHO.DATE).s ("- "));
if (wrapseq) {
if (Yaml.DEBUG) of.warn ("node %s wrapseq ? %s".printf (node.name, wrapseq.to_string ()));
}
yaml_tag (ref yaml, node, show_tags);
if (!wrapseq) {
int len = 0;
foreach (var child in node.parent) {
if (child.name.length > len) len = child.name.length;
}
len = (!show_tags || (node.tag == null && !node.ntype.is_collection ()) && len > 0) ? len +1 - node.name.length : 0;
yaml.append("%s%s%s".printf(
!SHOW_COLOR ? @"%s%$(len)s ".printf (node.name, " ") : of.c (node.ntype.is_collection() ? ECHO.TIME : ECHO.OPTION).s(@"%s%$(len)s".printf (node.name, " ")),
!SHOW_COLOR ? ":" : of.c (ECHO.DATE).s(":"),
node.ntype.is_collection () ? "\n" : " "
));
}
}
/**
*
*/
private static void yaml_scalar (ref StringBuilder yaml, Yaml.Node node, int indent, bool show_tags)
{
if (!(node.parent !=null && node.parent.ntype.is_single_pair ())) yaml_indent (ref yaml, node, indent);
if (node.parent != null && node.parent.ntype.is_sequence ()) yaml.append (!SHOW_COLOR ? "- " : of.c (ECHO.DATE).s ("- "));
yaml_tag (ref yaml, node, show_tags);
yaml.append ("%s\n".printf (
!SHOW_COLOR ? node.data : of.c (ECHO.OPTION_SEP).s (node.data)
));
}
}

View File

@ -1,38 +1,39 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* @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
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* lib-yaml is distributed in the hope that it will be useful, but WITHOUT
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*
* You should have received a copy of the GNU General Public License
* along with lib-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Gee;
using Pluie;
/**
* Yaml Event class
* Yaml Event class populated by {@link Yaml.Scanner} and treat by the {@link Yaml.Processor} to
* build a {@link Yaml.Node} from a yaml.file
*/
public class Pluie.Yaml.Event
{
@ -55,7 +56,10 @@ public class Pluie.Yaml.Event
/**
* construct a Event
* @param path the path to load
* @param evtype the Yaml.EVT event
* @param line original yaml line of related event
* @param style original yaml style
* @param data data related to event
*/
public Event (Yaml.EVT evtype, int line=0, int? style=null, Gee.HashMap<string, string>? data=null)
{

View File

@ -1,40 +1,53 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* @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
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* lib-yaml is distributed in the hope that it will be useful, but WITHOUT
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*
* You should have received a copy of the GNU General Public License
* along with lib-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
* along with pluie-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
* Finder class used to easily retriew Yaml.Node
*
* Path definition has two mode :
* default mode is ''Yaml.FIND_MODE.DOT''
*
* * child mapping node are separated by dot :
* * sequence entry must be enclosed in curly brace
* ex : ``grandfather.father.son{2}.age``
*
* other mode is ''Yaml.FIND_MODE.SQUARE_BRACKETS''.
*
* * node's key name must be enclosed in square brackets
* * sequence entry must be enclosed in curly brace
* ex : ``[grandfather][father][son]{2}[age]``
*/
public class Pluie.Yaml.Finder : Object
public class Pluie.Yaml.Finder : GLib.Object
{
/**
@ -44,25 +57,76 @@ public class Pluie.Yaml.Finder : Object
/**
* default Yaml.Finder constructor
* @param default Yaml.Node context
* @param context default Yaml.Node context
*/
public Finder (Yaml.Node context)
{
this.context = context;
}
/**
* Find a specific child Yaml.Node corresponding to path definition.
*
* @param path the definition to retriew the child node
* @param context the Yaml.Node context to operate
*/
public Yaml.Node? find (string path, Yaml.Node? context = null)
{
string search = this.find_path (path);
bool match = false;
Yaml.Node? node = context == null ? this.context : context;
Regex reg = /(\[|\{)([^\]\}]*)(\]|\})/;
MatchInfo mi;
try {
//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)));
if (this.is_collection_path (mi)) {
if (!match) match = true;
if (this.is_collection_path (mi, true)) {
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.empty() && node.first().ntype.is_scalar ()) {
node = node.first ();
}
// assume sequence
else {
var n = node as Yaml.Sequence;
if (n != null && !n.empty () && index >= 0 && index < n.count ()) {
node = n.list.get (index);
}
else node = null;
}
}
if (node == null) break;
}
}
}
catch (RegexError e) {
of.error (e.message);
}
if (!match) node = null;
return node;
}
/**
* get a path definition depending of current Node.mode
* if path definition is Yaml.FIND_MODE.DOT the path is convert to a
* Yaml.FIND_MODE.SQUARE_BRACKETS path definition
* @path the path definition
* @param path the path definition
* @return the find path definition according to current Node.mode
*/
private string find_path (string path)
{
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() != "") {
@ -83,7 +147,8 @@ public class Pluie.Yaml.Finder : Object
/**
* indicates if specifiyed MatchInfo is related to a mapping node only or a collection node
* @param mi
* @param mi used MathInfo
* @param mappingOnly flag indicates if mappu only
*/
private bool is_collection_path (MatchInfo mi, bool mappingOnly = false)
{
@ -91,59 +156,4 @@ public class Pluie.Yaml.Finder : Object
(mi.fetch (FIND_COLLECTION.OPEN) == "{" && mi.fetch (FIND_COLLECTION.CLOSE) == "}"));
}
/**
* find a specific child Yaml.Node corresponding to path definition
* path definition has two mode.
* default mode is Yaml.FIND_MODE.SQUARE_BRACKETS
* node's key name must be enclosed in square brackets
* sequence entry must be enclosed in curly brace
* ex : [grandfather][father][son]{2}
*
* other mode is Yaml.FIND_MODE.DOT
* child mapping node are separated by dot :
* ex : grandfather.father.son{2}
* @param path the definition to retriew the child node
*/
public Yaml.Node? find (string path, Yaml.Node? context = null)
{
string search = this.find_path (path);
bool match = false;
Yaml.Node? node = context == null ? this.context : context;
Regex reg = /(\[|\{)([^\]\}]*)(\]|\})/;
MatchInfo mi;
try {
//~ 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)));
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)];
}
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 ();
}
// assume sequence
else {
var n = node as Yaml.NodeSequence;
if (index < n.list.size && index >= 0) {
node = n.list.get (index);
}
else node = null;
}
}
if (node == null) break;
}
}
}
catch (RegexError e) {
of.error (e.message);
}
if (!match) node = null;
return node;
}
}

View File

@ -0,0 +1,107 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Gee;
using Pluie;
/**
* a Yaml.GeeBuilder class helping to build vala Gee.Collection with fundamental type to Yaml.Node
*/
public class Pluie.Yaml.GeeBuilder
{
/**
* transform a Gee.Collection with fundamental type to a Yaml.Node
* @param property_name name of related property
* @param parent parent Yaml.Node of the list
* @param is_char flag indicating data with char representation
*/
public static Yaml.Node? fundamental_arraylist_to_node (Gee.ArrayList* o, string property_name, Yaml.Node parent, bool is_char = false)
{
Yaml.dbg_action ("prop %s (type %s) has element type :".printf (property_name, o->get_type ().name ()), o->element_type.name ());
Yaml.Node? node = null;
var type = o->element_type;
if (!type.is_object () && type.is_fundamental ()) {
node = new Yaml.Sequence (parent, property_name);
var it = o->iterator();
while (it.next ()) {
string data = "";
if (is_char && (type == typeof (unichar) || type == typeof (uchar))) {
void* d = (void*) it.get ();
data = ((unichar) d).to_string();
}
else {
switch (type) {
case Type.LONG :
case Type.INT64 :
int64* d = (int64*) it.get ();
data = d.to_string ();
break;
case Type.INT :
data = ((int64) it.get ()).to_string ();
break;
case Type.CHAR :
data = ((char) it.get ()).to_string ();
break;
case Type.UCHAR :
data = "%u".printf (((uint) it.get ()));
break;
case Type.ULONG :
case Type.UINT64 :
uint64* d = (uint64*) it.get ();
data = d.to_string ();
break;
case Type.UINT :
data = "%u".printf ((uint) it.get ());
break;
case Type.BOOLEAN :
data = ((bool) it.get ()).to_string ();
break;
case Type.FLOAT :
float* f = (float*) it.get ();
data = f.to_string ();
break;
case Type.DOUBLE :
var d = (double*) it.get ();
data = "%g".printf (double.parse(d.to_string ()));
break;
default :
data = (string) it.get ();
break;
}
}
new Yaml.Scalar (node, data);
}
}
else {
of.error ("in %s : Gee.ArrayList.element_type (%s) is not a fundamental type".printf (Log.METHOD, type.name ()));
}
return node;
}
}

View File

@ -1,31 +1,31 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* @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
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* lib-yaml is distributed in the hope that it will be useful, but WITHOUT
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*
* You should have received a copy of the GNU General Public License
* along with lib-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Gee;
@ -37,97 +37,139 @@ using Pluie;
public class Pluie.Yaml.Loader
{
/**
* Scanner
* Flag PACK_NESTED_ENTRIES
*/
Yaml.Scanner scanner { public get; internal set; }
public static bool PACK_NESTED_ENTRIES { public get; public set; default = false; }
/**
* Yaml.Scanner used to retriew yaml events
*/
Yaml.Scanner scanner { public get; internal set; }
/**
* indicate if file has been sucessfully loaded
*/
public bool done { get; internal set; }
public bool done { get; internal set; }
/**
* Reader used to load content yaml file
*/
Io.Reader reader;
Io.Reader reader;
/**
* default constructor of Yaml.Loader
* @param path the path of file to parse
* @param displayFile display original file
* @param display_file display original file
* @param displayNode display corresponding Yaml Node Graph
*/
public Loader (string path, bool displayFile = false, bool displayNode = false )
public Loader (string path, bool display_file = false, bool displayNode = false )
{
this.reader = new Io.Reader (path);
if (displayFile) {
this.displayFile ();
}
this.scanner = new Yaml.Scanner (path);
if ((this.done = this.scanner.run()) && displayNode) {
var n = this.get_nodes ();
if (n != null) {
n.display_childs ();
if (this.reader.readable) {
this.scanner = new Yaml.Scanner (path);
if (display_file) this.display_file ();
if ((this.done = this.scanner.run())) {
if (displayNode) {
var n = this.get_nodes ();
if (n != null) n.display_childs ();
of.state(n != null);
}
}
else {
var evt = this.scanner.get_error_event ();
of.error ("line %d (%s)".printf (evt.line, evt.data["error"]));
this.display_file (evt.line);
}
of.state(n != null);
}
if (!this.done) {
var evt = this.scanner.get_error_event ();
of.error ("line %d (%s)".printf (evt.line, evt.data["error"]));
this.displayFile (evt.line);
}
}
/**
* return resulting Yaml root node
*/
public Yaml.NodeRoot get_nodes ()
public Yaml.Node? get_nodes ()
{
return this.scanner.get_nodes ();
Yaml.Node? n = this.scanner.get_nodes ();
if (PACK_NESTED_ENTRIES) {
this.pack_entries (n);
}
return n;
}
/**
*
*/
private void pack_entries (Yaml.Node? node = null)
{
bool restart = false;
if (node != null) {
if (node.ntype.is_sequence ()) {
foreach (var child in node) {
if (child.ntype.is_mapping () && child.name[0] == '_' && child.count () == 1) {
var sub = child.first ().clone_node ();
node.replace_node (child, sub);
restart = true;
break;
}
}
if (restart) pack_entries (node);
}
else foreach (var child in node) this.pack_entries (child);
}
}
/**
* display original file
* @param errorLine highlight error line
*/
public void displayFile (int errorLine = 0)
public void display_file (int errorLine = 0)
{
of.action (errorLine == 0 ? "Reading file" : "Invalid Yaml File", this.reader.path);
of.echo ();
this.reader.rewind(new Io.StreamLineMark(0, 0));
int line = 0;
string? data = null;
int line = 0;
string? data = null;
bool err = false;
bool before = false;
while (this.reader.readable) {
line = this.reader.line + 1;
data = this.reader.read ();
if (errorLine > 0 && line > 0) {
if (line < errorLine - 7) continue;
else if (line == errorLine - 7) {
of.echo ("%s%s%s".printf (
of.c (ECHO.MICROTIME ).s (" %03d ".printf (line-1)),
of.c (ECHO.DATE).s ("| "),
of.c (ECHO.COMMAND).s ("... ")
));
}
}
if (data !=null) {
ECHO color = data.strip()[0] != '#' ? ECHO.COMMAND : ECHO.COMMENT;
of.echo ("%s%s%s".printf (
of.c (ECHO.MICROTIME ).s (" %03d ".printf (line)),
of.c (ECHO.DATE).s ("| "),
errorLine > 0 && line == errorLine
? of.c (ECHO.FAIL).s (data)
: of.c (color).s (data)
), errorLine == 0 || line < errorLine);
}
if (errorLine > 0 && line == errorLine) {
line = this.reader.line + 1;
data = this.reader.read ();
err = errorLine > 0 && line == errorLine;
before = errorLine == 0 || line < errorLine;
if (this.bypass_ellipse (errorLine, line)) continue;
ECHO color = data!=null && data.strip()[0] != '#' ? ECHO.COMMAND : ECHO.COMMENT;
of.echo ("%s%s%s".printf (
of.c (ECHO.MICROTIME ).s (" %03d ".printf (line)),
of.c (ECHO.DATE).s ("| "),
err ? of.c (ECHO.FAIL).s (data)
: of.c (color).s (data)
), before);
if (err) {
int len = of.term_width - data.length - 13;
stdout.printf (of.c (ECHO.FAIL).s (@" %$(len)s ".printf (" ")));
of.echo (Color.off (), true);
}
if (errorLine > 0 && line > errorLine) {
break;
}
else if (!before) break;
}
of.echo (errorLine == 0 ? "EOF" : "");
of.state (errorLine == 0);
}
/**
* bypass_ellipse
*/
private bool bypass_ellipse (int errorLine, int line)
{
bool bypass = false;
if (errorLine > 0 && line > 0) {
if (line < errorLine - 7) bypass = true;
else if (line == errorLine - 7 && line > 1) {
of.echo ("%s%s%s".printf (
of.c (ECHO.MICROTIME ).s (" %03d ".printf (line-1)),
of.c (ECHO.DATE).s ("| "),
of.c (ECHO.COMMAND).s ("... ")
));
}
}
return bypass;
}
}

View File

@ -0,0 +1,154 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using 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; }
/**
* default Yaml.Mapping constructor
* @param parent the parent node
* @param name the node name
*/
public Mapping (Yaml.Node? parent = null, string? name = null)
{
base (parent, NODE_TYPE.MAPPING, name);
this.keys = new ArrayList<string> ();
}
/**
* Yaml.Mapping constructor as single pair node with scalar data
* @param parent the parent node
* @param name the node name
* @param data scalar data
*/
public Mapping.with_scalar (Yaml.Node? parent = null, string? name = null, string? data = null)
{
base (parent, NODE_TYPE.SINGLE_PAIR, name);
var s = new Scalar (null, data);
this.add (s);
}
/**
* {@inheritDoc}
*/
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);
}
}
}
/**
* {@inheritDoc}
*/
protected override void on_added (Yaml.Node child)
{
base.on_added (child);
if (this.keys != null) {
if (!this.ntype.is_single_pair () && this.keys.size == 0 && child.ntype.is_scalar ()) {
this.ntype = Yaml.NODE_TYPE.SINGLE_PAIR;
}
this.keys.add(child.name);
}
}
/**
* {@inheritDoc}
*/
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 name
* @param name name of searched child
* @return the matching 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;
}
/**
* {@inheritDoc}
*/
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;
}
/**
* get a collection of chils name
*/
public Gee.ArrayList<string>? child_names ()
{
return this.keys;
}
}

View File

@ -1,123 +1,349 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* @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
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* lib-yaml is distributed in the hope that it will be useful, but WITHOUT
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*
* You should have received a copy of the GNU General Public License
* along with lib-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Pluie;
using Gee;
public interface Pluie.Yaml.Node : Object
/**
* a class representing a yaml node no matter was his type
*/
public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
{
/**
* universal unique identifier
* Yaml.Node collection
*/
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
* @param name the node name
*/
public abstract Yaml.NODE_TYPE node_type { get; internal set; }
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; }
/**
* 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 Node (Yaml.Node? parent = null, Yaml.NODE_TYPE type = Yaml.NODE_TYPE.UNDEFINED, string? name = null)
{
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
* @param node the Yaml.Node child to add
*/
public abstract string? val ();
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);
Yaml.dbg (this.to_string ());
this.display_childs ();
}
return done;
}
/**
* stuff on changing parent node
* @param child the childto add
* actions to execute before adding the specified child bode
* @param child the Yaml.Node child to add
*/
protected abstract bool on_change_parent ();
protected virtual void before_add (Yaml.Node child) throws Yaml.AddNodeError
{
}
/**
* actions to execute after adding the specified child bode
* @param child the Yaml.Node child to add
*/
protected virtual void on_added (Yaml.Node child)
{
this.update_level ();
}
/**
* remove a child
* @param child the child to remove
* @param child the child to remove
* @param levelUpdate flag indacting if level must be updated
*/
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
* action to exectuing after removing the specified child node
* @param child the Yaml.Node child to remove
* @param levelUpdate flag indacting if level must be updated for removed child
*/
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
* {@inheritDoc}
*/
public abstract bool has_child_nodes ();
public virtual Yaml.Node? item (int index)
{
return this.list.get (index);
}
/**
* give the next sibling node
* {@inheritDoc}
*/
public abstract Yaml.Node? next_sibling ();
public bool contains (Yaml.Node child) {
return !this.empty () && this.list.contains (child);
}
/**
* give the previous sibling node
* {@inheritDoc}
*/
public abstract Yaml.Node? previous_sibling ();
public override int count () {
return !this.empty () ? this.list.size : 0;
}
/**
* give the root parent node
* {@inheritDoc}
*/
public abstract Yaml.Node? get_root_node ();
public bool empty () {
return this.list == null || this.list.size == 0;
}
/**
* update node level and all childs level
* {@inheritDoc}
*/
public abstract void update_level ();
public Gee.Iterator<Yaml.Node> iterator () {
return this.list.iterator ();
}
/**
* {@inheritDoc}
*/
public virtual Yaml.Node? first ()
{
return this.list.first ();
}
/**
* {@inheritDoc}
*/
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;
}
/**
* {@inheritDoc}
*/
public Yaml.Node? child_next_sibling (Yaml.Node child)
{
return this.child_sibling (child, true);
}
/**
* {@inheritDoc}
*/
public Yaml.Node? child_previous_sibling (Yaml.Node child)
{
return this.child_sibling (child, false);
}
/**
* update nested indention node level and propagate approprietly level to all childs
*/
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 (with all his children)
* @param name the name of the clone
* @return the cloned node with cloned childs
*/
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;
}
/**
*
*/
internal virtual Yaml.Node get_cloned_instance (string? name = null)
{
return new Yaml.Node (null, this.ntype, name);
}
/**
* retriew the GLib.Value initialized with specified type (only) for single pair node
* return the pair value
*/
public GLib.Value val (GLib.Type type)
{
var v = GLib.Value(type);
if (this.ntype.is_single_pair ()) {
Yaml.Builder.set_basic_type_value (ref v, type, this.first ().data);
}
return v;
}
/**
*
*/
public void replace_node (Yaml.Node child, Yaml.Node new_child)
{
int index = this.list.index_of (child);
if (index > -1) {
new_child.level = this.level + 1;
new_child.parent = this;
new_child.update_level ();
this.list.remove_at (index);
this.list.insert (index, new_child);
}
}
/**
* display childs
* @param withTitle display a title before the childs node presentation
*/
public void display_childs (bool withTitle = true)
{
if (withTitle) {
of.action ("display_childs", this.name);
of.echo ("");
}
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
* @param withIndent display indentation formating
* @param withParent display parent node name
* @param withUuid display node uuid
* @param withCount display number of childs
* @param withRefCount display number of reference
* @param withTag display tag information
* @param withType display node type
*/
public abstract string to_string (bool indentFormat = true, bool withParent = false, bool withUuid = false, bool withIndent = true, bool withRefCount = false);
public override string to_string (
bool withIndent = Yaml.DBG_SHOW_INDENT,
bool withParent = Yaml.DBG_SHOW_PARENT,
bool withUuid = Yaml.DBG_SHOW_UUID,
bool withLevel = Yaml.DBG_SHOW_LEVEL,
bool withCount = Yaml.DBG_SHOW_COUNT,
bool withRefCount = Yaml.DBG_SHOW_REF,
bool withTag = Yaml.DBG_SHOW_TAG,
bool withType = Yaml.DBG_SHOW_TYPE
)
{
return "%s%s%s%s%s%s%s%s%s%s%s".printf (
this.level == 0 ? "" : of.s_indent ((int8) (withIndent ? (this.level-1)*4 : 0)),
of.c (ECHO.OPTION).s ("["),
this.name != null && !this.ntype.is_scalar ()
? of.c (ntype.is_root () ? ECHO.MICROTIME : ECHO.TIME).s ("%s".printf (this.name))
: (
this.ntype.is_scalar ()
? of.c(ECHO.DATE).s ("%s".printf (this.data))
: ""
),
withRefCount ? of.c (ECHO.COMMAND).s ("[%lu]".printf (this.ref_count)) : "",
!withParent || this.parent == null
? withLevel ? of.c (ECHO.NUM).s (" %d".printf (this.level)) : ""
: of.c (ECHO.SECTION).s (" "+this.parent.name)+(
withLevel ? of.c (ECHO.NUM).s (" %d".printf (this.level)) : " "
),
withType ? of.c (ECHO.OPTION_SEP).s (" %s".printf(this.ntype.infos ())) : "",
withCount && this.ntype.is_collection () ? of.c (ECHO.MICROTIME).s (" %d".printf(this.count ())) : "",
withUuid ? of.c (ECHO.COMMENT).s (" %s".printf(this.uuid[0:8]+"...")) : "",
this.tag != null && withTag
? " %s%s".printf (
of.c (ECHO.TITLE).s (" %s ".printf(this.tag.handle)),
of.c (ECHO.DEFAULT).s (" %s".printf(this.tag.value))
)
: "",
of.c (ECHO.OPTION).s ("]"),
withTag && this.ntype.is_root () && (this as Yaml.Root) !=null ? (this as Yaml.Root).get_display_tag_directives () : ""
);
}
}

View File

@ -1,61 +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;
/**
* a class representing a mapping node
*/
public interface Pluie.Yaml.NodeCollection
{
/**
* retriew the previous sibling of specifiyed child node
* @param 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? child_next_sibling (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);
}

View File

@ -1,192 +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 HashMap<string, Yaml.Node> map { 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.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.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.map.size > 0) {
foreach (string key in this.map.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.map.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;
}
/**
* retriew the next sibling of specifiyed child node
* @param child
*/
public virtual Yaml.Node? child_next_sibling (Yaml.Node child)
{
Yaml.Node? target = null;
bool match = false;
if (this.map.size > 0) {
foreach (string key in this.map.keys) {
if (child.name == key) {
match = true;
continue;
}
if (match) {
target = this.map.get(key);
}
}
}
return target;
}
/**
* retriew the previous sibling of specifiyed child node
* @param child
*/
public virtual Yaml.Node? child_previous_sibling (Yaml.Node child)
{
Yaml.Node? target = null;
bool match = false;
if (this.map.size > 0) {
foreach (string key in this.map.keys) {
if (child.name == key) {
match = true;
break;
}
target = this.map.get(key);
}
}
if (!match) {
target = null;
}
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.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;
}
}

View File

@ -1,48 +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.NodeRoot : 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 NodeRoot (Yaml.Node? parent = null, string? name = null, string? data = null)
{
this.standard (null, NODE_TYPE.ROOT);
this.name = "PluieYamlRootNode";
}
}

View File

@ -1,56 +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 scalar node
*/
public class Pluie.Yaml.NodeScalar : Yaml.BaseNode
{
/**
* construct a scalar node
* @param parent the parent node
* @param data the current scalar data
*/
public NodeScalar (Yaml.Node? parent = null, string? data = null)
{
base (parent, NODE_TYPE.SCALAR);
this.data = data;
}
/**
* clone current node
* @param the name of clone
*/
public override Yaml.Node clone_node (string? name = null)
{
return new Yaml.NodeScalar (this.parent, this.data);
}
}

View File

@ -1,214 +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);
}
/**
* retriew the first child node
* @return the first child node
*/
public Yaml.Node first ()
{
return this.list.first ();
}
/**
* retriew the last child node
* @return the last child node
*/
public Yaml.Node last ()
{
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");
}
}
/**
* count childnodes
*/
public 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 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;
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,180 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Gee;
/**
* Yaml.Object base class which can be transform to a Yaml.Node structure
*/
public abstract class Pluie.Yaml.Object : GLib.Object
{
/**
* Yaml node name
*/
public string yaml_name { get; internal set; }
/**
* associated Yaml.Register for tag resolution (full namespace names)
*/
public static Yaml.Register register { get; private set; }
/**
* Yaml.Tag definition
*/
public static Yaml.Tag yaml_tag { get; internal set; }
/**
*
*/
static construct
{
register = new Yaml.Register();
yaml_tag = new Tag (typeof (Pluie.Yaml.Object).name (), "v");
Yaml.Register.add_namespace("Pluie", "Pluie.Yaml");
}
/**
*
*/
public Object ()
{
this.yaml_construct ();
}
/**
* default constructor
*/
public virtual void yaml_construct ()
{
Dbg.msg ("%s (%s) instantiated".printf (this.yaml_name, this.get_type().name ()), Log.LINE, Log.FILE);
}
/**
* initialization method called by Yaml.Builder after instantiation
* and after properties has been populated
*/
public virtual void yaml_init ()
{
Dbg.msg ("%s (%s) initialized".printf (this.yaml_name, this.get_type().name ()), Log.LINE, Log.FILE);
}
/**
* build property name from a Yaml.Node
* @param name name the property to build
* @param type type the property type
* @param node the Yaml.Node source
*/
public virtual signal void populate_from_node (string name, GLib.Type type, Yaml.Node node) {
if (type.is_a(typeof (Yaml.Object))) {
this.set (node.name, Yaml.Builder.from_node(node, type));
}
else {
message ("base Yaml.Object : %s".printf (Log.METHOD));
this.set (node.name, (GLib.Object) Yaml.Builder.from_node(node, type));
}
}
/**
* convert property name to a Yaml.node
* @param name name of the property to build
* @param type type of the property to build
* @param parent parent node of the property
* @return the resulting Yaml.Node
*/
public virtual signal Yaml.Node? populate_to_node (string name, GLib.Type type, Yaml.Node parent) {
Yaml.Node? node = null;
if (type.is_object ()) {
var o = (GLib.Object) GLib.Object.new (type);
this.get (name, out o);
node = Yaml.Builder.to_node (o, parent, false, null, name);
}
return node;
}
/**
* build an object collection (Gee.Collection) to a Yaml.Node
* @param list the gee collection to transform
* @param name name of collection sequence node
* @param parent parent node of the collection
* @return the resulting Yaml.Node
*/
public static Yaml.Node? objects_collection_to_node (Gee.Collection list, string name, Yaml.Node? parent = null)
{
var node = new Yaml.Sequence (parent, name);
node.tag = new Yaml.Tag (Yaml.Register.resolve_namespace_type(list.get_type ()), "v");
var it = list.iterator ();
var i = 0;
while (it.next ()) {
Yaml.Builder.to_node ((GLib.Object) it.get (), node, false, i++);
}
return node;
}
/**
* build an object Gee.HashMap<string, Yaml.Object> to a Yaml.Node
* @param map the gee hashmap to transform
* @param name name of map sequence node
* @param parent parent node of the map
* @return the resulting Yaml.Node
*/
public static Yaml.Node? objects_mapkstr_to_node (Gee.HashMap map, string name, Yaml.Node? parent = null)
{
var node = new Yaml.Sequence (parent, name);
node.tag = new Yaml.Tag (Yaml.Register.resolve_namespace_type(map.get_type ()), "v");
var i = 0;
foreach (var child in map.entries) {
var entryNode = new Yaml.Mapping (node, "_%d".printf (i++));
new Yaml.Mapping.with_scalar (entryNode, "key", (string) child.key);
Yaml.Builder.to_node ((GLib.Object) child.value, entryNode, false, null, "val");
}
return node;
}
/**
* build an object Gee.HashMap<string, Yaml.Object> to a Yaml.Node
* @param map the gee hashmap to transform
* @param name name of map sequence node
* @param parent parent node of the map
* @return the resulting Yaml.Node
*/
public static Yaml.Node? objects_mapobjects_to_node (Gee.HashMap map, string name, Yaml.Node? parent = null)
{
var node = new Yaml.Sequence (parent, name);
node.tag = new Yaml.Tag (Yaml.Register.resolve_namespace_type(map.get_type ()), "v");
var i = 0;
foreach (var child in map.entries) {
var entryNode = new Yaml.Mapping (node, "_%d".printf (i++));
Yaml.Builder.to_node ((GLib.Object) child.key, entryNode, false, null, "key");
Yaml.Builder.to_node ((GLib.Object) child.value, entryNode, false, null, "val");
}
return node;
}
}

View File

@ -1,31 +1,31 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* @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
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* lib-yaml is distributed in the hope that it will be useful, but WITHOUT
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*
* You should have received a copy of the GNU General Public License
* along with lib-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Gee;
@ -41,6 +41,66 @@ public class Pluie.Yaml.Processor
*/
public bool done;
/**
* indicates if new node has been created
*/
bool change;
/**
* indicates if document start begin
*/
bool begin;
/**
* indicates if new node is a sequence entry
*/
bool isEntry;
/**
* indicates if new node is a sequence entry mapping
*/
bool isEntryMapping;
/**
* indicates if begon a flow sequence
*/
bool beginFlowSeq;
/**
*
*/
int indexEvt;
/**
* current anchor id
*/
string? idAnchor;
/**
* current key
*/
string? ckey;
/**
* current key tag
*/
Yaml.Tag? keyTag;
/**
* current key tag
*/
Yaml.Tag? valueTag;
/**
* current tag handle
*/
string? tagHandle;
/**
* current tag handle
*/
Yaml.Event? nextValueEvt;
/**
* Events list
*/
@ -51,6 +111,11 @@ public class Pluie.Yaml.Processor
*/
Gee.HashMap<string, Yaml.Node> anchors { get; internal set; }
/**
* Error event
*/
Yaml.Event? event { get; internal set; }
/**
* Error event
*/
@ -59,7 +124,7 @@ public class Pluie.Yaml.Processor
/**
* the root Yaml.Node
*/
public Yaml.Node root;
public Yaml.Root root;
/**
* current previous Yaml.Node
@ -77,9 +142,9 @@ public class Pluie.Yaml.Processor
Yaml.Node node;
/**
* previous level
* Yaml.Event Iterator
*/
int prev_level;
Gee.Iterator<Yaml.Event> iterator;
/**
*
@ -96,9 +161,10 @@ public class Pluie.Yaml.Processor
public void read ()
{
of.action ("Reading events");
var i = 0;
foreach (Yaml.Event event in this.events) {
int len = 24 - event.evtype.infos ().length;
stdout.printf (" [ %s"+@" %$(len)s "+", %d, %s", event.evtype.infos (), " ", event.line, event.style != null ? event.style.to_string () : "0");
stdout.printf (" %03d [ %s"+@" %$(len)s "+", %d, %s", i++, event.evtype.infos (), " ", event.line, event.style != null ? event.style.to_string () : "0");
if (event.data != null && event.data.size > 0) {
stdout.printf (", {");
var it = event.data.map_iterator ();
@ -113,157 +179,407 @@ public class Pluie.Yaml.Processor
}
}
/**
* retriew the next Yaml Event
* @param the iterator
*/
private Yaml.Event? next_event (Iterator<Yaml.Event> it)
{
Yaml.Event? evt = null;
if (it.has_next () && it.next ()) {
evt = it.get ();
}
return evt;
}
/**
* retriew the next Yaml Value Event closest to Key Event
* @param the iterator
*/
private Yaml.Event? get_value_key_event (Iterator<Yaml.Event> it)
{
Yaml.Event? evt = null;
var e = it.get ();
if (e != null && e.evtype.is_key ()) {
evt = this.next_event (it);
}
return evt;
}
/**
* retriew the next Yaml Value Event
* @param the iterator
*/
private Yaml.Event? get_value_event (Iterator<Yaml.Event> it)
{
Yaml.Event? evt = null;
var e = it.get ();
if (e != null && e.evtype.is_value ()) {
evt = this.next_event (it);
}
return evt;
}
/**
* processing the events list and generate the corresponding Yaml Nodes
*/
public bool run ()
{
if (Pluie.Yaml.Scanner.DEBUG) this.read ();
this.root = new Yaml.NodeRoot ();
this.prev_node = this.root;
this.parent_node = this.root;
this.prev_level = this.root.level;
int level = this.root.level + 1;
var it = this.events.iterator ();
var change = false;
string? key = null;
string? id = null;
bool beginFlowSeq = false;
Yaml.Event? evt;
if (Pluie.Yaml.Scanner.DEBUG) of.action ("Processing events");
for (var has_next = it.next (); has_next; has_next = it.next ()) {
evt = it.get ();
if (evt.evtype.is_error ()) {
error_event = evt;
if (Yaml.DEBUG) this.read ();
Yaml.dbg_action ("Processing events");
this.reset ();
for (var has_next = this.iterator.next (); has_next; has_next = this.iterator.next ()) {
this.event = this.iterator.get ();
Yaml.dbg (" [[[ EVENT %d %s ]]]".printf (this.indexEvt++, this.event.evtype.infos ()));
if (this.event.evtype.is_tag_directive ()) {
this.on_tag_directive ();
}
if (this.event.evtype.is_error ()) {
this.on_error ();
break;
}
if (evt.evtype.is_mapping_end () || evt.evtype.is_sequence_end ()) {
level -= 4;
this.parent_node = this.prev_node.parent != null && this.prev_node.parent != this.root
? this.prev_node.parent.parent
: this.root;
this.prev_node = this.parent_node;
continue;
}
if (evt.evtype.is_entry ()) {
evt = this.next_event(it);
if (evt.evtype.is_mapping_start ()) {
key = "_%d".printf((this.parent_node as Yaml.NodeSequence).get_size());
this.node = new Yaml.NodeMap (this.parent_node, key);
key = null;
level += 1;
change = true;
if (!this.begin) {
if (this.event.evtype.is_sequence_start () || this.event.evtype.is_mapping_start ()) {
this.begin = true;
continue;
}
else if (evt.evtype.is_scalar ()) {
var content = evt.data["data"];
this.node = new Yaml.NodeScalar (this.parent_node, content);
change = true;
}
}
if (beginFlowSeq && evt.evtype.is_scalar ()) {
var content = evt.data["data"];
this.node = new Yaml.NodeScalar (this.parent_node, content);
change = true;
beginFlowSeq = false;
}
if (evt.evtype.is_key () && (evt = this.get_value_key_event (it)) != null) {
key = evt.data["data"];
}
if (evt.evtype.is_value () && (evt = this.get_value_event (it)) != null) {
if (evt.evtype.is_scalar ()) {
var content = evt.data["data"];
if (key != null) {
this.node = new Yaml.NodeSinglePair (this.parent_node, key, content);
change = true;
else if (this.event.evtype.is_document_start ()) {
this.begin = true;
// to do
this.event = this.next_event ();
if (this.event.evtype.is_tag ()) {
this.root.tag = new Yaml.Tag (this.event.data["suffix"], this.event.data["handle"].replace("!", ""));
this.event = this.next_event ();
}
continue;
}
else if (evt.evtype.is_anchor ()) {
id = evt.data["id"];
evt = this.next_event (it);
}
else if (evt.evtype.is_alias ()) {
id = evt.data["id"];
Yaml.Node? refnode = this.anchors.get(id);
if (refnode != null) {
this.node = refnode.clone_node (key);
this.parent_node.add (this.node);
this.prev_node = this.node;
this.prev_level = this.prev_node.level;
}
}
if (evt.evtype.is_mapping_start ()) {
this.node = new Yaml.NodeMap (this.parent_node, key);
level += 1;
change = true;
}
else if (evt.evtype.is_sequence_start ()) {
this.node = new Yaml.NodeSequence (this.parent_node, key);
level += 1;
change = true;
beginFlowSeq = true;
}
if (id != null) {
if (this.node != null) {
this.anchors.set(id, this.node);
}
id = null;
}
key = null;
}
if (change) {
this.parent_node.add (this.node);
if (this.node.node_type.is_collection ()) {
this.parent_node = this.node;
else {
if (this.event.evtype.is_anchor ()) {
this.on_anchor ();
}
this.prev_node = this.node;
this.prev_level = this.prev_node.level;
this.node = null;
change = false;
else if (this.event.evtype.is_alias ()) {
this.on_alias ();
}
else if (this.event.evtype.is_mapping_end () || this.event.evtype.is_sequence_end ()) {
this.on_block_end ();
continue;
}
else if (this.event.evtype.is_key () && (this.event = this.get_value_key_event ()) != null) {
this.on_key ();
}
else if (this.event.evtype.is_entry ()) {
this.on_entry ();
}
else if (this.event.evtype.is_mapping_start ()) {
this.create_mapping (this.isEntry);
}
else if (this.event.evtype.is_sequence_start ()) {
this.on_sequence_start ();
}
else if (this.event.evtype.is_value ()) {
continue;
}
else if (this.event.evtype.is_scalar ()) {
this.on_scalar ();
}
this.add_anchor_if_needed ();
this.on_update ();
}
}
this.done = error_event == null && this.root != null;
return done;
}
/**
*
*/
private void reset ()
{
this.root = new Yaml.Root ();
this.prev_node = this.root;
this.parent_node = this.root;
this.iterator = this.events.iterator ();
this.change = false;
this.ckey = null;
this.idAnchor = null;
this.tagHandle = null;
this.keyTag = null;
this.valueTag = null;
this.beginFlowSeq = false;
this.nextValueEvt = null;
this.indexEvt = 0;
this.isEntry = false;
this.begin = false;
this.isEntryMapping = false;
}
/**
* retriew the next Yaml Event
*/
private Yaml.Event? next_event ()
{
Yaml.Event? evt = null;
if (this.iterator.has_next () && this.iterator.next ()) {
evt = this.iterator.get ();
Yaml.dbg (" >>>>> [EVENT event [%d] %s <<<<< %s".printf (this.indexEvt++, evt.evtype.infos (), Log.METHOD));
}
return evt;
}
/**
* retriew the next Yaml Event without use of iterator
*/
private Yaml.Event? get_next_event ()
{
Yaml.Event? evt = null;
var i = this.indexEvt;
if (i < this.events.size) {
evt = this.events.get (i);
}
return evt;
}
/**
* retriew the next Yaml Value Event closest to Key Event
*/
private Yaml.Event? get_value_key_event ()
{
Yaml.Event? evt = null;
var e = this.iterator.get ();
if (e != null && e.evtype.is_key ()) {
evt = this.next_event ();
}
return evt;
}
/**
* retriew the next Yaml Value Event
*/
private Yaml.Event? get_value_event ()
{
Yaml.Event? evt = null;
var e = this.iterator.get ();
if (e != null && e.evtype.is_value ()) {
evt = this.next_event ();
this.nextValueEvt = evt;
}
return evt;
}
/**
* retriew the next Yaml Value Event without use of iterator
*/
private Yaml.Event? get_next_value_event ()
{
Yaml.Event? evt = null;
var i = this.indexEvt;
Yaml.dbg (" >>> %s from %d".printf (Log.METHOD, i));
var search = true;
while (search) {
if (i < this.events.size) {
var e = this.events.get (i++);
if (e != null && e.evtype.is_value ()) {
evt = this.events.get (i);
Yaml.dbg (" >>> %s > %d : %s".printf (Log.METHOD, i, evt.evtype.infos ()));
break;
}
}
else search = false;
}
return evt;
}
/**
*
*/
private void on_tag_directive ()
{
Yaml.dbg_action ("on_tag_directive %s".printf (this.event.data["handle"]), this.event.data["prefix"]);
this.root.tag_directives[this.event.data["handle"]] = this.event.data["prefix"];
}
/**
*
*/
private void on_error ()
{
this.error_event = this.event;
}
/**
*
*/
private bool is_entry_nested_block (Yaml.Node node)
{
return node.ntype.is_sequence () && !node.empty() && node.first ().ntype.is_collection ();
}
/**
*
*/
private void on_block_end ()
{
if (this.prev_node.ntype.is_scalar () || (this.prev_node.ntype.is_single_pair () && this.prev_node.parent != null && this.prev_node.parent.ntype.is_mapping ())) {
this.prev_node = this.prev_node.parent;
}
this.parent_node = this.prev_node.parent != null && this.prev_node.parent != this.root
? this.prev_node.parent
: this.root;
this.prev_node = this.parent_node;
}
/**
*
*/
private void on_entry ()
{
this.isEntry = true;
this.ckey = null;
var e = this.get_next_event ();
if (e!= null && e.evtype.is_mapping_start ()) {
this.isEntryMapping = true;
this.create_mapping (true);
this.next_event ();
}
}
/**
*
*/
private void on_tag (bool onKey = false)
{
if (this.event.evtype.is_tag ()) {
Yaml.dbg_keyval ("tag %s".printf (this.event.data["handle"]), this.event.data["suffix"]);
if (this.root.tag_directives.has_key (this.event.data["handle"])) {
var tag = new Yaml.Tag (this.event.data["suffix"], this.event.data["handle"].replace("!", ""));
if (onKey)
this.keyTag = tag;
else
this.valueTag = tag;
this.event = this.next_event ();
}
else {
of.warn ("tag handle %s not found in directive".printf (this.event.data["handle"]));
}
}
}
/**
*
*/
private void on_key ()
{
this.on_tag (true);
if (this.event.evtype.is_scalar ()) {
this.ckey = this.event.data["data"];
Yaml.dbg (" >> node name : %s".printf (this.ckey));
}
}
/**
*
*/
private void on_scalar (bool entry = false)
{
if (this.ckey != null && this.parent_node.ntype.is_collection ()) {
this.node = new Yaml.Mapping.with_scalar (this.parent_node, this.ckey, this.event.data["data"]);
}
else {
this.node = new Yaml.Scalar (this.parent_node, this.event.data["data"]);
}
this.change = true;
}
/**
*
*/
private void on_anchor ()
{
if (this.event.data != null) {
this.idAnchor = this.event.data["id"];
}
}
/**
*
*/
private void on_alias ()
{
if (this.event.data != null) {
this.idAnchor = this.event.data["id"];
Yaml.Node? refnode = this.anchors.get(this.idAnchor);
if (refnode != null) {
this.node = refnode.clone_node (this.ckey);
this.parent_node.add (this.node);
this.prev_node = this.node;
}
}
}
/**
*
*/
private void on_sequence_start ()
{
this.node = new Yaml.Sequence (this.parent_node, this.ckey);
this.change = true;
}
/**
*
*/
private void on_mapping_start (bool entry = false)
{
this.ckey = null;
this.event = this.next_event ();
if (this.event.evtype.is_key ()) {
this.event = this.next_event ();
this.on_tag (true);
if (this.event.evtype.is_scalar ()) {
this.ckey = this.event.data["data"];
}
var e = this.get_next_value_event();
if (e!=null) {
if ( e.evtype.is_sequence_start ()) {
this.on_sequence_start ();
}
else {
this.create_mapping (this.isEntry);
}
}
}
}
/**
*
*/
private void create_mapping (bool entry = false)
{
if (entry && this.ckey == null) {
this.ckey = "_%d".printf(this.parent_node.count());
}
this.node = new Yaml.Mapping (this.parent_node, this.ckey);
this.change = true;
}
/**
*
*/
private void add_anchor_if_needed ()
{
if (this.idAnchor != null && this.node != null) {
this.anchors.set(this.idAnchor, this.node);
this.idAnchor = null;
}
}
/**
*
*/
private void on_update ()
{
if (this.node != null) {
Yaml.dbg (Log.METHOD);
Yaml.dbg (this.node.name);
Yaml.dbg (this.node.ntype.infos ());
Yaml.dbg ("anchor ? %s".printf (this.idAnchor));
}
if (this.change) {
if (this.node.parent.ntype.is_sequence ()) {
var seq = this.node.parent as Yaml.Sequence;
if (seq != null) seq.close_block = false;
}
Yaml.dbg_action ("on change", this.node.name != null ? this.node.name : this.node.data);
if (this.keyTag != null) {
Yaml.dbg_action ("setting tag", this.keyTag.@value);
this.node.tag = this.keyTag;
}
else if (this.valueTag != null) {
if (this.node.ntype.is_scalar ()) {
this.node.tag = this.valueTag;
}
else if (!this.node.empty () && this.node.first().ntype.is_scalar ()) {
this.node.first ().tag = this.valueTag;
}
}
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.tagHandle = null;
this.keyTag = null;
this.valueTag = null;
this.node = null;
this.isEntryMapping = false;
this.change = false;
this.isEntry = false;
this.ckey = null;
}
}
}

View File

@ -0,0 +1,210 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Pluie;
using Gee;
/**
* A Register class responsible to register owner types and related types lists
*
* The register also manage full namespace resolving for the yaml tags generation <<BR>>
* (from Yaml.Object to Yaml.Node)
*
* The registered types means that they can (must) be populated from Yaml.Node
* to Yaml.Object or the opposite.<<BR>>
* See classes Yaml.Builder & Yaml.Object for more details about that.
*/
public class Pluie.Yaml.Register
{
/**
*
*/
static Gee.HashMap<Type, Gee.ArrayList<GLib.Type>> rtype;
/**
*
*/
static Gee.ArrayList<string> namespaces;
/**
*
*/
static Gee.HashMap<Quark, string> ns_resolved;
/**
*
*/
static construct {
Yaml.Register.rtype = new Gee.HashMap<Type, Gee.ArrayList<GLib.Type>> ();
Yaml.Register.namespaces = new Gee.ArrayList<string> ();
Yaml.Register.ns_resolved = new Gee.HashMap<Quark, string> ();
}
/**
*
*/
internal Register ()
{
}
/**
* add multiple type to specified owner type
* @param owner_type the owner type to registering types
*/
public static bool add_type (GLib.Type owner_type, ...)
{
bool done = true;
if (!is_registered (owner_type)) {
rtype.set (owner_type, init_type_list ());
}
var l = va_list();
while (done) {
GLib.Type? t = l.arg<GLib.Type> ();
if (t == null || t == Type.INVALID) {
break;
}
Yaml.dbg ("adding to %s type %s".printf (owner_type.name (), t.name ()));
done = done && rtype.get (owner_type).add (t);
}
return done;
}
/**
* check if specified owner_type is registered
* @param owner_type the owner type to check
*/
public static bool is_registered (GLib.Type owner_type)
{
return rtype.has_key (owner_type);
}
/**
* check if specified type is registered for specified owner_type
* @param owner_type the owner type to check
* @param type the type presumably belonging to owner type
*/
public static bool is_registered_type (GLib.Type owner_type, GLib.Type type)
{
return is_registered (owner_type) && rtype.get (owner_type).contains (type);
}
/**
* add one or multiple namespace for tag resolution
* namespace value ar same as in vala source code (so with dot separator)
* @param name a namespace to register
*/
public static bool add_namespace (string name, ...)
{
var l = va_list();
Yaml.dbg ("adding namespace %s".printf (name));
var done = Yaml.Register.namespaces.contains (name) || Yaml.Register.namespaces.add (name);
while (done) {
string? ns = l.arg();
if (ns == null) {
break; // end of the list
}
Yaml.dbg ("adding namespace %s".printf (ns));
if (!Yaml.Register.namespaces.contains (ns)) {
done = done && Yaml.Register.namespaces.add (ns);
}
}
return done;
}
/**
* resolve full namespace for specified type
* @param type the type to retriew his full namespace
* @return the full namespace
*/
public static string resolve_namespace_type (GLib.Type type)
{
if (!is_resolved_ns (type)) {
var name = type.name ();
try {
Regex reg = new Regex ("([A-Z]{1}[a-z]+)");
var d = reg.split (type.name (), 0);
var rn = "";
var gb = "";
for (var i = 1; i < d.length; i+=2) {
rn += d[i];
if (namespaces.contains (rn)) {
rn += ".";
gb += d[i];
}
}
// case ENUM which ends with dot
if (rn.substring(-1) == ".") {
rn = name.splice (0, gb.length, rn);
}
name = rn;
}
catch (GLib.RegexError e) {
of.error (e.message);
}
var serial = get_serial (type);
Yaml.dbg ("resolve_namespace_type %u (%s) => %s".printf (serial, type.name (), name));
ns_resolved.set (serial, name);
}
return get_resolved_ns (type);
}
/**
*
*/
private static Gee.ArrayList<GLib.Type> init_type_list ()
{
return new Gee.ArrayList<GLib.Type> ();
}
/**
* check if full namespace is already resolved for specified type
* @param type the type to check
*/
private static bool is_resolved_ns (GLib.Type type)
{
return ns_resolved.has_key (get_serial (type));
}
/**
* get Quark related to specified type
*/
private static Quark get_serial (Type type)
{
return Quark.from_string (type.name ());
}
/**
* retriew full namespace value for specified type
* @param type the type to retriew his full namespace
* @return the full namespace for specified type
*/
private static string get_resolved_ns (GLib.Type type)
{
return is_resolved_ns (type) ? ns_resolved.get (get_serial (type)) : type.name ();
}
}

View File

@ -0,0 +1,78 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Pluie;
using Gee;
/**
* a class representing a Yaml Root Node
*/
public class Pluie.Yaml.Root : Yaml.Mapping
{
/**
* Tags directives
*/
public Gee.HashMap<string, string> tag_directives { get; internal set; }
/**
* @param name the name of the root node
*/
public Root (string? name = "PluieYamlRoot", bool add_directive = false, Yaml.Node? child = null)
{
base (null, name);
this.ntype = Yaml.NODE_TYPE.ROOT;
this.tag_directives = new Gee.HashMap<string, string> ();
if (add_directive) {
this.tag_directives["!%s!".printf (Yaml.YAML_VALA_PREFIX)] = Yaml.YAML_VALA_DIRECTIVE;
}
if (child != null) {
this.add (child);
}
}
/**
* get tag directives formatted for colorized output
*/
public string get_display_tag_directives ()
{
var sb = new StringBuilder();
foreach (var entry in this.tag_directives.entries) {
int len = 10 - entry.key.length -2;
var str = " %TAG "+@" %$(len)s"+" %s %s";
sb.append (
"\n %s %s".printf (
of.c(ECHO.TITLE).s (str.printf (" ", entry.key.replace("!", ""), Color.off ())),
of.c (ECHO.DEFAULT).s (entry.value))
);
}
return sb.str;
}
}

View File

@ -0,0 +1,64 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Pluie;
using Gee;
/**
* a class representing a Scalar node
*/
public class Pluie.Yaml.Scalar : Yaml.Node
{
bool container { get; internal set; default = false; }
/**
* default Yaml.Node constructor
* @param parent the parent node
* @param data the Scalar value
*/
public Scalar (Yaml.Node ? parent = null, string? data = null)
{
base (parent, NODE_TYPE.SCALAR);
this.container = false;
this.data = data;
}
/**
* clone current node
* @param name the overrinding name
*/
public override Yaml.Node clone_node (string? name = null)
{
Yaml.Scalar clone = new Yaml.Scalar (null, this.data);
return clone;
}
}

View File

@ -1,31 +1,31 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* @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
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* lib-yaml is distributed in the hope that it will be useful, but WITHOUT
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*
* You should have received a copy of the GNU General Public License
* along with lib-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Gee;
@ -37,7 +37,7 @@ extern void yaml_parse_file(string srcPath, string destPath);
*/
public class Pluie.Yaml.Scanner
{
public static bool DEBUG = false;
string path;
/**
* Regex pattern use to find EVENT
*/
@ -112,17 +112,32 @@ public class Pluie.Yaml.Scanner
*/
public Scanner (string path)
{
var destPath = Path.build_filename (Environment.get_tmp_dir (), Path.get_basename(path));
yaml_parse_file(path, destPath);
this.reader = new Io.Reader (destPath);
var date = new GLib.DateTime.now_local ().format ("%s");
this.path = Path.build_filename (Environment.get_tmp_dir (), "pluie-yaml-%s-%s.events".printf (date, Path.get_basename(path)));
yaml_parse_file(path, this.path);
this.reader = new Io.Reader (this.path);
}
/**
*
*/
~Scanner()
{
var f = GLib.File.new_for_path (this.path);
try {
f.delete ();
}
catch (GLib.Error e) {
of.error (e.message);
}
}
/**
* 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;
}
/**
@ -135,29 +150,37 @@ public class Pluie.Yaml.Scanner
/**
* scan specifiyed file generated throught yaml.c
* @param optional file path to scan
* @param path optional file path to scan
*/
public bool run (string? path = null)
{
Dbg.in (Log.METHOD, "path:'%s'".printf (path), Log.LINE, Log.FILE);
this.before_run (path);
this.processor = new Yaml.Processor ();
this.done = false;
Yaml.dbg_action ("Scanning events", path);
while (this.reader.readable) {
this.scan_event (this.reader.read ());
}
this.done = true;
Yaml.dbg_state (this.done);
this.done = this.done && this.processor.run ();
Yaml.dbg_state (this.done);
Dbg.out (Log.METHOD, "done:%d".printf ((int)done), Log.LINE, Log.FILE);
return this.done;
}
/**
*
*/
private void before_run (string? path)
{
if (path != null && this.reader.path != path) {
this.reader.load (path);
}
else {
this.reader.rewind(new Io.StreamLineMark(0, 0));
}
this.processor = new Yaml.Processor ();
this.done = false;
if (Pluie.Yaml.Scanner.DEBUG) of.action ("Scanning events", path);
while (this.reader.readable) {
this.scan_event (this.reader.read ());
}
this.done = true;
if (Pluie.Yaml.Scanner.DEBUG) of.state (this.done);
this.done = this.done && this.processor.run ();
if (Pluie.Yaml.Scanner.DEBUG) of.state (this.done);
Dbg.out (Log.METHOD, "done:%d".printf ((int)done), Log.LINE, Log.FILE);
return this.done;
}
/**
@ -179,6 +202,25 @@ public class Pluie.Yaml.Scanner
this.processor.events.add(new Yaml.Event(EVT.VERSION_DIRECTIVE, line, null, data));
}
/**
* register event tag
* @param evtdata the current data event
* @param line the current line
* @throws GLib.RegexError
*/
private void register_event_tag_directive(string evtdata, int line) throws GLib.RegexError
{
MatchInfo mi = null;
Regex reg = new Regex (REG_TAG);
HashMap<string, string>? data = null;
if (reg.match (evtdata, 0, out mi)) {
data = new HashMap<string, string>();
data.set("handle", mi.fetch (MIEVT_TAG.HANDLE));
data.set("prefix", mi.fetch (MIEVT_TAG.SUFFIX));
}
this.processor.events.add(new Yaml.Event(EVT.TAG_DIRECTIVE, line, null, data));
}
/**
* register event tag
* @param evtdata the current data event
@ -291,25 +333,28 @@ public class Pluie.Yaml.Scanner
string evtdata = mi.fetch (MIEVT.DATA);
switch(type) {
case EVT.SCALAR :
this.register_event_scalar(evtdata, line);
this.register_event_scalar (evtdata, line);
break;
case EVT.ANCHOR :
this.register_event_anchor(evtdata, line);
this.register_event_anchor (evtdata, line);
break;
case EVT.ALIAS :
this.register_event_alias(evtdata, line);
this.register_event_alias (evtdata, line);
break;
case EVT.TAG :
this.register_event_tag(evtdata, line);
this.register_event_tag (evtdata, line);
break;
case EVT.TAG_DIRECTIVE :
this.register_event_tag_directive (evtdata, line);
break;
case EVT.VERSION_DIRECTIVE :
this.register_event_version(evtdata, line);
this.register_event_version (evtdata, line);
break;
case EVT.NONE :
this.register_event_error(evtdata, line);
this.register_event_error (evtdata, line);
break;
default :
this.processor.events.add(new Yaml.Event((Yaml.EVT)type, line, null, null));
this.processor.events.add(new Yaml.Event ((Yaml.EVT) type, line, null, null));
break;
}
}

View File

@ -0,0 +1,51 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Pluie;
using Gee;
/**
* a class representing a sequence node
*/
public class Pluie.Yaml.Sequence : Yaml.Node
{
internal bool close_block { internal get; internal set; default = false; }
/**
* default Yaml.Node constructor
* @param parent the parent node
* @param name the node name
*/
public Sequence (Yaml.Node? parent = null, string? name = null)
{
base (parent, NODE_TYPE.SEQUENCE, name);
this.list = new ArrayList<Yaml.Node> ();
}
}

View File

@ -0,0 +1,46 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
using GLib;
using Gee;
/**
* a Tag class to store handle and value tag for Yaml.Node
*/
public class Pluie.Yaml.Tag
{
public string handle { get; internal set; }
public string @value { get; internal set; }
public Tag (string @value, string handle = "")
{
this.@value = @value;
this.handle = handle;
}
}

View File

@ -1,293 +1,461 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.60
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* @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
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* lib-yaml is distributed in the hope that it will be useful, but WITHOUT
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*
* You should have received a copy of the GNU General Public License
* along with lib-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
namespace Pluie
namespace Pluie.Yaml
{
namespace Yaml
const string YAML_VERSION = "1.2";
const string YAML_VALA_PREFIX = "v";
const string YAML_VALA_DIRECTIVE = "tag:pluie.org,2018:vala/";
public static bool DEBUG = false;
public static bool DBG_SHOW_INDENT = true;
public static bool DBG_SHOW_PARENT = false;
public static bool DBG_SHOW_UUID = true;
public static bool DBG_SHOW_LEVEL = false;
public static bool DBG_SHOW_REF = false;
public static bool DBG_SHOW_COUNT = true;
public static bool DBG_SHOW_TAG = true;
public static bool DBG_SHOW_TYPE = true;
/**
*
*/
internal static void dbg_action (string msg, string? val = null)
{
/**
* haxadecimal sequence
*/
const string hexa_sequence = "0123456789abcdef";
if (Pluie.Yaml.DEBUG) of.action (msg, val);
}
/**
*
*/
internal static void dbg_keyval (string key, string val)
{
if (Pluie.Yaml.DEBUG) of.keyval (key, val);
}
/**
*
*/
internal static void dbg_state (bool done)
{
if (Pluie.Yaml.DEBUG) of.state (done);
}
/**
*
*/
internal static void dbg (string? msg = null)
{
if (Pluie.Yaml.DEBUG && msg != null) of.echo (msg);
}
/**
* ParseError
*/
public errordomain AddNodeError
{
MAPPING_CONTAINS_CHILD,
MAPPING_IS_SINGLE_PAIR,
MAPPING_NOT_SINGLE_PAIR
}
private const ZlibCompressorFormat ZFORMAT = ZlibCompressorFormat.GZIP;
/**
*
*/
private void convert (File source, File dest, Converter converter) throws Error {
var src_stream = source.read ();
var dst_stream = dest.replace (null, false, 0);
var conv_stream = new ConverterOutputStream (dst_stream, converter);
// 'splice' pumps all data from an InputStream to an OutputStream
conv_stream.splice (src_stream, 0);
}
/**
* serialize an object as a yaml compressed document data
* @param obj the object to serialize
* @param dest path destination if you want to write to a file
*/
public static uint8[] serialize (GLib.Object? obj, string? dest = null)
{
Array<uint8> a = new Array<uint8> ();
if (obj != null) {
var node = obj.get_type ().is_a (typeof (Yaml.Node)) ? obj as Yaml.Node : Yaml.Builder.to_node (obj);
if (node != null) {
var content = node.to_yaml_string ();
var date = new GLib.DateTime.now_local ().format ("%s");
var path = Path.build_filename (Environment.get_tmp_dir (), "pluie-yaml-%s-%s.source".printf (date, node.uuid));
var dpath = dest == null ? path + ".gz" : dest;
var writter = new Io.Writter (path);
if (writter.write (content.data)) {
try {
var gzfile = File.new_for_path (dpath);
convert (writter.file, gzfile, new ZlibCompressor (ZFORMAT));
var reader = new Io.InputChunkStream(dpath, 80);
while (!reader.eof ()) {
var b = reader.read ();
a.append_vals (b, reader.get_buffer_size ());
}
writter.delete_file ();
if (dest == null) {
writter.delete_file (gzfile);
}
}
catch (GLib.Error e) {
of.error (e.message);
}
}
}
}
return a.data;
}
/**
* deserialize yaml compressed document data to a Yaml.Object
* @param zdata the data to deserialized
*/
public static Yaml.Root deserialize (uint8[] zdata)
{
Yaml.Root? obj = null;
if (zdata.length > 0) {
var date = new GLib.DateTime.now_local ().format ("%s");
var path = Path.build_filename (Environment.get_tmp_dir (), "pluie-yaml-%s.gz".printf (date));
var dpath = Path.build_filename (Environment.get_tmp_dir (), "pluie-yaml-%s.source".printf (date));
var writter = new Io.Writter (path);
if (writter.write (zdata)) {
var file = File.new_for_path (dpath);
try {
convert (writter.file, file, new ZlibDecompressor (ZFORMAT));
var config = new Yaml.Config (dpath);
obj = config.root_node ();
writter.delete_file ();
}
catch(GLib.Error e) {
of.error (e.message);
}
}
}
return obj;
}
/**
* haxadecimal sequence
*/
const string hexa_sequence = "0123456789abcdef";
/**
* convert %02x string to uint8
* @param hex2byte string representation of hexadecimal value on 1 byte
*/
uint8 hex_to_dec (string hexbyte)
{
return (uint8) (
Yaml.hexa_sequence.index_of(hexbyte.data[0].to_string ())*16 +
Yaml.hexa_sequence.index_of(hexbyte.data[1].to_string ())
);
}
/**
* enum MatchInfo keys of Yaml.Mode.find method related to mode FIND_MODE.SQUARE_BRACKETS of Yaml.Node
*/
public enum EVT {
NONE,
STREAM_START,
STREAM_END,
VERSION_DIRECTIVE,
TAG_DIRECTIVE,
DOCUMENT_START,
DOCUMENT_END,
BLOCK_SEQUENCE_START,
BLOCK_MAPPING_START,
BLOCK_END,
FLOW_SEQUENCE_START,
FLOW_SEQUENCE_END,
FLOW_MAPPING_START,
FLOW_MAPPING_END,
BLOCK_ENTRY,
FLOW_ENTRY,
KEY,
VALUE,
ALIAS,
ANCHOR,
TAG,
SCALAR;
/**
* convert %02x string to uint8
* @param hex2byte string representation of hexadecimal value on 1 byte
*/
uint8 hex_to_dec (string hexbyte)
* @return infos related to EVT
*/
public string infos ()
{
return (uint8) (
Yaml.hexa_sequence.index_of(hexbyte.data[0].to_string ())*16 +
Yaml.hexa_sequence.index_of(hexbyte.data[1].to_string ())
);
return this.to_string().substring("PLUIE_YAML_".length);
}
/**
* enum MatchInfo keys of Yaml.Mode.find method related to mode FIND_MODE.SQUARE_BRACKETS of Yaml.Node
*/
public enum EVT {
NONE,
STREAM_START,
STREAM_END,
VERSION_DIRECTIVE,
TAG_DIRECTIVE,
DOCUMENT_START,
DOCUMENT_END,
BLOCK_SEQUENCE_START,
BLOCK_MAPPING_START,
BLOCK_END,
FLOW_SEQUENCE_START,
FLOW_SEQUENCE_END,
FLOW_MAPPING_START,
FLOW_MAPPING_END,
BLOCK_ENTRY,
FLOW_ENTRY,
KEY,
VALUE,
ALIAS,
ANCHOR,
TAG,
SCALAR;
/**
* @return infos related to EVT
*/
public string infos ()
{
return this.to_string().substring("PLUIE_YAML_".length);
}
/**
* @return event is key
*/
public bool is_key ()
{
return this == EVT.KEY;
}
/**
* @return event is anchor
*/
public bool is_anchor ()
{
return this == EVT.ANCHOR;
}
/**
* @return event is alias
*/
public bool is_alias ()
{
return this == EVT.ALIAS;
}
/**
* @return event is key
*/
public bool is_value ()
{
return this == EVT.VALUE;
}
/**
* @return event is scalar
*/
public bool is_scalar ()
{
return this == EVT.SCALAR;
}
/**
* @return event is mapping start event
*/
public bool is_mapping_start ()
{
return this == EVT.BLOCK_MAPPING_START || this == EVT.FLOW_MAPPING_START;
}
/**
* @return event is sequence start event
*/
public bool is_sequence_start ()
{
return this == EVT.BLOCK_SEQUENCE_START || this == EVT.FLOW_SEQUENCE_START;
}
/**
* @return event is sequence end event
*/
public bool is_sequence_end ()
{
return this == EVT.BLOCK_END || this == EVT.FLOW_SEQUENCE_END;
}
/**
* @return event is sequence entry event
*/
public bool is_entry ()
{
return this == EVT.BLOCK_ENTRY || this == EVT.FLOW_ENTRY;
}
/**
* @return event is mapping end event
*/
public bool is_mapping_end ()
{
return this == EVT.BLOCK_END;
}
/**
* @return event is error event
*/
public bool is_error ()
{
return this == EVT.NONE;
}
* @return event is key
*/
public bool is_key ()
{
return this == EVT.KEY;
}
/**
* enum possible find mode of Yaml.Node.mode
*/
public enum FIND_MODE
* @return event is anchor
*/
public bool is_anchor ()
{
DOT,
SQUARE_BRACKETS;
/**
*
*/
public bool is_dot ()
{
return this == DOT;
}
return this == EVT.ANCHOR;
}
/**
* enum MatchInfo keys of Yaml.Mode.find method related to mode FIND_MODE.SQUARE_BRACKETS of Yaml.Node
*/
internal enum FIND_COLLECTION { PATH, OPEN, KEY, CLOSE; }
/**
* enum MatchInfo keys of Yaml.Node.find method related to mode FIND_MODE.DOT of Yaml.Node
*/
internal enum FIND_DOT { PATH, KEY, SEQUENCE; }
/**
* enum possible type of Yaml.Node
*/
public enum NODE_TYPE
* @return event is alias
*/
public bool is_alias ()
{
UNDEFINED,
ROOT,
SCALAR,
SINGLE_PAIR,
MAPPING,
SEQUENCE;
/**
* @return if current NODE_TYPE match a collection node (root|mapping|sequence)
*/
public bool is_collection ()
{
return this == MAPPING || this == SEQUENCE || this == ROOT;
}
/**
* @return if current NODE_TYPE match a scalar node
*/
public bool is_scalar ()
{
return this == SCALAR;
}
/**
* @return if current NODE_TYPE match a single/pair mapping node
*/
public bool is_single_pair ()
{
return this == SINGLE_PAIR;
}
/**
* @return if current NODE_TYPE match a mapping node
*/
public bool is_mapping ()
{
return this == MAPPING;
}
/**
* @return if current NODE_TYPE match a sequence node
*/
public bool is_sequence ()
{
return this == SEQUENCE;
}
/**
* @return if current NODE_TYPE match a root node
*/
public bool is_root ()
{
return this == ROOT;
}
/**
*@return infos related to NODE_TYPE
*/
public string infos ()
{
return this.to_string().substring("PLUIE_YAML_NODE_TYPE_".length);
}
return this == EVT.ALIAS;
}
/**
*@return universal infos related to NODE_TYPE
*/
public string uuid ()
* @return event is tag
*/
public bool is_tag ()
{
var sb = new StringBuilder();
for (var i = 0; i < 4; i++) sb.append (Random.next_int ().to_string ("%08x"));
var h = sb.str;
var d = Yaml.hex_to_dec (h.substring (16, 2));
d &= 0x3f;
d |= 0x80;
return "%s-%s-4%s-%02x%s-%s".printf (
h.substring (0, 8),
h.substring (8, 4),
h.substring (13, 3),
d,
h.substring (18, 2),
h.substring (20)
);
return this == EVT.TAG;
}
/**
* @return event is tag
*/
public bool is_tag_directive ()
{
return this == EVT.TAG_DIRECTIVE;
}
/**
* @return event is key
*/
public bool is_value ()
{
return this == EVT.VALUE;
}
/**
* @return event is scalar
*/
public bool is_scalar ()
{
return this == EVT.SCALAR;
}
/**
* @return event is mapping start event
*/
public bool is_mapping_start ()
{
return this == EVT.BLOCK_MAPPING_START || this == EVT.FLOW_MAPPING_START;
}
/**
* @return event is sequence start event
*/
public bool is_sequence_start ()
{
return this == EVT.BLOCK_SEQUENCE_START || this == EVT.FLOW_SEQUENCE_START;
}
/**
* @return event is sequence end event
*/
public bool is_sequence_end ()
{
return this == EVT.BLOCK_END || this == EVT.FLOW_SEQUENCE_END;
}
/**
* @return event is sequence entry event
*/
public bool is_entry ()
{
return this == EVT.BLOCK_ENTRY || this == EVT.FLOW_ENTRY;
}
/**
* @return event is mapping end event
*/
public bool is_mapping_end ()
{
return this == EVT.BLOCK_END;
}
/**
* @return event is error event
*/
public bool is_error ()
{
return this == EVT.NONE;
}
/**
* @return event is document start event
*/
public bool is_document_start ()
{
return this == EVT.DOCUMENT_START;
}
/**
* @return event is stream start event
*/
public bool is_stream_start ()
{
return this == EVT.STREAM_START;
}
}
/**
* enum possible find mode of Yaml.Node.mode
*/
public enum FIND_MODE
{
DOT,
SQUARE_BRACKETS;
/**
*
*/
public bool is_dot ()
{
return this == DOT;
}
}
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
*/
internal enum FIND_COLLECTION { PATH, OPEN, KEY, CLOSE; }
/**
* enum MatchInfo keys of Yaml.Node.find method related to mode FIND_MODE.DOT of Yaml.Node
*/
internal enum FIND_DOT { PATH, KEY, SEQUENCE; }
/**
* enum possible type of Yaml.Node
*/
public enum NODE_TYPE
{
UNDEFINED,
ROOT,
SCALAR,
SINGLE_PAIR,
MAPPING,
SEQUENCE;
/**
* @return if current NODE_TYPE match a collection node (root|mapping|sequence)
*/
public bool is_collection ()
{
return this == MAPPING || this == SEQUENCE || this == ROOT;
}
/**
* @return if current NODE_TYPE match a scalar node
*/
public bool is_scalar ()
{
return this == SCALAR;
}
/**
* @return if current NODE_TYPE match a single/pair mapping node
*/
public bool is_single_pair ()
{
return this == SINGLE_PAIR;
}
/**
* @return if current NODE_TYPE match a mapping node
*/
public bool is_mapping ()
{
return this == MAPPING;
}
/**
* @return if current NODE_TYPE match a sequence node
*/
public bool is_sequence ()
{
return this == SEQUENCE;
}
/**
* @return if current NODE_TYPE match a root node
*/
public bool is_root ()
{
return this == ROOT;
}
/**
*@return infos related to NODE_TYPE
*/
public string infos ()
{
return this.to_string().substring("PLUIE_YAML_NODE_TYPE_".length);
}
}
/**
*@return a universal unique identifier (type 4)
*/
public string uuid ()
{
var sb = new StringBuilder();
for (var i = 0; i < 4; i++) sb.append (Random.next_int ().to_string ("%08x"));
var h = sb.str;
var d = Yaml.hex_to_dec (h.substring (16, 2));
d &= 0x3f;
d |= 0x80;
return "%s-%s-4%s-%02x%s-%s".printf (
h.substring (0, 8),
h.substring (8, 4),
h.substring (13, 3),
d,
h.substring (18, 2),
h.substring (20)
);
}
}

68
src/vala/install.vala.in Normal file
View File

@ -0,0 +1,68 @@
/*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.56
* @type : library
* @date : 2018
* @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of pluie-yaml.
*
* pluie-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *^*/
/**
* root namespace of various Pluie lib
*/
namespace Pluie
{
/**
* Pluie.Io is dedicated to various input/ouput operations
*/
namespace Io
{
}
/**
* Samples namespace to illustrate or test functionnalities
*/
namespace Samples
{
}
/**
* Pluie.Yaml provides various tools to deal with yaml files and yaml nodes :
*
* Use {@link Yaml.Config} to load a .yml file and build a {@link Yaml.Root} node<<BR>>
* Use {@link Yaml.Config.get} to retriew a particular {@link Yaml.Node}<<BR>>
* Use {@link Yaml.Builder} to convert a {@link Yaml.Node} into a {@link Yaml.Object}<<BR>>
* Use {@link Yaml.Dumper} to dump a {@link Yaml.Object} or {@link Yaml.Node} into a yaml string<<BR>>
* Use {@link Yaml.serialize} to serialize a {@link Yaml.Object} or {@link Yaml.Node} into a string<<BR>>
* Use {@link Yaml.deserialize} to deserialize a serialized string into a {@link Yaml.Node}<<BR>>
* Use {@link Yaml.Collection} and {@link Yaml.AbstractChild} methods for Node traversing
*/
namespace Yaml
{
protected const string INSTALL_PATH = "@INSTALL_PATH@";
public const string DATA_PATH = "@DATA_PATH@";
public const string VERSION = "@VERSION@";
}
}

48
valadoc.sh Executable file
View File

@ -0,0 +1,48 @@
#!/bin/bash
#^# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
# @version : 0.60
# @type : library
# @date : 2018
# @license : GPLv3.0 <http://www.gnu.org/licenses/>
# @author : a-Sansara <[dev]at[pluie]dot[org]>
# @copyright : pluie.org <http://www.pluie.org>
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# This file is part of pluie-yaml.
#
# pluie-yaml is free software (free as in speech) : you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# pluie-yaml is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License
# along with pluie-yaml. If not, see <http://www.gnu.org/licenses/>.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #^#
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
lib="pluie-yaml-0.6"
cd $DIR
valadoc --package-name=$lib --verbose --force --deps -o ./doc --pkg gee-0.8 --pkg gio-2.0 --pkg gobject-2.0 --pkg gmodule-2.0 --pkg glib-2.0 --pkg pluie-echo-0.2 ./src/vala/Pluie/*.vala ./build/install.vala
if [ $? -eq 0 ]; then
rm doc/*.png
cp resources/doc-scripts.js ./doc/scripts.js
cp resources/doc-style.css ./doc/style.css
if [ -f "./docfix" ]; then
./docfix
if [ $? -eq 0 ]; then
rm $lib.tar.gz
tar -czvf $lib.tar.gz doc/
scp $lib.tar.gz pluie@pluie.org:/home/pluie/
ssh pluie@pluie.org "./updatedoc.sh $lib"
fi
fi
fi