Compare commits

...

49 Commits
0.42 ... 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
57 changed files with 4982 additions and 997 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^

5
.gitignore vendored
View File

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

291
README.md
View File

@ -4,26 +4,33 @@
As json is now a valid subset of yaml, you can use this lib to load json files too. 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. 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) So, currently the lib deal only with one yaml document (it's not recommended to use multiples doc),
to load a subset of yaml files in the main yaml document. 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** use the ![libyaml c library](https://github.com/yaml/libyaml) (License MIT, many thanks to Kirill Simonov) to parse and retriew related yaml events.
![pluie-yaml](https://www.meta-tech.academy/img/pluie-yaml-imports2.png) ![pluie-yaml-1](https://www.meta-tech.academy/img/pluie-yaml-1.png?tmp=1)
_legend display_childs_ : ![pluie-yaml-2](https://www.meta-tech.academy/img/pluie-yaml-2.png)
```
[ node.name [refCount] node.parent.name node.level node.ntype.infos () node.count () node.uuid ]
```
## License ## License
GNU GPL v3 GNU GPL v3
## Prerequisites ## 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 ## Install
@ -38,26 +45,43 @@ sudo ninja install -C build
## Compilation ## Compilation
``` ```
valac --pkg gee-0.8 --pkg pluie-echo-0.2 --pkg pluie-yaml-0.4 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 ## Api / Documentation
https://pluie.org/pluie-yaml-0.4/index.htm https://pluie.org/pluie-yaml-0.6/index.htm
## Docker ## 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 docker run --rm -it pluie/libyaml
``` ```
then you can execute any samples : Then you can execute any samples, for example :
``` ```
./json-loader ./json-loader
@ -65,6 +89,9 @@ then you can execute any samples :
![pluie-yaml-json](https://www.meta-tech.academy/img/pluie-yaml-json.png) ![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 ## Usage
@ -81,7 +108,7 @@ then you can execute any samples :
} }
``` ```
see Finder below to get precision about config.get parameter see Finder below to get precisions about config.get parameter (search path definition)
------------------- -------------------
@ -108,6 +135,34 @@ see Finder below to get precision about config.get parameter
db : db.yml 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 ### loader
@ -118,7 +173,7 @@ load a single document.
```vala ```vala
var path = "./config/main.yml"; var path = "./config/main.yml";
// uncomment to enable debug // uncomment to enable debug
// Pluie.Yaml.Scanner.DEBUG = true; // Pluie.Yaml.DEBUG = true;
var loader = new Yaml.Loader (path /* , displayFile, displayNode */); var loader = new Yaml.Loader (path /* , displayFile, displayNode */);
if ((done = loader.done)) { if ((done = loader.done)) {
Yaml.Node root = loader.get_nodes (); Yaml.Node root = loader.get_nodes ();
@ -129,7 +184,7 @@ load a single document.
### finder ### 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. Search path definition has two mode.
The default mode is `Yaml.FIND_MODE.DOT` The default mode is `Yaml.FIND_MODE.DOT`
- child mapping node are separated by dot - child mapping node are separated by dot
@ -177,12 +232,28 @@ vala code :
```vala ```vala
var config = new Yaml.Config (path); var config = new Yaml.Config (path);
var root = config.root_node (); 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 (); Iterator<Yaml.Node> it = root.iterator ();
Yaml.Node? child = null; Yaml.Node? child = null;
for (var has_next = it.next (); has_next; has_next = it.next ()) { for (var has_next = it.next (); has_next; has_next = it.next ()) {
child = it.get (); child = it.get ();
// do stuff
of.echo (child.to_string ()); of.echo (child.to_string ());
} }
}
``` ```
#### other #### other
@ -213,6 +284,181 @@ vala code :
} }
``` ```
-------------------
### 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 ### more samples
@ -227,6 +473,11 @@ see samples files in ./samples directory
* ~~fix nodes traversing~~ * ~~fix nodes traversing~~
* ~~rewrite nodes classes~~ * ~~rewrite nodes classes~~
* ~~put doc online~~ * ~~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 * improve doc
* dumper
* manage tag directives & tag

View File

@ -1,36 +1,39 @@
#!/bin/bash #!/bin/bash
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #^# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml> # @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
# @version : 0.4 # @version : 0.60
# @type : library
# @date : 2018 # @date : 2018
# @licence : GPLv3.0 <http://www.gnu.org/licenses/> # @license : GPLv3.0 <http://www.gnu.org/licenses/>
# @author : a-Sansara <[dev]at[pluie]dot[org]> # @author : a-Sansara <[dev]at[pluie]dot[org]>
# @copyright : pluie.org <http://www.pluie.org/> # @copyright : pluie.org <http://www.pluie.org>
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# 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 # 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, # published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version. # 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 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details. # more details.
# #
# You should have received a copy of the GNU General Public License # 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/>.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #^#
# -------------------------------------------------------- # --------------------------------------------------------
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
lib="pluie-yaml-0.4" 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" c1="\033[1;38;5;215m"
c2="\033[1;38;5;97m" c2="\033[1;38;5;97m"
cok="\033[1;38;5;37m" cok="\033[1;38;5;37m"
@ -62,6 +65,11 @@ function build.lib()
cd "$DIR" cd "$DIR"
build.title "$lib LIB BUILD" build.title "$lib LIB BUILD"
meson --prefix=/usr ./ build meson --prefix=/usr ./ build
if [ "$1" -eq 1 ]; then
meson configure -DLOCAL=true build
else
meson configure -DLOCAL=false build
fi
if [ "$UID" != "0" ]; then if [ "$UID" != "0" ]; then
sudo ninja -v install -C build sudo ninja -v install -C build
else else
@ -77,8 +85,10 @@ function build.samples()
for file in ./samples/*.vala for file in ./samples/*.vala
do do
if [[ -f $file ]]; then if [[ -f $file ]]; then
if [ -z "$1" ] || [ "$1" == "$file" ]; then
build.sample "$file" build.sample "$file"
fi fi
fi
done done
echo -e "\n RESUME : " echo -e "\n RESUME : "
for t in $resume; do for t in $resume; do
@ -92,9 +102,9 @@ function build.sample()
local f="$(basename $1)" local f="$(basename $1)"
local fx="${f:0:-5}" local fx="${f:0:-5}"
local state="FAILED" local state="FAILED"
local cmd="valac -v --pkg gee-0.8 --pkg pluie-echo-0.2 --pkg $lib $1 -o ./bin/$fx" local cmd="valac -v -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" build.title "$f SAMPLE BUILD"
echo -e "\n$cmd" echo
$cmd $cmd
local done=$? local done=$?
resume="$resume$done$f " resume="$resume$done$f "
@ -103,10 +113,14 @@ function build.sample()
# -------------------------------------------------------- # --------------------------------------------------------
function build.main() function build.main()
{ {
build.lib local onefile=""
if [ ! -z "$1" ]; then
onefile="./samples/$1.vala"
fi
build.lib "$2"
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
build.samples build.samples $onefile
fi 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.4
* @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/>
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of lib-yaml.
*
* lib-yaml is free software (free as in speech) : you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* lib-yaml is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with lib-yaml. If not, see <http://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
namespace Pluie
{
namespace Yaml
{
protected const string INSTALL_PATH = "@INSTALL_PATH@";
public const string DATA_PATH = "@DATA_PATH@";
public const string VERSION = "@VERSION@";
}
}

View File

@ -1,102 +1,96 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #^# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml> # @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
# @version : 0.4 # @version : 0.60
# @type : library
# @date : 2018 # @date : 2018
# @licence : GPLv3.0 <http://www.gnu.org/licenses/> # @license : GPLv3.0 <http://www.gnu.org/licenses/>
# @author : a-Sansara <[dev]at[pluie]dot[org]> # @author : a-Sansara <[dev]at[pluie]dot[org]>
# @copyright : pluie.org <http://www.pluie.org/> # @copyright : pluie.org <http://www.pluie.org>
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# 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 # 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, # published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version. # 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 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details. # more details.
# #
# You should have received a copy of the GNU General Public License # 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/>.
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #^#
#
project('libpluie-yaml', 'vala', 'c') project('pluie-yaml', ['vala', 'c'], version:'0.6')
cc = meson.get_compiler('c') cc = meson.get_compiler('c')
dep_glib = dependency('glib-2.0') version = meson.project_version()
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.4'
bindir = join_paths(get_option('prefix'), get_option('bindir')) bindir = join_paths(get_option('prefix'), get_option('bindir'))
datadir = join_paths(get_option('prefix'), get_option('datadir'), 'pluie/yaml') datadir = join_paths(get_option('prefix'), get_option('datadir'), 'pluie/yaml')
libdir = join_paths(get_option('prefix'), get_option('libdir'), 'pkgconfig') libdir = join_paths(get_option('prefix'), get_option('libdir'), 'pkgconfig')
incdir = join_paths(get_option('prefix'), get_option('includedir'), 'pluie') incdir = join_paths(get_option('prefix'), get_option('includedir'), 'pluie')
conf = configuration_data() conf = configuration_data()
conf.set('VERSION' , version) conf.set('VERSION' , version)
conf.set('INSTALL_PATH', bindir) conf.set('INSTALL_PATH', bindir)
if get_option('LOCAL')
conf.set('DATA_PATH' , './resources')
else
conf.set('DATA_PATH' , datadir) conf.set('DATA_PATH' , datadir)
endif
configure_file( configure_file(
input: 'install.vala.in', input: 'src/vala/install.vala.in',
output: 'install.vala', output: 'install.vala',
configuration: conf configuration: conf
) )
sources = [ install_data([
'build/install.vala', 'resources/main.yml',
'src/vala/Pluie/Io.Reader.vala', 'resources/tag.yml',
'src/vala/Pluie/Io.StreamLineMark.vala', 'resources/bug.yml',
'src/vala/Pluie/Yaml.global.vala', 'resources/test.yml',
'src/vala/Pluie/Yaml.AbstractChild.vala', 'resources/test.json'
'src/vala/Pluie/Yaml.AbstractNode.vala', ],
'src/vala/Pluie/Yaml.Collection.vala', install_dir : datadir
'src/vala/Pluie/Yaml.Config.vala', )
'src/vala/Pluie/Yaml.Event.vala',
'src/vala/Pluie/Yaml.Finder.vala',
'src/vala/Pluie/Yaml.Loader.vala',
'src/vala/Pluie/Yaml.Mapping.vala',
'src/vala/Pluie/Yaml.Node.vala',
'src/vala/Pluie/Yaml.Scalar.vala',
'src/vala/Pluie/Yaml.Scanner.vala',
'src/vala/Pluie/Yaml.Sequence.vala',
'src/vala/Pluie/Yaml.Processor.vala',
'src/c/yaml.c'
]
install_data('resources/main.yml', install_dir : datadir)
install_data('resources/test.yml', install_dir : datadir)
install_data('resources/test.json', install_dir : datadir)
install_data('resources/config/db.yml', install_dir : join_paths(datadir, 'config')) 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')) install_data('resources/config/subdir/test.yml', install_dir : join_paths(datadir, 'config/subdir'))
subdir('src')
add_global_arguments('-D DEBUG', language : 'valac')
libpluie_yaml = library( libpluie_yaml = library(
'pluie-yaml-' + version, 'pluie-yaml-' + version,
sources, src_files,
vala_header : 'pluie_yaml.h', vala_header : 'pluie_yaml.h',
vala_vapi : 'pluie-yaml-' +version+'.vapi', 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, install : true,
version : version,
install_dir : [get_option('libdir'), incdir, true] install_dir : [get_option('libdir'), incdir, true]
) )
pkgconfig = import('pkgconfig') pkgconfig = import('pkgconfig')
pkgconfig.generate( pkgconfig.generate(
libraries : libpluie_yaml, 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'), variables : 'datarootdir='+join_paths('${prefix}', get_option('datadir'))+'\ndatadir='+join_paths('${datarootdir}', 'pluie'),
version : version, version : version,
name : 'libpluie-yaml', 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 user : dev
password : mysql password : mysql
charset : utf8 charset : utf8
port : 3306
therapy : therapy :
driver : mysql driver : mysql
@ -13,3 +14,4 @@ therapy :
user : dev user : dev
password : mysql password : mysql
charset : utf8 charset : utf8
port : 3306

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,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> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.5
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @licence : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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/>.
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/ */
@ -39,7 +69,7 @@ int main (string[] args)
var done = false; var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara"); 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); var loader = new Yaml.Loader (path, true, true);
if ((done = loader.done)) { if ((done = loader.done)) {
var root = loader.get_nodes (); var root = loader.get_nodes ();

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> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.5
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @licence : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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/>.
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/ */
@ -39,7 +69,7 @@ int main (string[] args)
var done = false; var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara"); 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 config = new Yaml.Config (path, true);
var spath = "bo.host{0}"; var spath = "bo.host{0}";
var root = config.root_node (); var root = config.root_node ();

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> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.5
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @licence : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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/>.
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/ */
@ -39,7 +69,7 @@ int main (string[] args)
var done = false; var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara"); 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); var loader = new Yaml.Loader (path, true);
if ((done = loader.done)) { if ((done = loader.done)) {
Yaml.Node root = loader.get_nodes (); Yaml.Node root = loader.get_nodes ();

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> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.5
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @licence : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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 GLib;
using Gee; using Gee;
using Pluie; using Pluie;
@ -40,7 +71,7 @@ int main (string[] args)
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara"); 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 config = new Yaml.Config (path, true);
var spath = "^imports"; var spath = "^imports";
var node = config.get (spath); var node = config.get (spath);

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> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.5
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @licence : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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 GLib;
using Gee; using Gee;
using Pluie; using Pluie;
@ -39,7 +70,7 @@ int main (string[] args)
var done = false; var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara"); 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); var loader = new Yaml.Loader (path, true, true);
if ((done = loader.done)) { if ((done = loader.done)) {
var root = loader.get_nodes (); var root = loader.get_nodes ();

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> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.5
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @licence : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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 GLib;
using Gee; using Gee;
using Pluie; using Pluie;

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

@ -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> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.5
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @licence : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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 GLib;
using Gee; using Gee;
using Pluie; using Pluie;
@ -39,7 +70,7 @@ int main (string[] args)
var done = false; var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara"); 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 config = new Yaml.Config (path, true);
var node = config.root_node (); var node = config.root_node ();
if ((done = node != null)) { if ((done = node != null)) {

View File

@ -1,31 +1,31 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.60
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/> * @copyright : pluie.org <http://www.pluie.org>
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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 <stdio.h>
#include <yaml.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); fprintf(wh, "%lu, %d, %d, %d\n", line, token.type, token.data.version_directive.major, token.data.version_directive.minor);
break; 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 : case YAML_NO_TOKEN :
fprintf(wh, "%lu, %d, \"%s\"\n", line, token.type, escape_string((char *)parser.problem)); fprintf(wh, "%lu, %d, \"%s\"\n", line, token.type, escape_string((char *)parser.problem));
stop = 1; 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 : lib-yaml <https://git.pluie.org/pluie/lib-yaml> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.60
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/> * @copyright : pluie.org <http://www.pluie.org>
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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 GLib;
using Gee; using Gee;
using Pluie; using Pluie;
@ -140,4 +141,18 @@ public class Pluie.Io.Reader
return this.readable; 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 : lib-yaml <https://git.pluie.org/pluie/lib-yaml> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.60
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/> * @copyright : pluie.org <http://www.pluie.org>
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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 * 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

@ -1,31 +1,31 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.60
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/> * @copyright : pluie.org <http://www.pluie.org>
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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 GLib;
using Pluie; using Pluie;
@ -51,6 +51,11 @@ public abstract class Pluie.Yaml.AbstractChild : Yaml.AbstractNode
*/ */
public string? anchor { get; internal set; default = null; } public string? anchor { get; internal set; default = null; }
/**
*
*/
public Yaml.Tag? tag { get; internal set; default = null; }
/** /**
* default Yaml.Node constructor * default Yaml.Node constructor
* @param parent the parent node * @param parent the parent node
@ -82,7 +87,7 @@ public abstract class Pluie.Yaml.AbstractChild : Yaml.AbstractNode
} }
/** /**
* check if first chikd * check if last chikd
*/ */
public bool is_last () public bool is_last ()
{ {
@ -90,7 +95,7 @@ public abstract class Pluie.Yaml.AbstractChild : Yaml.AbstractNode
} }
/** /**
* check if first chikd * get nextt sibling node
*/ */
public Yaml.Node? next_sibling () public Yaml.Node? next_sibling ()
{ {
@ -98,7 +103,7 @@ public abstract class Pluie.Yaml.AbstractChild : Yaml.AbstractNode
} }
/** /**
* check if first chikd * get previous sibling node
*/ */
public Yaml.Node? previous_sibling () public Yaml.Node? previous_sibling ()
{ {
@ -118,6 +123,9 @@ public abstract class Pluie.Yaml.AbstractChild : Yaml.AbstractNode
return done; return done;
} }
/**
* coutn childs. return 0
*/
public virtual int count () public virtual int count ()
{ {
return 0; return 0;
@ -130,6 +138,4 @@ public abstract class Pluie.Yaml.AbstractChild : Yaml.AbstractNode
{ {
this.anchor = id; this.anchor = id;
} }
} }

View File

@ -1,31 +1,31 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.60
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/> * @copyright : pluie.org <http://www.pluie.org>
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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 GLib;
using Gee; using Gee;
@ -34,7 +34,7 @@ using Pluie;
/** /**
* abstract class representing a node * abstract class representing a node
*/ */
public abstract class Pluie.Yaml.AbstractNode : Object public abstract class Pluie.Yaml.AbstractNode : GLib.Object
{ {
/** /**
* universal unique identifier * universal unique identifier
@ -88,10 +88,51 @@ public abstract class Pluie.Yaml.AbstractNode : Object
return node != null && node.uuid == this.uuid; return node != null && node.uuid == this.uuid;
} }
public virtual string to_string (bool withIndent = Yaml.DBG_SHOW_INDENT, bool withParent = Yaml.DBG_SHOW_PARENT, bool withUuid = Yaml.DBG_SHOW_UUID, bool withLevel = Yaml.DBG_SHOW_LEVEL, bool withCount = Yaml.DBG_SHOW_COUNT, bool withRefCount = Yaml.DBG_SHOW_REF){ /**
* 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 ""; 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

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

@ -1,31 +1,31 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.60
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/> * @copyright : pluie.org <http://www.pluie.org>
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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 GLib;
using Gee; using Gee;
@ -37,13 +37,14 @@ using Pluie;
public interface Pluie.Yaml.Collection public interface Pluie.Yaml.Collection
{ {
/** /**
* retriew the child at index * retriew a child node throught specifiyed index
* @param index index of seached child * @param index index of searched child
* @return the matching child node
*/ */
public abstract Yaml.Node? item (int index); public abstract Yaml.Node? item (int index);
/** /**
* check if contains specifyed child node * check if current node contains the specifiyed child node
* @param child the child to check * @param child the child to check
*/ */
public abstract bool contains (Yaml.Node child); public abstract bool contains (Yaml.Node child);
@ -66,11 +67,13 @@ public interface Pluie.Yaml.Collection
/** /**
* retriew the first child * retriew the first child
* @return the first child node
*/ */
public abstract Yaml.Node? first (); public abstract Yaml.Node? first ();
/** /**
* retriew the last child * retriew the last child
* @return the last child node
*/ */
public abstract Yaml.Node? last (); public abstract Yaml.Node? last ();

View File

@ -1,39 +1,76 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.60
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/> * @copyright : pluie.org <http://www.pluie.org>
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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 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 public class Pluie.Yaml.Config
{ {
/** /**
* * special char use in imports clause & imports var
*/ */
const char IMPORTS_SPE = '^'; const char IMPORTS_SPE = '^';
@ -45,7 +82,7 @@ public class Pluie.Yaml.Config
/** /**
* *
*/ */
public bool displayFile { get; internal set; } public bool display_file { get; internal set; }
/** /**
* Yaml Loader * Yaml Loader
@ -69,14 +106,18 @@ public class Pluie.Yaml.Config
/** /**
* construct a Yaml Config for specifiyed path * 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.MODE = mode; Yaml.MODE = mode;
this.path = path; this.path = path;
this.displayFile = displayFile; this.display_file = display_file;
if (this.path != null) { if (this.path != null) {
this.loader = new Yaml.Loader (this.path, displayFile, false); this.loader = new Yaml.Loader (this.path, display_file, false);
if (this.loader.done) {
Yaml.Node? root = this.loader.get_nodes (); Yaml.Node? root = this.loader.get_nodes ();
if (root != null) { if (root != null) {
this.finder = new Yaml.Finder(root); this.finder = new Yaml.Finder(root);
@ -84,9 +125,11 @@ public class Pluie.Yaml.Config
} }
} }
} }
}
/** /**
* find node matching specifiyed keyPath * find node matching specifiyed keyPath
* see {@link Yaml.Finder} for precisions
*/ */
public new Yaml.Node? get (string keyPath) public new Yaml.Node? get (string keyPath)
{ {
@ -98,15 +141,15 @@ public class Pluie.Yaml.Config
} }
/** /**
* * retriew the corresponding Yaml.Root node for loaded yaml file
*/ */
public Yaml.Node root_node () public Yaml.Root? root_node ()
{ {
return this.finder.context; return this.finder!=null ? this.finder.context as Yaml.Root : null;
} }
/** /**
* find node matching specifiyed keyPath *
*/ */
protected void get_imports () protected void get_imports ()
{ {
@ -137,16 +180,14 @@ public class Pluie.Yaml.Config
Yaml.Node? n = null; Yaml.Node? n = null;
Yaml.Config? conf = null; Yaml.Config? conf = null;
foreach(var entry in this.paths.entries) { foreach(var entry in this.paths.entries) {
conf = new Yaml.Config(entry.value, this.displayFile); conf = new Yaml.Config(entry.value, this.display_file);
sub = conf.loader.get_nodes (); sub = conf.loader.get_nodes ();
n = new Yaml.Mapping (root, entry.key); n = new Yaml.Mapping (root, entry.key);
foreach(var subnode in sub.list) { foreach(var subnode in sub.list) {
subnode.parent = null; subnode.parent = null;
n.add(subnode); n.add(subnode);
} }
//~ root.add (n);
} }
//~ root.update_level();
} }
/** /**
@ -175,7 +216,7 @@ public class Pluie.Yaml.Config
foreach (var v in this.varmap.entries) { foreach (var v in this.varmap.entries) {
if (v.key != "path") { if (v.key != "path") {
this.paths[key] = val.replace ("^%s^".printf (v.key), v.value); this.paths[key] = val.replace ("^%s^".printf (v.key), v.value);
if (Yaml.Scanner.DEBUG) of.keyval (key, this.paths[key]); Yaml.dbg_keyval (key, this.paths[key]);
} }
} }
} }

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 : lib-yaml <https://git.pluie.org/pluie/lib-yaml> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.60
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/> * @copyright : pluie.org <http://www.pluie.org>
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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 GLib;
using Gee; using Gee;
using Pluie; 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 public class Pluie.Yaml.Event
{ {

View File

@ -1,31 +1,31 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.60
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/> * @copyright : pluie.org <http://www.pluie.org>
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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 GLib;
using Gee; using Gee;
@ -33,8 +33,21 @@ using Pluie;
/** /**
* Finder class used to easily retriew Yaml.Node * 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
{ {
/** /**
@ -52,17 +65,7 @@ public class Pluie.Yaml.Finder : Object
} }
/** /**
* find a specific child Yaml.Node corresponding to path definition * Find a specific child Yaml.Node corresponding to path definition.
* 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.DOTSQUARE_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]
* *
* @param path the definition to retriew the child node * @param path the definition to retriew the child node
* @param context the Yaml.Node context to operate * @param context the Yaml.Node context to operate

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 : lib-yaml <https://git.pluie.org/pluie/lib-yaml> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.60
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/> * @copyright : pluie.org <http://www.pluie.org>
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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 GLib;
using Gee; using Gee;
@ -37,10 +37,13 @@ using Pluie;
public class Pluie.Yaml.Loader public class Pluie.Yaml.Loader
{ {
/** /**
* Scanner * Flag PACK_NESTED_ENTRIES
*/
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; } Yaml.Scanner scanner { public get; internal set; }
/** /**
* indicate if file has been sucessfully loaded * indicate if file has been sucessfully loaded
*/ */
@ -52,15 +55,17 @@ public class Pluie.Yaml.Loader
Io.Reader reader; Io.Reader reader;
/** /**
* default constructor of Yaml.Loader
* @param path the path of file to parse * @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 * @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); this.reader = new Io.Reader (path);
if (this.reader.readable) {
this.scanner = new Yaml.Scanner (path); this.scanner = new Yaml.Scanner (path);
if (displayFile) this.displayFile (); if (display_file) this.display_file ();
if ((this.done = this.scanner.run())) { if ((this.done = this.scanner.run())) {
if (displayNode) { if (displayNode) {
@ -72,7 +77,8 @@ public class Pluie.Yaml.Loader
else { else {
var evt = this.scanner.get_error_event (); var evt = this.scanner.get_error_event ();
of.error ("line %d (%s)".printf (evt.line, evt.data["error"])); of.error ("line %d (%s)".printf (evt.line, evt.data["error"]));
this.displayFile (evt.line); this.display_file (evt.line);
}
} }
} }
@ -81,13 +87,40 @@ public class Pluie.Yaml.Loader
*/ */
public Yaml.Node? 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 * 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.action (errorLine == 0 ? "Reading file" : "Invalid Yaml File", this.reader.path);
of.echo (); of.echo ();

View File

@ -1,31 +1,31 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.60
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/> * @copyright : pluie.org <http://www.pluie.org>
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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 GLib;
using Pluie; using Pluie;
@ -42,7 +42,9 @@ public class Pluie.Yaml.Mapping : Yaml.Node
Gee.ArrayList<string>? keys { internal get; internal set; default = null; } 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) public Mapping (Yaml.Node? parent = null, string? name = null)
{ {
@ -51,18 +53,20 @@ public class Pluie.Yaml.Mapping : Yaml.Node
} }
/** /**
* * 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) public Mapping.with_scalar (Yaml.Node? parent = null, string? name = null, string? data = null)
{ {
base (parent, NODE_TYPE.MAPPING, name); base (parent, NODE_TYPE.SINGLE_PAIR, name);
var s = new Scalar (null, data); var s = new Scalar (null, data);
this.add (s); this.add (s);
} }
/** /**
* add a child node to current collection (mapping or sequence) node * {@inheritDoc}
* @param child the Yaml.Node child to add
*/ */
protected override void before_add (Yaml.Node child) throws Yaml.AddNodeError protected override void before_add (Yaml.Node child) throws Yaml.AddNodeError
{ {
@ -83,21 +87,21 @@ public class Pluie.Yaml.Mapping : Yaml.Node
} }
/** /**
* add a child node to current collection (mapping or sequence) node * {@inheritDoc}
* @param child the Yaml.Node child to add
*/ */
protected override void on_added (Yaml.Node child) protected override void on_added (Yaml.Node child)
{ {
base.on_added (child); base.on_added (child);
if (this.keys != null) { if (this.keys != null) {
if (!this.ntype.is_single_pair () && this.keys.size == 0 && child.ntype.is_scalar ()) {
this.ntype = Yaml.NODE_TYPE.SINGLE_PAIR;
}
this.keys.add(child.name); this.keys.add(child.name);
} }
} }
/** /**
* add a child node to current collection (mapping or sequence) node * {@inheritDoc}
* @param child the Yaml.Node child to add
* @param levelUpdate flag indicating if update level is needed
*/ */
protected override void on_removed (Yaml.Node child, bool levelUpdate = true) protected override void on_removed (Yaml.Node child, bool levelUpdate = true)
{ {
@ -108,9 +112,9 @@ public class Pluie.Yaml.Mapping : Yaml.Node
} }
/** /**
* retriew a child node throught specifiyed index * retriew a child node throught specifiyed name
* @param name name of searched child * @param name name of searched child
* @return the child node * @return the matching child node
*/ */
public new Yaml.Node? item (string name) public new Yaml.Node? item (string name)
{ {
@ -125,8 +129,7 @@ public class Pluie.Yaml.Mapping : Yaml.Node
} }
/** /**
* clone current node * {@inheritDoc}
* @param name the overrinding name
*/ */
public override Yaml.Node clone_node (string? name = null) public override Yaml.Node clone_node (string? name = null)
{ {
@ -140,8 +143,12 @@ public class Pluie.Yaml.Mapping : Yaml.Node
return clone; return clone;
} }
/**
* get a collection of chils name
*/
public Gee.ArrayList<string>? child_names () public Gee.ArrayList<string>? child_names ()
{ {
return this.keys; return this.keys;
} }
} }

View File

@ -1,37 +1,37 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.60
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/> * @copyright : pluie.org <http://www.pluie.org>
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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 GLib;
using Gee; using Gee;
/** /**
* a class representing a node * a class representing a yaml node no matter was his type
*/ */
public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
{ {
@ -76,12 +76,14 @@ public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
} }
catch (Yaml.AddNodeError e) { catch (Yaml.AddNodeError e) {
of.warn (e.message); of.warn (e.message);
Yaml.dbg (this.to_string ());
this.display_childs ();
} }
return done; return done;
} }
/** /**
* add a child node to current collection (mapping or sequence) node * actions to execute before adding the specified child bode
* @param child the Yaml.Node child to add * @param child the Yaml.Node child to add
*/ */
protected virtual void before_add (Yaml.Node child) throws Yaml.AddNodeError protected virtual void before_add (Yaml.Node child) throws Yaml.AddNodeError
@ -90,7 +92,7 @@ public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
} }
/** /**
* add a child node to current collection (mapping or sequence) node * actions to execute after adding the specified child bode
* @param child the Yaml.Node child to add * @param child the Yaml.Node child to add
*/ */
protected virtual void on_added (Yaml.Node child) protected virtual void on_added (Yaml.Node child)
@ -101,6 +103,7 @@ public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
/** /**
* remove a child * remove a child
* @param child the child to remove * @param child the child to remove
* @param levelUpdate flag indacting if level must be updated
*/ */
public bool remove_child (Yaml.Node child, bool levelUpdate = true) public bool remove_child (Yaml.Node child, bool levelUpdate = true)
{ {
@ -114,8 +117,9 @@ public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
} }
/** /**
* add a child node to current collection (mapping or sequence) node * action to exectuing after removing the specified child node
* @param child the Yaml.Node child to add * @param child the Yaml.Node child to remove
* @param levelUpdate flag indacting if level must be updated for removed child
*/ */
protected virtual void on_removed (Yaml.Node child, bool levelUpdate = true) protected virtual void on_removed (Yaml.Node child, bool levelUpdate = true)
{ {
@ -126,9 +130,7 @@ public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
} }
/** /**
* retriew a child node throught specifiyed index * {@inheritDoc}
* @param index index of searched child
* @return the child node
*/ */
public virtual Yaml.Node? item (int index) public virtual Yaml.Node? item (int index)
{ {
@ -136,37 +138,35 @@ public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
} }
/** /**
* check if current node contains the specifiyed child node * {@inheritDoc}
* @param child the child to check
*/ */
public bool contains (Yaml.Node child) { public bool contains (Yaml.Node child) {
return !this.empty () && this.list.contains (child); return !this.empty () && this.list.contains (child);
} }
/** /**
* count childnodes * {@inheritDoc}
*/ */
public override int count () { public override int count () {
return !this.empty () ? this.list.size : 0; return !this.empty () ? this.list.size : 0;
} }
/** /**
* check if empty * {@inheritDoc}
*/ */
public bool empty () { public bool empty () {
return this.list == null || this.list.size == 0; return this.list == null || this.list.size == 0;
} }
/** /**
* get an iterator * {@inheritDoc}
*/ */
public Gee.Iterator<Yaml.Node> iterator () { public Gee.Iterator<Yaml.Node> iterator () {
return this.list.iterator (); return this.list.iterator ();
} }
/** /**
* retriew the first child node * {@inheritDoc}
* @return the first child node
*/ */
public virtual Yaml.Node? first () public virtual Yaml.Node? first ()
{ {
@ -174,8 +174,7 @@ public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
} }
/** /**
* retriew the last child node * {@inheritDoc}
* @return the last child node
*/ */
public Yaml.Node? last () public Yaml.Node? last ()
{ {
@ -198,7 +197,7 @@ public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
} }
/** /**
* * {@inheritDoc}
*/ */
public Yaml.Node? child_next_sibling (Yaml.Node child) public Yaml.Node? child_next_sibling (Yaml.Node child)
{ {
@ -206,15 +205,15 @@ public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
} }
/** /**
* * {@inheritDoc}
*/ */
public Yaml.Node? child_previous_sibling (Yaml.Node child) public Yaml.Node? child_previous_sibling (Yaml.Node child)
{ {
return this.child_sibling (child, false); return this.child_sibling (child, false);
} }
/* /**
* * update nested indention node level and propagate approprietly level to all childs
*/ */
public virtual void update_level() public virtual void update_level()
{ {
@ -227,8 +226,9 @@ public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
} }
/** /**
* clone current node * clone current node (with all his children)
* @param name the name of clone * @param name the name of the clone
* @return the cloned node with cloned childs
*/ */
public virtual Yaml.Node clone_node (string? name = null) public virtual Yaml.Node clone_node (string? name = null)
{ {
@ -243,22 +243,50 @@ public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
} }
/** /**
* clone current node *
* @param name the name of clone
*/ */
public virtual Yaml.Node get_cloned_instance (string? name = null) internal virtual Yaml.Node get_cloned_instance (string? name = null)
{ {
return new Yaml.Node (null, this.ntype, name); 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 * display childs
* @param withTitle display a title before the childs node presentation
*/ */
public void display_childs (bool withTitle = true) public void display_childs (bool withTitle = true)
{ {
if (withTitle) { if (withTitle) {
of.action ("display_childs", this.name); of.action ("display_childs", this.name);
of.echo ("");
} }
of.echo (this.to_string ()); of.echo (this.to_string ());
if (!this.empty ()) { if (!this.empty ()) {
@ -270,14 +298,30 @@ public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
/** /**
* get a presentation string of current Yaml.Node * get a presentation string of current Yaml.Node
* @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 override string to_string (bool withIndent = Yaml.DBG_SHOW_INDENT, bool withParent = Yaml.DBG_SHOW_PARENT, bool withUuid = Yaml.DBG_SHOW_UUID, bool withLevel = Yaml.DBG_SHOW_LEVEL, bool withCount = Yaml.DBG_SHOW_COUNT, bool withRefCount = Yaml.DBG_SHOW_REF) public override string to_string (
bool withIndent = Yaml.DBG_SHOW_INDENT,
bool withParent = Yaml.DBG_SHOW_PARENT,
bool withUuid = Yaml.DBG_SHOW_UUID,
bool withLevel = Yaml.DBG_SHOW_LEVEL,
bool withCount = Yaml.DBG_SHOW_COUNT,
bool withRefCount = Yaml.DBG_SHOW_REF,
bool withTag = Yaml.DBG_SHOW_TAG,
bool withType = Yaml.DBG_SHOW_TYPE
)
{ {
return "%s%s%s%s%s%s%s%s%s".printf ( return "%s%s%s%s%s%s%s%s%s%s%s".printf (
this.level == 0 ? "" : of.s_indent ((int8) (withIndent ? (this.level-1)*4 : 0)), this.level == 0 ? "" : of.s_indent ((int8) (withIndent ? (this.level-1)*4 : 0)),
of.c (ECHO.OPTION).s ("["), of.c (ECHO.OPTION).s ("["),
this.name != null && !this.ntype.is_scalar () this.name != null && !this.ntype.is_scalar ()
? of.c (ECHO.TIME).s ("%s".printf (this.name)) ? of.c (ntype.is_root () ? ECHO.MICROTIME : ECHO.TIME).s ("%s".printf (this.name))
: ( : (
this.ntype.is_scalar () this.ntype.is_scalar ()
? of.c(ECHO.DATE).s ("%s".printf (this.data)) ? of.c(ECHO.DATE).s ("%s".printf (this.data))
@ -285,17 +329,21 @@ public class Pluie.Yaml.Node : Yaml.AbstractChild, Pluie.Yaml.Collection
), ),
withRefCount ? of.c (ECHO.COMMAND).s ("[%lu]".printf (this.ref_count)) : "", withRefCount ? of.c (ECHO.COMMAND).s ("[%lu]".printf (this.ref_count)) : "",
!withParent || this.parent == null !withParent || this.parent == null
? "" ? withLevel ? of.c (ECHO.NUM).s (" %d".printf (this.level)) : ""
: of.c (ECHO.SECTION).s (" "+this.parent.name)+( : of.c (ECHO.SECTION).s (" "+this.parent.name)+(
withLevel ? of.c (ECHO.NUM).s (" %d".printf (this.level)) : " " withLevel ? of.c (ECHO.NUM).s (" %d".printf (this.level)) : " "
), ),
of.c (ECHO.OPTION_SEP).s (" %s".printf( withType ? of.c (ECHO.OPTION_SEP).s (" %s".printf(this.ntype.infos ())) : "",
!this.ntype.is_mapping () || this.count () >= 1 && !this.first().ntype.is_scalar () ? this.ntype.infos () : NODE_TYPE.SINGLE_PAIR.infos () withCount && this.ntype.is_collection () ? of.c (ECHO.MICROTIME).s (" %d".printf(this.count ())) : "",
)),
withCount ? of.c (ECHO.MICROTIME).s (" %d".printf(this.count ())) : "",
withUuid ? of.c (ECHO.COMMENT).s (" %s".printf(this.uuid[0:8]+"...")) : "", withUuid ? of.c (ECHO.COMMENT).s (" %s".printf(this.uuid[0:8]+"...")) : "",
//~ of.c (ECHO.NUM).s ("%d".printf (this.level)), this.tag != null && withTag
of.c (ECHO.OPTION).s ("]") ? " %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

@ -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 : lib-yaml <https://git.pluie.org/pluie/lib-yaml> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.60
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/> * @copyright : pluie.org <http://www.pluie.org>
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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 GLib;
using Gee; using Gee;
@ -46,11 +46,31 @@ public class Pluie.Yaml.Processor
*/ */
bool change; 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 * indicates if begon a flow sequence
*/ */
bool beginFlowSeq; bool beginFlowSeq;
/**
*
*/
int indexEvt;
/** /**
* current anchor id * current anchor id
*/ */
@ -61,6 +81,26 @@ public class Pluie.Yaml.Processor
*/ */
string? ckey; 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 * Events list
*/ */
@ -84,7 +124,7 @@ public class Pluie.Yaml.Processor
/** /**
* the root Yaml.Node * the root Yaml.Node
*/ */
public Yaml.Node root; public Yaml.Root root;
/** /**
* current previous Yaml.Node * current previous Yaml.Node
@ -121,9 +161,10 @@ public class Pluie.Yaml.Processor
public void read () public void read ()
{ {
of.action ("Reading events"); of.action ("Reading events");
var i = 0;
foreach (Yaml.Event event in this.events) { foreach (Yaml.Event event in this.events) {
int len = 24 - event.evtype.infos ().length; 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) { if (event.data != null && event.data.size > 0) {
stdout.printf (", {"); stdout.printf (", {");
var it = event.data.map_iterator (); var it = event.data.map_iterator ();
@ -143,44 +184,68 @@ public class Pluie.Yaml.Processor
*/ */
public bool run () public bool run ()
{ {
if (Yaml.Scanner.DEBUG) { if (Yaml.DEBUG) this.read ();
this.read (); Yaml.dbg_action ("Processing events");
of.action ("Processing events");
}
this.reset (); this.reset ();
for (var has_next = this.iterator.next (); has_next; has_next = this.iterator.next ()) { for (var has_next = this.iterator.next (); has_next; has_next = this.iterator.next ()) {
this.event = this.iterator.get (); this.event = this.iterator.get ();
Yaml.dbg (" [[[ 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 ()) { if (this.event.evtype.is_error ()) {
this.on_error (); this.on_error ();
break; break;
} }
if (this.event.evtype.is_mapping_end () || this.event.evtype.is_sequence_end ()) { if (!this.begin) {
if (this.event.evtype.is_sequence_start () || this.event.evtype.is_mapping_start ()) {
this.begin = true;
continue;
}
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 (this.event.evtype.is_anchor ()) {
this.on_anchor ();
}
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 (); this.on_block_end ();
continue; continue;
} }
if (this.event.evtype.is_entry ()) { else if (this.event.evtype.is_key () && (this.event = this.get_value_key_event ()) != null) {
this.on_entry ();
}
if (this.beginFlowSeq && this.event.evtype.is_scalar ()) {
this.on_scalar (true);
this.beginFlowSeq = false;
}
if (this.event.evtype.is_key () && (this.event = this.get_value_key_event ()) != null) {
this.on_key (); this.on_key ();
} }
if (this.event.evtype.is_value () && (this.event = this.get_value_event ()) != null) { else if (this.event.evtype.is_entry ()) {
this.on_value (); this.on_entry ();
if (this.event.evtype.is_mapping_start ()) { }
this.on_mapping_start (); else if (this.event.evtype.is_mapping_start ()) {
this.create_mapping (this.isEntry);
} }
else if (this.event.evtype.is_sequence_start ()) { else if (this.event.evtype.is_sequence_start ()) {
this.on_sequence_start (); this.on_sequence_start ();
} }
this.add_anchor_if_needed (); else if (this.event.evtype.is_value ()) {
this.ckey = null; continue;
} }
else if (this.event.evtype.is_scalar ()) {
this.on_scalar ();
}
this.add_anchor_if_needed ();
this.on_update (); this.on_update ();
} }
}
this.done = error_event == null && this.root != null; this.done = error_event == null && this.root != null;
return done; return done;
} }
@ -190,15 +255,22 @@ public class Pluie.Yaml.Processor
*/ */
private void reset () private void reset ()
{ {
this.root = new Yaml.Mapping (null, "PluieYamlRoot"); this.root = new Yaml.Root ();
this.root.ntype = Yaml.NODE_TYPE.ROOT;
this.prev_node = this.root; this.prev_node = this.root;
this.parent_node = this.root; this.parent_node = this.root;
this.iterator = this.events.iterator (); this.iterator = this.events.iterator ();
this.change = false; this.change = false;
this.ckey = null; this.ckey = null;
this.idAnchor = null; this.idAnchor = null;
this.tagHandle = null;
this.keyTag = null;
this.valueTag = null;
this.beginFlowSeq = false; this.beginFlowSeq = false;
this.nextValueEvt = null;
this.indexEvt = 0;
this.isEntry = false;
this.begin = false;
this.isEntryMapping = false;
} }
/** /**
@ -209,6 +281,20 @@ public class Pluie.Yaml.Processor
Yaml.Event? evt = null; Yaml.Event? evt = null;
if (this.iterator.has_next () && this.iterator.next ()) { if (this.iterator.has_next () && this.iterator.next ()) {
evt = this.iterator.get (); 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; return evt;
} }
@ -235,10 +321,44 @@ public class Pluie.Yaml.Processor
var e = this.iterator.get (); var e = this.iterator.get ();
if (e != null && e.evtype.is_value ()) { if (e != null && e.evtype.is_value ()) {
evt = this.next_event (); evt = this.next_event ();
this.nextValueEvt = evt;
} }
return 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"];
}
/** /**
* *
*/ */
@ -247,13 +367,24 @@ public class Pluie.Yaml.Processor
this.error_event = this.event; 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 () 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.parent_node = this.prev_node.parent != null && this.prev_node.parent != this.root
? this.prev_node.parent.parent ? this.prev_node.parent
: this.root; : this.root;
this.prev_node = this.parent_node; this.prev_node = this.parent_node;
} }
@ -263,12 +394,35 @@ public class Pluie.Yaml.Processor
*/ */
private void on_entry () private void on_entry ()
{ {
this.event = this.next_event(); this.isEntry = true;
if (this.event.evtype.is_mapping_start ()) { this.ckey = null;
this.on_mapping_start (true); 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"]));
} }
else if (this.event.evtype.is_scalar ()) {
this.on_scalar (true);
} }
} }
@ -277,22 +431,10 @@ public class Pluie.Yaml.Processor
*/ */
private void on_key () private void on_key ()
{ {
this.ckey = this.event.data["data"]; this.on_tag (true);
}
/**
*
*/
private void on_value ()
{
if (this.event.evtype.is_scalar ()) { if (this.event.evtype.is_scalar ()) {
this.on_scalar (); this.ckey = this.event.data["data"];
} Yaml.dbg (" >> node name : %s".printf (this.ckey));
else if (this.event.evtype.is_anchor ()) {
this.on_anchor ();
}
else if (this.event.evtype.is_alias ()) {
this.on_alias ();
} }
} }
@ -301,16 +443,13 @@ public class Pluie.Yaml.Processor
*/ */
private void on_scalar (bool entry = false) private void on_scalar (bool entry = false)
{ {
if (!entry) { if (this.ckey != null && this.parent_node.ntype.is_collection ()) {
if (this.ckey != null) {
this.node = new Yaml.Mapping.with_scalar (this.parent_node, this.ckey, this.event.data["data"]); this.node = new Yaml.Mapping.with_scalar (this.parent_node, this.ckey, this.event.data["data"]);
this.change = true;
}
} }
else { else {
this.node = new Yaml.Scalar (this.parent_node, this.event.data["data"]); this.node = new Yaml.Scalar (this.parent_node, this.event.data["data"]);
this.change = true;
} }
this.change = true;
} }
/** /**
@ -318,8 +457,9 @@ public class Pluie.Yaml.Processor
*/ */
private void on_anchor () private void on_anchor ()
{ {
if (this.event.data != null) {
this.idAnchor = this.event.data["id"]; this.idAnchor = this.event.data["id"];
this.event = this.next_event (); }
} }
/** /**
@ -327,6 +467,7 @@ public class Pluie.Yaml.Processor
*/ */
private void on_alias () private void on_alias ()
{ {
if (this.event.data != null) {
this.idAnchor = this.event.data["id"]; this.idAnchor = this.event.data["id"];
Yaml.Node? refnode = this.anchors.get(this.idAnchor); Yaml.Node? refnode = this.anchors.get(this.idAnchor);
if (refnode != null) { if (refnode != null) {
@ -335,6 +476,7 @@ public class Pluie.Yaml.Processor
this.prev_node = this.node; this.prev_node = this.node;
} }
} }
}
/** /**
* *
@ -343,7 +485,6 @@ public class Pluie.Yaml.Processor
{ {
this.node = new Yaml.Sequence (this.parent_node, this.ckey); this.node = new Yaml.Sequence (this.parent_node, this.ckey);
this.change = true; this.change = true;
this.beginFlowSeq = true;
} }
/** /**
@ -351,11 +492,24 @@ public class Pluie.Yaml.Processor
*/ */
private void on_mapping_start (bool entry = false) private void on_mapping_start (bool entry = false)
{ {
if (entry) {
this.create_mapping (entry);
this.ckey = null; 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);
}
}
} }
else this.create_mapping ();
} }
/** /**
@ -363,7 +517,7 @@ public class Pluie.Yaml.Processor
*/ */
private void create_mapping (bool entry = false) private void create_mapping (bool entry = false)
{ {
if (entry) { if (entry && this.ckey == null) {
this.ckey = "_%d".printf(this.parent_node.count()); this.ckey = "_%d".printf(this.parent_node.count());
} }
this.node = new Yaml.Mapping (this.parent_node, this.ckey); this.node = new Yaml.Mapping (this.parent_node, this.ckey);
@ -375,10 +529,8 @@ public class Pluie.Yaml.Processor
*/ */
private void add_anchor_if_needed () private void add_anchor_if_needed ()
{ {
if (this.idAnchor != null) { if (this.idAnchor != null && this.node != null) {
if (this.node != null) {
this.anchors.set(this.idAnchor, this.node); this.anchors.set(this.idAnchor, this.node);
}
this.idAnchor = null; this.idAnchor = null;
} }
} }
@ -388,7 +540,30 @@ public class Pluie.Yaml.Processor
*/ */
private void on_update () 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.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 ()))) { if (this.node.ntype.is_collection () && (this.node.empty() || (!this.node.first().ntype.is_scalar ()))) {
this.parent_node = this.node; this.parent_node = this.node;
} }
@ -396,8 +571,14 @@ public class Pluie.Yaml.Processor
this.parent_node = this.node.parent; this.parent_node = this.node.parent;
} }
this.prev_node = this.node; this.prev_node = this.node;
this.tagHandle = null;
this.keyTag = null;
this.valueTag = null;
this.node = null; this.node = null;
this.isEntryMapping = false;
this.change = 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

@ -1,31 +1,31 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.60
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/> * @copyright : pluie.org <http://www.pluie.org>
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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 GLib;
using Pluie; using Pluie;
@ -47,6 +47,7 @@ public class Pluie.Yaml.Scalar : Yaml.Node
public Scalar (Yaml.Node ? parent = null, string? data = null) public Scalar (Yaml.Node ? parent = null, string? data = null)
{ {
base (parent, NODE_TYPE.SCALAR); base (parent, NODE_TYPE.SCALAR);
this.container = false;
this.data = data; this.data = data;
} }

View File

@ -1,31 +1,31 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.60
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/> * @copyright : pluie.org <http://www.pluie.org>
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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 GLib;
using Gee; using Gee;
@ -37,7 +37,7 @@ extern void yaml_parse_file(string srcPath, string destPath);
*/ */
public class Pluie.Yaml.Scanner public class Pluie.Yaml.Scanner
{ {
public static bool DEBUG = false; string path;
/** /**
* Regex pattern use to find EVENT * Regex pattern use to find EVENT
*/ */
@ -112,9 +112,24 @@ public class Pluie.Yaml.Scanner
*/ */
public Scanner (string path) public Scanner (string path)
{ {
var destPath = Path.build_filename (Environment.get_tmp_dir (), Path.get_basename(path)); var date = new GLib.DateTime.now_local ().format ("%s");
yaml_parse_file(path, destPath); this.path = Path.build_filename (Environment.get_tmp_dir (), "pluie-yaml-%s-%s.events".printf (date, Path.get_basename(path)));
this.reader = new Io.Reader (destPath); 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);
}
} }
/** /**
@ -143,14 +158,14 @@ public class Pluie.Yaml.Scanner
this.before_run (path); this.before_run (path);
this.processor = new Yaml.Processor (); this.processor = new Yaml.Processor ();
this.done = false; this.done = false;
if (Pluie.Yaml.Scanner.DEBUG) of.action ("Scanning events", path); Yaml.dbg_action ("Scanning events", path);
while (this.reader.readable) { while (this.reader.readable) {
this.scan_event (this.reader.read ()); this.scan_event (this.reader.read ());
} }
this.done = true; this.done = true;
if (Pluie.Yaml.Scanner.DEBUG) of.state (this.done); Yaml.dbg_state (this.done);
this.done = this.done && this.processor.run (); this.done = this.done && this.processor.run ();
if (Pluie.Yaml.Scanner.DEBUG) of.state (this.done); Yaml.dbg_state (this.done);
Dbg.out (Log.METHOD, "done:%d".printf ((int)done), Log.LINE, Log.FILE); Dbg.out (Log.METHOD, "done:%d".printf ((int)done), Log.LINE, Log.FILE);
return this.done; return this.done;
} }
@ -187,6 +202,25 @@ public class Pluie.Yaml.Scanner
this.processor.events.add(new Yaml.Event(EVT.VERSION_DIRECTIVE, line, null, data)); 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 * register event tag
* @param evtdata the current data event * @param evtdata the current data event
@ -310,6 +344,9 @@ public class Pluie.Yaml.Scanner
case EVT.TAG : case EVT.TAG :
this.register_event_tag (evtdata, line); this.register_event_tag (evtdata, line);
break; break;
case EVT.TAG_DIRECTIVE :
this.register_event_tag_directive (evtdata, line);
break;
case EVT.VERSION_DIRECTIVE : case EVT.VERSION_DIRECTIVE :
this.register_event_version (evtdata, line); this.register_event_version (evtdata, line);
break; break;

View File

@ -1,31 +1,31 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.60
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/> * @copyright : pluie.org <http://www.pluie.org>
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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 GLib;
using Pluie; using Pluie;
@ -36,6 +36,7 @@ using Gee;
*/ */
public class Pluie.Yaml.Sequence : Yaml.Node public class Pluie.Yaml.Sequence : Yaml.Node
{ {
internal bool close_block { internal get; internal set; default = false; }
/** /**
* default Yaml.Node constructor * default Yaml.Node constructor

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,42 +1,80 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /*^* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* @software : lib-yaml <https://git.pluie.org/pluie/lib-yaml> * @software : pluie-yaml <https://git.pluie.org/pluie/lib-yaml>
* @version : 0.4 * @version : 0.60
* @type : library
* @date : 2018 * @date : 2018
* @licence : GPLv3.0 <http://www.gnu.org/licenses/> * @license : GPLv3.0 <http://www.gnu.org/licenses/>
* @author : a-Sansara <[dev]at[pluie]dot[org]> * @author : a-Sansara <[dev]at[pluie]dot[org]>
* @copyright : pluie.org <http://www.pluie.org/> * @copyright : pluie.org <http://www.pluie.org>
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 * 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, * published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version. * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * 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_INDENT = true;
public static bool DBG_SHOW_PARENT = true; public static bool DBG_SHOW_PARENT = false;
public static bool DBG_SHOW_UUID = true; public static bool DBG_SHOW_UUID = true;
public static bool DBG_SHOW_LEVEL = true; public static bool DBG_SHOW_LEVEL = false;
public static bool DBG_SHOW_REF = true; public static bool DBG_SHOW_REF = false;
public static bool DBG_SHOW_COUNT = true; public static bool DBG_SHOW_COUNT = true;
public static bool DBG_SHOW_TAG = true;
public static bool DBG_SHOW_TYPE = true;
/**
*
*/
internal static void dbg_action (string msg, string? val = null)
{
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 * ParseError
@ -48,6 +86,86 @@ namespace Pluie
MAPPING_NOT_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 * haxadecimal sequence
*/ */
@ -124,6 +242,22 @@ namespace Pluie
return this == EVT.ALIAS; return this == EVT.ALIAS;
} }
/**
* @return event is tag
*/
public bool is_tag ()
{
return this == EVT.TAG;
}
/**
* @return event is tag
*/
public bool is_tag_directive ()
{
return this == EVT.TAG_DIRECTIVE;
}
/** /**
* @return event is key * @return event is key
*/ */
@ -188,6 +322,22 @@ namespace Pluie
return this == EVT.NONE; 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;
}
} }
/** /**
@ -289,7 +439,7 @@ namespace Pluie
} }
/** /**
*@return universal infos related to NODE_TYPE *@return a universal unique identifier (type 4)
*/ */
public string uuid () public string uuid ()
{ {
@ -309,4 +459,3 @@ namespace Pluie
); );
} }
} }
}

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

View File

@ -1,6 +1,48 @@
#!/bin/bash #!/bin/bash
valadoc --package-name=pluie-yaml-0.4 --verbose --force --deps -o ./doc --pkg gee-0.8 --pkg gio-2.0 --pkg gobject-2.0 --pkg glib-2.0 --pkg pluie-echo-0.2 ./src/vala/Pluie/*.vala ./build/install.vala #^# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# @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 rm doc/*.png
cp resources/doc-scripts.js ./doc/scripts.js cp resources/doc-scripts.js ./doc/scripts.js
cp resources/doc-style.css ./doc/style.css 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