finish ^imports
This commit is contained in:
parent
3043b5ef88
commit
30197dde42
76
README.md
76
README.md
|
@ -4,8 +4,10 @@
|
||||||
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 an @import clause (nodemap) is plan in order to load a subset of yaml files in the main yaml document.
|
So, currently the lib deal only with one yaml document, but you can use a special `^imports` clause (nodemap)
|
||||||
|
to load a subset of yaml files in the main yaml document.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
@ -51,9 +53,11 @@ docker run --rm -it pluie/libyaml
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
-------------------
|
||||||
|
|
||||||
### config
|
### config
|
||||||
|
|
||||||
```
|
```vala
|
||||||
|
|
||||||
var config = new Yaml.Config (path);
|
var config = new Yaml.Config (path);
|
||||||
var node = config.get ("ship-to.address.city{0}");
|
var node = config.get ("ship-to.address.city{0}");
|
||||||
|
@ -62,10 +66,39 @@ docker run --rm -it pluie/libyaml
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
### config with ^imports clause
|
||||||
|
|
||||||
|
```yml
|
||||||
|
# | 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
|
||||||
|
```
|
||||||
|
|
||||||
|
-------------------
|
||||||
|
|
||||||
### loader
|
### loader
|
||||||
|
|
||||||
```
|
load a single document.
|
||||||
|
`^imports` clause is out of effects here.
|
||||||
|
|
||||||
|
```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.Scanner.DEBUG = true;
|
||||||
|
@ -75,48 +108,57 @@ docker run --rm -it pluie/libyaml
|
||||||
root.display_childs ();
|
root.display_childs ();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
-------------------
|
||||||
|
|
||||||
### finder
|
### finder
|
||||||
|
|
||||||
**lib-yaml** provide a `Yaml.Finder` to easily retriew a particular yaml node.
|
**lib-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.SQUARE_BRACKETS`
|
The default mode is `Yaml.FIND_MODE.DOT`
|
||||||
- node's key name must be enclosed in square brackets
|
|
||||||
- sequence entry must be enclosed in curly brace
|
|
||||||
|
|
||||||
ex : `[grandfather][father][son]{2}[age]`
|
|
||||||
|
|
||||||
The Other mode is Yaml.FIND_MODE.DOT
|
|
||||||
- child mapping node are separated by dot
|
- child mapping node are separated by dot
|
||||||
- sequence entry must be enclosed in curly brace
|
- sequence entry must be enclosed in curly brace
|
||||||
|
|
||||||
ex : `grandfather.father.son{2}.age`
|
ex : `grandfather.father.son{2}.age`
|
||||||
|
|
||||||
|
The 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]`
|
||||||
|
|
||||||
with singlepair node, you can retriew corresponding scalar node with {0}
|
with singlepair node, you can retriew corresponding scalar node with {0}
|
||||||
|
|
||||||
```
|
ex yaml file :
|
||||||
/*
|
|
||||||
# ex yaml file :
|
```yml
|
||||||
product:
|
product:
|
||||||
- sku : BL394D
|
- sku : BL394D
|
||||||
quantity : 4
|
quantity : 4
|
||||||
description : Basketball
|
description : Basketball
|
||||||
*/
|
```
|
||||||
|
|
||||||
|
vala code :
|
||||||
|
|
||||||
|
```vala
|
||||||
...
|
...
|
||||||
Yaml.NodeRoot root = loader.get_nodes ();
|
Yaml.NodeRoot root = loader.get_nodes ();
|
||||||
Yaml.Node? node = null;
|
Yaml.Node? node = null;
|
||||||
if ((node = finder.find("product{0}.description{0}")) != null) {
|
if ((node = finder.find ("product{0}.description")) != null) {
|
||||||
var val = node.data;
|
var val = node.val ();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
-------------------
|
||||||
|
|
||||||
### more samples
|
### more samples
|
||||||
|
|
||||||
see samples files in ./samples directory
|
see samples files in ./samples directory
|
||||||
|
|
||||||
|
-------------------
|
||||||
|
|
||||||
### todo
|
### todo
|
||||||
|
|
||||||
* import clause
|
* ~~imports clause~~
|
||||||
* fix nodes traversing
|
* fix nodes traversing
|
||||||
* dumper
|
* dumper
|
||||||
|
* manage tag directives & tag
|
||||||
|
|
||||||
|
|
16
build.sh
16
build.sh
|
@ -36,6 +36,7 @@ lib="pluie-yaml-0.3"
|
||||||
cok="\033[1;38;5;37m"
|
cok="\033[1;38;5;37m"
|
||||||
cko="\033[1;38;5;204m"
|
cko="\033[1;38;5;204m"
|
||||||
off="\033[m"
|
off="\033[m"
|
||||||
|
resume=
|
||||||
# --------------------------------------------------------
|
# --------------------------------------------------------
|
||||||
function build.title()
|
function build.title()
|
||||||
{
|
{
|
||||||
|
@ -49,7 +50,11 @@ function build.title()
|
||||||
fi
|
fi
|
||||||
s="$cko<"
|
s="$cko<"
|
||||||
fi
|
fi
|
||||||
echo -e "\n $s $c1[$c2$1$c1] $state$off"
|
if [ ! -z $3 ]; then
|
||||||
|
echo -e " |- $c1[$c2$1$c1] $state$off"
|
||||||
|
else
|
||||||
|
echo -e "\n $s $c1[$c2$1$c1] $state$off"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
# --------------------------------------------------------
|
# --------------------------------------------------------
|
||||||
function build.lib()
|
function build.lib()
|
||||||
|
@ -72,7 +77,10 @@ function build.samples()
|
||||||
build.sample "$file"
|
build.sample "$file"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
echo
|
echo -e "\n RESUME : "
|
||||||
|
for t in $resume; do
|
||||||
|
build.title "${t:1}" ${t:0:1} 1
|
||||||
|
done
|
||||||
}
|
}
|
||||||
# --------------------------------------------------------
|
# --------------------------------------------------------
|
||||||
function build.sample()
|
function build.sample()
|
||||||
|
@ -84,7 +92,9 @@ function build.sample()
|
||||||
build.title "$f SAMPLE BUILD"
|
build.title "$f SAMPLE BUILD"
|
||||||
echo -e "\n$cmd"
|
echo -e "\n$cmd"
|
||||||
$cmd
|
$cmd
|
||||||
build.title "$f SAMPLE BUILD" $?
|
local done=$?
|
||||||
|
resume="$resume$done$f "
|
||||||
|
build.title "$f SAMPLE BUILD" $done
|
||||||
}
|
}
|
||||||
# --------------------------------------------------------
|
# --------------------------------------------------------
|
||||||
function build.main()
|
function build.main()
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
project:
|
project:
|
||||||
name : blabla
|
name : blabla
|
||||||
env : local
|
env : local
|
||||||
|
@ -15,12 +14,12 @@ project:
|
||||||
# redefined path values are relative to the current directory (if a relative path
|
# redefined path values are relative to the current directory (if a relative path
|
||||||
# is provided)
|
# is provided)
|
||||||
^path : ./config
|
^path : ./config
|
||||||
# you can also define any other var by prefixing key with ~
|
# you can also define any other var by prefixing key with ^
|
||||||
^dir : subdir
|
^dir : subdir
|
||||||
# and use it enclosed by ^
|
# and use it enclosed by ^
|
||||||
# here final test path will be "./config/subdir/test.yml"
|
# here final test path will be "./config/subdir/test.yml"
|
||||||
test : ^dir^/test.yml
|
test : ^dir^/test.yml
|
||||||
# here final db path will be "./config/db.yml"
|
# here final db path will be "./config/db.yml"
|
||||||
db : db.yml
|
db : db.yml
|
||||||
|
|
||||||
bilbo : tato
|
bilbo : tato
|
||||||
|
|
|
@ -39,7 +39,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 = true;
|
Pluie.Yaml.Scanner.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)) {
|
||||||
Yaml.NodeRoot root = loader.get_nodes ();
|
Yaml.NodeRoot root = loader.get_nodes ();
|
||||||
|
|
|
@ -39,8 +39,8 @@ 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;
|
||||||
var config = new Yaml.Config (path);
|
var config = new Yaml.Config (path, true);
|
||||||
var spath = "bo.host{0}";
|
var spath = "bo.host{0}";
|
||||||
var node = config.get (spath);
|
var node = config.get (spath);
|
||||||
if ((done = node != null)) {
|
if ((done = node != null)) {
|
||||||
|
|
|
@ -46,7 +46,35 @@ int main (string[] args)
|
||||||
var finder = new Yaml.Finder(root);
|
var finder = new Yaml.Finder(root);
|
||||||
Yaml.Node? node = null;
|
Yaml.Node? node = null;
|
||||||
|
|
||||||
var spath = "[product]{0}[description]";
|
var spath = "bill-to.family";
|
||||||
|
of.action ("Find node", spath);
|
||||||
|
if ((node = finder.find(spath)) != null) {
|
||||||
|
of.echo (node.to_string (false));
|
||||||
|
of.action ("get scalar value", spath);
|
||||||
|
of.echo ((node as Yaml.NodeSinglePair).scalar ().data);
|
||||||
|
|
||||||
|
of.action ("get parent node");
|
||||||
|
of.echo (node.parent.to_string ());
|
||||||
|
|
||||||
|
of.action ("get address node");
|
||||||
|
if ((node = (node.parent as Yaml.NodeMap).map["address"])!= null) {
|
||||||
|
of.echo (node.to_string (false));
|
||||||
|
(node as Yaml.NodeMap).display_childs ();
|
||||||
|
|
||||||
|
of.action ("Loop throught childs", node.name);
|
||||||
|
foreach (var child in (node as Yaml.NodeMap).map.values) {
|
||||||
|
of.echo (child.to_string (false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
of.state (node != null);
|
||||||
|
}
|
||||||
|
else of.state (node != null);
|
||||||
|
|
||||||
|
of.action ("Set find mode", "SQUARE_BRACKETS");
|
||||||
|
Yaml.BaseNode.mode = Yaml.FIND_MODE.SQUARE_BRACKETS;
|
||||||
|
of.state (true);
|
||||||
|
|
||||||
|
spath = "[product]{0}[description]";
|
||||||
// equivalent in DOT MODE
|
// equivalent in DOT MODE
|
||||||
// spath = "product{0}.description";
|
// spath = "product{0}.description";
|
||||||
of.action ("Find node", spath);
|
of.action ("Find node", spath);
|
||||||
|
@ -80,33 +108,6 @@ int main (string[] args)
|
||||||
}
|
}
|
||||||
else of.state (node != null);
|
else of.state (node != null);
|
||||||
|
|
||||||
of.action ("Set find mode", "DOT");
|
|
||||||
Yaml.BaseNode.mode = Yaml.FIND_MODE.DOT;
|
|
||||||
of.state (true);
|
|
||||||
|
|
||||||
spath = "bill-to.family";
|
|
||||||
of.action ("Find node", spath);
|
|
||||||
if ((node = finder.find(spath)) != null) {
|
|
||||||
of.echo (node.to_string (false));
|
|
||||||
of.action ("get scalar value", spath);
|
|
||||||
of.echo ((node as Yaml.NodeSinglePair).scalar ().data);
|
|
||||||
|
|
||||||
of.action ("get parent node");
|
|
||||||
of.echo (node.parent.to_string ());
|
|
||||||
|
|
||||||
of.action ("get address node");
|
|
||||||
if ((node = (node.parent as Yaml.NodeMap).map["address"])!= null) {
|
|
||||||
of.echo (node.to_string (false));
|
|
||||||
(node as Yaml.NodeMap).display_childs ();
|
|
||||||
|
|
||||||
of.action ("Loop throught childs", node.name);
|
|
||||||
foreach (var child in (node as Yaml.NodeMap).map.values) {
|
|
||||||
of.echo (child.to_string (false));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
of.state (node != null);
|
|
||||||
}
|
|
||||||
else of.state (node != null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
of.rs (done);
|
of.rs (done);
|
||||||
|
|
|
@ -43,19 +43,14 @@ 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.Scanner.DEBUG = false;
|
||||||
var config = new Yaml.Config (path);
|
var config = new Yaml.Config (path, true);
|
||||||
var spath = "^imports";
|
var spath = "^imports";
|
||||||
var node = config.get (spath);
|
var node = config.get (spath);
|
||||||
if ((done = node != null)) {
|
if ((done = node != null)) {
|
||||||
of.action ("retriew node from Yaml.Config", spath);
|
spath = "db.therapy.dbname{0}";
|
||||||
if ((node as Yaml.NodeMap).map.has_key ("^path")) {
|
|
||||||
of.echo ((node as Yaml.NodeMap).map["^path"].to_string (false));
|
|
||||||
}
|
|
||||||
of.echo (node.to_string (false));
|
|
||||||
spath = "therapy.dbname{0}";
|
|
||||||
of.action ("retriew imported node from Yaml.Config", spath);
|
of.action ("retriew imported node from Yaml.Config", spath);
|
||||||
var inode = config.get (spath);
|
var inode = config.get (spath);
|
||||||
if ((done = node != null)) {
|
if ((done = inode != null)) {
|
||||||
of.echo (inode.to_string (false));
|
of.echo (inode.to_string (false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,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 = true;
|
Pluie.Yaml.Scanner.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)) {
|
||||||
Yaml.NodeRoot root = loader.get_nodes ();
|
Yaml.NodeRoot root = loader.get_nodes ();
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class Pluie.Yaml.BaseNode : Object, Pluie.Yaml.Node
|
||||||
/**
|
/**
|
||||||
* find mode related to Yaml.FIND_MODE, default is Yaml.FIND_MODE.SQUARE_BRACKETS
|
* find mode related to Yaml.FIND_MODE, default is Yaml.FIND_MODE.SQUARE_BRACKETS
|
||||||
*/
|
*/
|
||||||
public static Yaml.FIND_MODE mode { get; set; default = Yaml.FIND_MODE.SQUARE_BRACKETS; }
|
public static Yaml.FIND_MODE mode { get; set; default = Yaml.FIND_MODE.DOT; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* node type related to Yaml.NODE_TYPE
|
* node type related to Yaml.NODE_TYPE
|
||||||
|
@ -54,9 +54,9 @@ public class Pluie.Yaml.BaseNode : Object, Pluie.Yaml.Node
|
||||||
public Yaml.NODE_TYPE node_type { get; internal set; }
|
public Yaml.NODE_TYPE node_type { get; internal set; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* current representation indent
|
* current representation level
|
||||||
*/
|
*/
|
||||||
public int indent { get; internal set; }
|
public int level { get; internal set; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parent node
|
* parent node
|
||||||
|
@ -76,33 +76,31 @@ public class Pluie.Yaml.BaseNode : Object, Pluie.Yaml.Node
|
||||||
/**
|
/**
|
||||||
* default Yaml.Node constructor
|
* default Yaml.Node constructor
|
||||||
* @param parent the parent node
|
* @param parent the parent node
|
||||||
* @param indent the current indentation in node representation string
|
|
||||||
* @param type the NODE_TYPE of Yaml.Node to create
|
* @param type the NODE_TYPE of Yaml.Node to create
|
||||||
*/
|
*/
|
||||||
public BaseNode (Yaml.Node? parent = null, int indent = 0, NODE_TYPE type = NODE_TYPE.UNDEFINED)
|
public BaseNode (Yaml.Node? parent = null, NODE_TYPE type = NODE_TYPE.UNDEFINED)
|
||||||
{
|
{
|
||||||
this.standard (parent, indent, type);
|
this.standard (parent, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor for root Yaml.Node
|
* constructor for root Yaml.Node
|
||||||
*/
|
*/
|
||||||
public BaseNode.root () {
|
public BaseNode.root () {
|
||||||
this.standard (null, -4, NODE_TYPE.ROOT);
|
this.standard (null, NODE_TYPE.ROOT);
|
||||||
this.name = "PluieYamlRootNode";
|
this.name = "PluieYamlRootNode";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor for standard Yaml.Node
|
* constructor for standard Yaml.Node
|
||||||
* @param parent the parent node
|
* @param parent the parent node
|
||||||
* @param indent the current indentation in node representation string
|
|
||||||
* @param type the NODE_TYPE of Yaml.Node to create
|
* @param type the NODE_TYPE of Yaml.Node to create
|
||||||
*/
|
*/
|
||||||
internal BaseNode.standard (Yaml.Node? parent = null, int indent = 0, NODE_TYPE type = NODE_TYPE.UNDEFINED)
|
internal BaseNode.standard (Yaml.Node? parent = null, NODE_TYPE type = NODE_TYPE.UNDEFINED)
|
||||||
{
|
{
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.node_type = type;
|
this.node_type = type;
|
||||||
this.indent = indent;
|
this.level = parent!=null ? parent.level + 1 : 0;
|
||||||
this.uuid = Yaml.uuid ();
|
this.uuid = Yaml.uuid ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +130,7 @@ public class Pluie.Yaml.BaseNode : Object, Pluie.Yaml.Node
|
||||||
*/
|
*/
|
||||||
public virtual Yaml.Node clone_node (string? name = null)
|
public virtual Yaml.Node clone_node (string? name = null)
|
||||||
{
|
{
|
||||||
return new BaseNode.standard (this.parent, this.indent);
|
return new BaseNode.standard (this.parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -226,30 +224,54 @@ public class Pluie.Yaml.BaseNode : Object, Pluie.Yaml.Node
|
||||||
return has;
|
return has;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public virtual void update_level()
|
||||||
|
{
|
||||||
|
this.level = this.parent != null ? this.parent.level + 1 : 0;
|
||||||
|
switch (this.node_type) {
|
||||||
|
case NODE_TYPE.SINGLE_PAIR :
|
||||||
|
(this as Yaml.NodeSinglePair).scalar ().update_level ();
|
||||||
|
break;
|
||||||
|
case NODE_TYPE.ROOT :
|
||||||
|
case NODE_TYPE.MAPPING :
|
||||||
|
foreach (var child in (this as Yaml.NodeMap).map.values) {
|
||||||
|
child.update_level ();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case NODE_TYPE.SEQUENCE :
|
||||||
|
foreach (var child in (this as Yaml.NodeSequence).list) {
|
||||||
|
child.update_level ();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get a presentation string of current Yaml.Node
|
* get a presentation string of current Yaml.Node
|
||||||
*/
|
*/
|
||||||
public string to_string (bool indentFormat = true, bool withParent = false, bool withUuid = false, bool withIndent = false, bool withRefCount = false)
|
public string to_string (bool indentFormat = true, bool withParent = false, bool withUuid = false, bool withLevel = false, bool withRefCount = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
return "%s%s%s%s%s%s%s%s".printf (
|
return "%s%s%s%s%s%s%s%s".printf (
|
||||||
this.node_type.is_root () ? "" : of.s_indent ((int8) (indentFormat ? this.indent : 0)),
|
this.node_type.is_root () ? "" : of.s_indent ((int8) (indentFormat ? (this.level-1)*4 : 0)),
|
||||||
of.c (ECHO.OPTION).s ("["),
|
of.c (ECHO.OPTION).s ("["),
|
||||||
of.c (ECHO.OPTION_SEP).s (this.node_type.infos ()),
|
|
||||||
this.name != null && !this.node_type.is_scalar ()
|
this.name != null && !this.node_type.is_scalar ()
|
||||||
? of.c (ECHO.TIME).s (" %s".printf (this.name))
|
? of.c (ECHO.TIME).s ("%s".printf (this.name))
|
||||||
: (
|
: (
|
||||||
this.node_type.is_scalar ()
|
this.node_type.is_scalar ()
|
||||||
? of.c(ECHO.DATE).s (" %s".printf (this.data))
|
? of.c(ECHO.DATE).s ("%s".printf (this.data))
|
||||||
: ""
|
: ""
|
||||||
),
|
),
|
||||||
withRefCount ? of.c (ECHO.COMMAND).s ("[%x]".printf (this.ref_count)) : "",
|
withRefCount ? of.c (ECHO.COMMAND).s ("[%lu]".printf (this.ref_count)) : "",
|
||||||
!withParent || this.parent == null
|
!withParent || this.parent == null
|
||||||
? ""
|
? ""
|
||||||
: of.c (ECHO.SECTION).s (" "+this.parent.name)+(
|
: of.c (ECHO.SECTION).s (" "+this.parent.name)+(
|
||||||
withIndent ? of.c (ECHO.NUM).s (" "+this.indent.to_string()) : ""
|
withLevel ? of.c (ECHO.NUM).s (" %d".printf (this.level)) : " "
|
||||||
),
|
),
|
||||||
|
of.c (ECHO.OPTION_SEP).s (" %s".printf(this.node_type.infos ())),
|
||||||
withUuid ? of.c (ECHO.COMMENT).s (" %s".printf(this.uuid[0:8]+"...")) : "",
|
withUuid ? of.c (ECHO.COMMENT).s (" %s".printf(this.uuid[0:8]+"...")) : "",
|
||||||
|
//~ of.c (ECHO.NUM).s ("%d".printf (this.level)),
|
||||||
of.c (ECHO.OPTION).s ("]")
|
of.c (ECHO.OPTION).s ("]")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,14 +32,17 @@ public class Pluie.Yaml.Config
|
||||||
/**
|
/**
|
||||||
* construct a Yaml Config for specifiyed path
|
* construct a Yaml Config for specifiyed path
|
||||||
*/
|
*/
|
||||||
public Config (string? path = null, Yaml.FIND_MODE mode = Yaml.FIND_MODE.DOT)
|
public Config (string? path = null, bool displayFile = false, Yaml.FIND_MODE mode = Yaml.FIND_MODE.DOT)
|
||||||
{
|
{
|
||||||
Yaml.BaseNode.mode = mode;
|
Yaml.BaseNode.mode = mode;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
if (this.path != null) {
|
if (this.path != null) {
|
||||||
this.loader = new Yaml.Loader (this.path, false, false);
|
this.loader = new Yaml.Loader (this.path, displayFile, false);
|
||||||
this.finder = new Yaml.Finder(this.loader.get_nodes ());
|
Yaml.NodeRoot? root = this.loader.get_nodes ();
|
||||||
this.get_imports ();
|
if (root != null) {
|
||||||
|
this.finder = new Yaml.Finder(root);
|
||||||
|
this.get_imports ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +58,9 @@ public class Pluie.Yaml.Config
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
public Yaml.NodeRoot root_node ()
|
public Yaml.NodeRoot root_node ()
|
||||||
{
|
{
|
||||||
return this.finder.context as Yaml.NodeRoot;
|
return this.finder.context as Yaml.NodeRoot;
|
||||||
|
@ -66,28 +72,30 @@ public class Pluie.Yaml.Config
|
||||||
public void get_imports ()
|
public void get_imports ()
|
||||||
{
|
{
|
||||||
var node = this.get("^imports") as Yaml.NodeMap;
|
var node = this.get("^imports") as Yaml.NodeMap;
|
||||||
var root = node.parent as Yaml.NodeRoot;
|
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
this.get_imports_var(node);
|
var root = node.parent as Yaml.NodeRoot;
|
||||||
var dir = this.strip_path(Path.get_dirname (this.path));
|
if (root != null && root.node_type.is_root ()) {
|
||||||
if (this.varmap.has_key ("path")) {
|
this.get_imports_var(node);
|
||||||
var p = this.strip_path(this.varmap["path"]);
|
var dir = this.strip_path(Path.get_dirname (this.path));
|
||||||
if (p != null) {
|
if (this.varmap.has_key ("path")) {
|
||||||
dir = Path.is_absolute(p) ? p : Path.build_filename(dir, p);
|
var p = this.strip_path(this.varmap["path"]);
|
||||||
|
if (p != null) {
|
||||||
|
dir = Path.is_absolute(p) ? p : Path.build_filename(dir, p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
this.update_var (node, dir);
|
||||||
this.update_var (node, dir);
|
|
||||||
foreach(var entry in this.paths.entries) {
|
foreach(var entry in this.paths.entries) {
|
||||||
var config = new Yaml.Config(entry.value);
|
var config = new Yaml.Config(entry.value);
|
||||||
Yaml.NodeMap sub = config.loader.get_nodes ();
|
Yaml.NodeMap sub = config.loader.get_nodes ();
|
||||||
Yaml.NodeMap n = new Yaml.NodeMap (root, 0, entry.key);
|
Yaml.NodeMap n = new Yaml.NodeMap (root, entry.key);
|
||||||
|
foreach(var subnode in sub.map.values) {
|
||||||
foreach(var subnode in sub.map.values) {
|
subnode.parent = null;
|
||||||
subnode.parent = null;
|
n.add(subnode);
|
||||||
|
}
|
||||||
n.add(subnode);
|
root.add (n);
|
||||||
}
|
}
|
||||||
root.add (n);
|
root.update_level();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,13 +37,12 @@ public class Pluie.Yaml.Document : Yaml.NodeMap
|
||||||
/**
|
/**
|
||||||
* construct a single/pair mapping node
|
* construct a single/pair mapping node
|
||||||
* @param parent the parent node
|
* @param parent the parent node
|
||||||
* @param indent the current indentation in node representation string
|
|
||||||
* @param name the current name (key) of sequence node
|
* @param name the current name (key) of sequence node
|
||||||
* @param data the current scalar data
|
* @param data the current scalar data
|
||||||
*/
|
*/
|
||||||
public Document (Yaml.Node? parent = null, int indent = 0, string? name = null, string? data = null)
|
public Document (Yaml.Node? parent = null, string? name = null, string? data = null)
|
||||||
{
|
{
|
||||||
this.standard (null, -4, NODE_TYPE.ROOT);
|
this.standard (null, NODE_TYPE.ROOT);
|
||||||
this.name = "PluieYamlRootNode";
|
this.name = "PluieYamlRootNode";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,10 +43,8 @@ public class Pluie.Yaml.Finder : Object
|
||||||
public Yaml.Node? context { get; internal set; }
|
public Yaml.Node? context { get; internal set; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default Yaml.Node constructor
|
* default Yaml.Finder constructor
|
||||||
* @param parent the parent node
|
* @param default Yaml.Node context
|
||||||
* @param indent the current indentation in node representation string
|
|
||||||
* @param type the NODE_TYPE of Yaml.Node to create
|
|
||||||
*/
|
*/
|
||||||
public Finder (Yaml.Node context)
|
public Finder (Yaml.Node context)
|
||||||
{
|
{
|
||||||
|
|
|
@ -64,8 +64,11 @@ public class Pluie.Yaml.Loader
|
||||||
}
|
}
|
||||||
this.scanner = new Yaml.Scanner (path);
|
this.scanner = new Yaml.Scanner (path);
|
||||||
if ((this.done = this.scanner.run()) && displayNode) {
|
if ((this.done = this.scanner.run()) && displayNode) {
|
||||||
this.get_nodes ().display_childs ();
|
var n = this.get_nodes ();
|
||||||
of.state(true);
|
if (n != null) {
|
||||||
|
n.display_childs ();
|
||||||
|
}
|
||||||
|
of.state(n != null);
|
||||||
}
|
}
|
||||||
if (!this.done) {
|
if (!this.done) {
|
||||||
var evt = this.scanner.get_error_event ();
|
var evt = this.scanner.get_error_event ();
|
||||||
|
@ -91,7 +94,7 @@ public class Pluie.Yaml.Loader
|
||||||
of.echo ();
|
of.echo ();
|
||||||
this.reader.rewind(new Io.StreamLineMark(0, 0));
|
this.reader.rewind(new Io.StreamLineMark(0, 0));
|
||||||
int line = 0;
|
int line = 0;
|
||||||
string? data = null;;
|
string? data = null;
|
||||||
while (this.reader.readable) {
|
while (this.reader.readable) {
|
||||||
line = this.reader.line + 1;
|
line = this.reader.line + 1;
|
||||||
data = this.reader.read ();
|
data = this.reader.read ();
|
||||||
|
@ -105,13 +108,16 @@ public class Pluie.Yaml.Loader
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
of.echo ("%s%s%s".printf (
|
if (data !=null) {
|
||||||
of.c (ECHO.MICROTIME ).s (" %03d ".printf (line)),
|
ECHO color = data.strip()[0] != '#' ? ECHO.COMMAND : ECHO.COMMENT;
|
||||||
of.c (ECHO.DATE).s ("| "),
|
of.echo ("%s%s%s".printf (
|
||||||
errorLine > 0 && line == errorLine
|
of.c (ECHO.MICROTIME ).s (" %03d ".printf (line)),
|
||||||
? of.c (ECHO.FAIL).s (data)
|
of.c (ECHO.DATE).s ("| "),
|
||||||
: of.c (ECHO.COMMAND).s (data)
|
errorLine > 0 && line == errorLine
|
||||||
), errorLine == 0 || line < errorLine);
|
? of.c (ECHO.FAIL).s (data)
|
||||||
|
: of.c (color).s (data)
|
||||||
|
), errorLine == 0 || line < errorLine);
|
||||||
|
}
|
||||||
if (errorLine > 0 && line == errorLine) {
|
if (errorLine > 0 && line == errorLine) {
|
||||||
int len = of.term_width - data.length - 13;
|
int len = of.term_width - data.length - 13;
|
||||||
stdout.printf (of.c (ECHO.FAIL).s (@" %$(len)s ".printf (" ")));
|
stdout.printf (of.c (ECHO.FAIL).s (@" %$(len)s ".printf (" ")));
|
||||||
|
|
|
@ -42,7 +42,7 @@ public interface Pluie.Yaml.Node : Object
|
||||||
*/
|
*/
|
||||||
public abstract Yaml.NODE_TYPE node_type { get; internal set; }
|
public abstract Yaml.NODE_TYPE node_type { get; internal set; }
|
||||||
|
|
||||||
public abstract int indent { get; internal set; }
|
public abstract int level { get; internal set; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parent node
|
* parent node
|
||||||
|
@ -109,9 +109,15 @@ public interface Pluie.Yaml.Node : Object
|
||||||
*/
|
*/
|
||||||
public abstract Yaml.Node? get_root_node ();
|
public abstract Yaml.Node? get_root_node ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update node level and all childs level
|
||||||
|
*/
|
||||||
|
public abstract void update_level ();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get a presentation string of current Yaml.Node
|
* get a presentation string of current Yaml.Node
|
||||||
*/
|
*/
|
||||||
public abstract string to_string (bool indentFormat = true, bool withParent = false, bool withUuid = true, bool withIndent = false, bool withRefCount = true);
|
public abstract string to_string (bool indentFormat = true, bool withParent = false, bool withUuid = false, bool withIndent = true, bool withRefCount = false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,12 +44,11 @@ public class Pluie.Yaml.NodeMap : Yaml.BaseNode, Yaml.NodeCollection
|
||||||
/**
|
/**
|
||||||
* construct a mapping node
|
* construct a mapping node
|
||||||
* @param parent the parent node
|
* @param parent the parent node
|
||||||
* @param indent the current indentation in node representation string
|
|
||||||
* @param name the current name (key) of mapping node
|
* @param name the current name (key) of mapping node
|
||||||
*/
|
*/
|
||||||
public NodeMap (Yaml.Node? parent = null, int indent = 0, string? name = null)
|
public NodeMap (Yaml.Node? parent = null, string? name = null)
|
||||||
{
|
{
|
||||||
base (parent, indent, NODE_TYPE.MAPPING);
|
base (parent, NODE_TYPE.MAPPING);
|
||||||
this.map = new HashMap<string, Yaml.Node> ();
|
this.map = new HashMap<string, Yaml.Node> ();
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
@ -74,7 +73,7 @@ public class Pluie.Yaml.NodeMap : Yaml.BaseNode, Yaml.NodeCollection
|
||||||
public override bool add (Yaml.Node node)
|
public override bool add (Yaml.Node node)
|
||||||
{
|
{
|
||||||
node.on_change_parent ();
|
node.on_change_parent ();
|
||||||
node.indent = this.indent + 4;
|
node.level = this.level + 1;
|
||||||
node.parent = this;
|
node.parent = this;
|
||||||
if (this.map == null) {
|
if (this.map == null) {
|
||||||
this.map = new HashMap<string, Yaml.Node> ();
|
this.map = new HashMap<string, Yaml.Node> ();
|
||||||
|
@ -182,7 +181,7 @@ public class Pluie.Yaml.NodeMap : Yaml.BaseNode, Yaml.NodeCollection
|
||||||
public override Yaml.Node clone_node (string? name = null)
|
public override Yaml.Node clone_node (string? name = null)
|
||||||
{
|
{
|
||||||
var key = name != null ? name : this.name;
|
var key = name != null ? name : this.name;
|
||||||
Yaml.Node clone = new Yaml.NodeMap (this.parent, this.indent, key);
|
Yaml.Node clone = new Yaml.NodeMap (this.parent, key);
|
||||||
foreach (string k in this.map.keys) {
|
foreach (string k in this.map.keys) {
|
||||||
var n = this.map.get(k).clone_node();
|
var n = this.map.get(k).clone_node();
|
||||||
n.parent = clone;
|
n.parent = clone;
|
||||||
|
@ -190,5 +189,4 @@ public class Pluie.Yaml.NodeMap : Yaml.BaseNode, Yaml.NodeCollection
|
||||||
}
|
}
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,13 +37,12 @@ public class Pluie.Yaml.NodeRoot : Yaml.NodeMap
|
||||||
/**
|
/**
|
||||||
* construct a single/pair mapping node
|
* construct a single/pair mapping node
|
||||||
* @param parent the parent node
|
* @param parent the parent node
|
||||||
* @param indent the current indentation in node representation string
|
|
||||||
* @param name the current name (key) of sequence node
|
* @param name the current name (key) of sequence node
|
||||||
* @param data the current scalar data
|
* @param data the current scalar data
|
||||||
*/
|
*/
|
||||||
public NodeRoot (Yaml.Node? parent = null, int indent = 0, string? name = null, string? data = null)
|
public NodeRoot (Yaml.Node? parent = null, string? name = null, string? data = null)
|
||||||
{
|
{
|
||||||
this.standard (null, -4, NODE_TYPE.ROOT);
|
this.standard (null, NODE_TYPE.ROOT);
|
||||||
this.name = "PluieYamlRootNode";
|
this.name = "PluieYamlRootNode";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,12 +37,11 @@ public class Pluie.Yaml.NodeScalar : Yaml.BaseNode
|
||||||
/**
|
/**
|
||||||
* construct a scalar node
|
* construct a scalar node
|
||||||
* @param parent the parent node
|
* @param parent the parent node
|
||||||
* @param indent the current indentation in node representation string
|
|
||||||
* @param data the current scalar data
|
* @param data the current scalar data
|
||||||
*/
|
*/
|
||||||
public NodeScalar (Yaml.Node? parent = null, int indent = 0, string? data = null)
|
public NodeScalar (Yaml.Node? parent = null, string? data = null)
|
||||||
{
|
{
|
||||||
base (parent, indent, NODE_TYPE.SCALAR);
|
base (parent, NODE_TYPE.SCALAR);
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +51,6 @@ public class Pluie.Yaml.NodeScalar : Yaml.BaseNode
|
||||||
*/
|
*/
|
||||||
public override Yaml.Node clone_node (string? name = null)
|
public override Yaml.Node clone_node (string? name = null)
|
||||||
{
|
{
|
||||||
return new Yaml.NodeScalar (this.parent, this.indent, this.data);
|
return new Yaml.NodeScalar (this.parent, this.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,12 +44,11 @@ public class Pluie.Yaml.NodeSequence : Yaml.BaseNode, Yaml.NodeCollection
|
||||||
/**
|
/**
|
||||||
* construct a sequence node
|
* construct a sequence node
|
||||||
* @param parent the parent node
|
* @param parent the parent node
|
||||||
* @param indent the current indentation in node representation string
|
|
||||||
* @param name the current name (key) of sequence node
|
* @param name the current name (key) of sequence node
|
||||||
*/
|
*/
|
||||||
public NodeSequence (Yaml.Node? parent = null, int indent = 0, string? name = null)
|
public NodeSequence (Yaml.Node? parent = null, string? name = null)
|
||||||
{
|
{
|
||||||
base (parent, indent, NODE_TYPE.SEQUENCE);
|
base (parent, NODE_TYPE.SEQUENCE);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +75,7 @@ public class Pluie.Yaml.NodeSequence : Yaml.BaseNode, Yaml.NodeCollection
|
||||||
this.list = new ArrayList<Yaml.Node> ();
|
this.list = new ArrayList<Yaml.Node> ();
|
||||||
}
|
}
|
||||||
node.on_change_parent ();
|
node.on_change_parent ();
|
||||||
node.indent = this.indent + 4;
|
node.level = this.level + 1;
|
||||||
node.parent = this;
|
node.parent = this;
|
||||||
return this.list.add (node);
|
return this.list.add (node);
|
||||||
}
|
}
|
||||||
|
@ -88,7 +87,7 @@ public class Pluie.Yaml.NodeSequence : Yaml.BaseNode, Yaml.NodeCollection
|
||||||
*/
|
*/
|
||||||
public Yaml.Node add_scalar (string? data = null)
|
public Yaml.Node add_scalar (string? data = null)
|
||||||
{
|
{
|
||||||
Yaml.Node scalar = new Yaml.NodeScalar (this, this.indent+4, data);
|
Yaml.Node scalar = new Yaml.NodeScalar (this, data);
|
||||||
this.add (scalar);
|
this.add (scalar);
|
||||||
return scalar;
|
return scalar;
|
||||||
}
|
}
|
||||||
|
@ -201,7 +200,7 @@ public class Pluie.Yaml.NodeSequence : Yaml.BaseNode, Yaml.NodeCollection
|
||||||
public override Yaml.Node clone_node (string? name = null)
|
public override Yaml.Node clone_node (string? name = null)
|
||||||
{
|
{
|
||||||
var key = name != null ? name : this.name;
|
var key = name != null ? name : this.name;
|
||||||
Yaml.Node clone = new Yaml.NodeSequence (this.parent, this.indent, key);
|
Yaml.Node clone = new Yaml.NodeSequence (this.parent, key);
|
||||||
if (this.list!= null && this.list.size > 0) {
|
if (this.list!= null && this.list.size > 0) {
|
||||||
foreach (Yaml.Node child in this.list) {
|
foreach (Yaml.Node child in this.list) {
|
||||||
var n = child.clone_node();
|
var n = child.clone_node();
|
||||||
|
|
|
@ -37,16 +37,15 @@ public class Pluie.Yaml.NodeSinglePair : Yaml.NodeMap
|
||||||
/**
|
/**
|
||||||
* construct a single/pair mapping node
|
* construct a single/pair mapping node
|
||||||
* @param parent the parent node
|
* @param parent the parent node
|
||||||
* @param indent the current indentation in node representation string
|
|
||||||
* @param name the current name (key) of sequence node
|
* @param name the current name (key) of sequence node
|
||||||
* @param data the current scalar data
|
* @param data the current scalar data
|
||||||
*/
|
*/
|
||||||
public NodeSinglePair (Yaml.Node? parent = null, int indent = 0, string? name = null, string? data = null)
|
public NodeSinglePair (Yaml.Node? parent = null, string? name = null, string? data = null)
|
||||||
{
|
{
|
||||||
this.standard (parent, indent, NODE_TYPE.SINGLE_PAIR);
|
this.standard (parent, NODE_TYPE.SINGLE_PAIR);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
var scalar = new Yaml.NodeScalar (this, this.indent+4, data);
|
var scalar = new Yaml.NodeScalar (this, data);
|
||||||
scalar.name = "singlepair";
|
scalar.name = "singlepair";
|
||||||
this.add (scalar);
|
this.add (scalar);
|
||||||
}
|
}
|
||||||
|
@ -68,7 +67,7 @@ public class Pluie.Yaml.NodeSinglePair : Yaml.NodeMap
|
||||||
public override Yaml.Node clone_node (string? name = null)
|
public override Yaml.Node clone_node (string? name = null)
|
||||||
{
|
{
|
||||||
var key = name != null ? name : this.name;
|
var key = name != null ? name : this.name;
|
||||||
Yaml.Node clone = new Yaml.NodeSinglePair (this.parent, this.indent, key, this.scalar ().data);
|
Yaml.Node clone = new Yaml.NodeSinglePair (this.parent, key, this.scalar ().data);
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,9 +77,9 @@ public class Pluie.Yaml.Processor
|
||||||
Yaml.Node node;
|
Yaml.Node node;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* previous indent
|
* previous level
|
||||||
*/
|
*/
|
||||||
int prev_indent;
|
int prev_level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -163,8 +163,8 @@ public class Pluie.Yaml.Processor
|
||||||
this.root = new Yaml.NodeRoot ();
|
this.root = new Yaml.NodeRoot ();
|
||||||
this.prev_node = this.root;
|
this.prev_node = this.root;
|
||||||
this.parent_node = this.root;
|
this.parent_node = this.root;
|
||||||
this.prev_indent = this.root.indent;
|
this.prev_level = this.root.level;
|
||||||
int indent = this.root.indent +4;
|
int level = this.root.level + 1;
|
||||||
var it = this.events.iterator ();
|
var it = this.events.iterator ();
|
||||||
var change = false;
|
var change = false;
|
||||||
string? key = null;
|
string? key = null;
|
||||||
|
@ -179,8 +179,10 @@ public class Pluie.Yaml.Processor
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (evt.evtype.is_mapping_end () || evt.evtype.is_sequence_end ()) {
|
if (evt.evtype.is_mapping_end () || evt.evtype.is_sequence_end ()) {
|
||||||
indent -= 4;
|
level -= 4;
|
||||||
this.parent_node = this.prev_node.parent != this.root ? this.prev_node.parent.parent : this.root;
|
this.parent_node = this.prev_node.parent != null && this.prev_node.parent != this.root
|
||||||
|
? this.prev_node.parent.parent
|
||||||
|
: this.root;
|
||||||
this.prev_node = this.parent_node;
|
this.prev_node = this.parent_node;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -188,20 +190,20 @@ public class Pluie.Yaml.Processor
|
||||||
evt = this.next_event(it);
|
evt = this.next_event(it);
|
||||||
if (evt.evtype.is_mapping_start ()) {
|
if (evt.evtype.is_mapping_start ()) {
|
||||||
key = "_%d".printf((this.parent_node as Yaml.NodeSequence).get_size());
|
key = "_%d".printf((this.parent_node as Yaml.NodeSequence).get_size());
|
||||||
this.node = new Yaml.NodeMap (this.parent_node, indent, key);
|
this.node = new Yaml.NodeMap (this.parent_node, key);
|
||||||
key = null;
|
key = null;
|
||||||
indent += 4;
|
level += 1;
|
||||||
change = true;
|
change = true;
|
||||||
}
|
}
|
||||||
else if (evt.evtype.is_scalar ()) {
|
else if (evt.evtype.is_scalar ()) {
|
||||||
var content = evt.data["data"];
|
var content = evt.data["data"];
|
||||||
this.node = new Yaml.NodeScalar (this.parent_node, indent, content);
|
this.node = new Yaml.NodeScalar (this.parent_node, content);
|
||||||
change = true;
|
change = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (beginFlowSeq && evt.evtype.is_scalar ()) {
|
if (beginFlowSeq && evt.evtype.is_scalar ()) {
|
||||||
var content = evt.data["data"];
|
var content = evt.data["data"];
|
||||||
this.node = new Yaml.NodeScalar (this.parent_node, indent, content);
|
this.node = new Yaml.NodeScalar (this.parent_node, content);
|
||||||
change = true;
|
change = true;
|
||||||
beginFlowSeq = false;
|
beginFlowSeq = false;
|
||||||
}
|
}
|
||||||
|
@ -212,7 +214,7 @@ public class Pluie.Yaml.Processor
|
||||||
if (evt.evtype.is_scalar ()) {
|
if (evt.evtype.is_scalar ()) {
|
||||||
var content = evt.data["data"];
|
var content = evt.data["data"];
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
this.node = new Yaml.NodeSinglePair (this.parent_node, indent, key, content);
|
this.node = new Yaml.NodeSinglePair (this.parent_node, key, content);
|
||||||
change = true;
|
change = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -226,18 +228,18 @@ public class Pluie.Yaml.Processor
|
||||||
if (refnode != null) {
|
if (refnode != null) {
|
||||||
this.node = refnode.clone_node (key);
|
this.node = refnode.clone_node (key);
|
||||||
this.parent_node.add (this.node);
|
this.parent_node.add (this.node);
|
||||||
this.prev_node = this.node;
|
this.prev_node = this.node;
|
||||||
this.prev_indent = this.prev_node.indent;
|
this.prev_level = this.prev_node.level;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (evt.evtype.is_mapping_start ()) {
|
if (evt.evtype.is_mapping_start ()) {
|
||||||
this.node = new Yaml.NodeMap (this.parent_node, indent, key);
|
this.node = new Yaml.NodeMap (this.parent_node, key);
|
||||||
indent += 4;
|
level += 1;
|
||||||
change = true;
|
change = true;
|
||||||
}
|
}
|
||||||
else if (evt.evtype.is_sequence_start ()) {
|
else if (evt.evtype.is_sequence_start ()) {
|
||||||
this.node = new Yaml.NodeSequence (this.parent_node, indent, key);
|
this.node = new Yaml.NodeSequence (this.parent_node, key);
|
||||||
indent += 4;
|
level += 1;
|
||||||
change = true;
|
change = true;
|
||||||
beginFlowSeq = true;
|
beginFlowSeq = true;
|
||||||
}
|
}
|
||||||
|
@ -255,7 +257,7 @@ public class Pluie.Yaml.Processor
|
||||||
this.parent_node = this.node;
|
this.parent_node = this.node;
|
||||||
}
|
}
|
||||||
this.prev_node = this.node;
|
this.prev_node = this.node;
|
||||||
this.prev_indent = this.prev_node.indent;
|
this.prev_level = this.prev_node.level;
|
||||||
this.node = null;
|
this.node = null;
|
||||||
change = false;
|
change = false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user