add samples json & yaml + fix flow entries + update build.sh
This commit is contained in:
parent
52db4f70a6
commit
8a4764080b
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,2 @@
|
||||||
build/
|
build/
|
||||||
main
|
bin/
|
||||||
|
|
0
bin/.gitkeep
Normal file
0
bin/.gitkeep
Normal file
71
build.sh
71
build.sh
|
@ -1,16 +1,69 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# --------------------------------------------------------
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
lib="pluie-yaml-0.3"
|
||||||
|
c1="\033[1;38;5;215m"
|
||||||
|
c2="\033[1;38;5;97m"
|
||||||
|
cok="\033[1;38;5;37m"
|
||||||
|
cko="\033[1;38;5;204m"
|
||||||
|
off="\033[m"
|
||||||
|
# --------------------------------------------------------
|
||||||
|
function build.title()
|
||||||
|
{
|
||||||
|
local s="$cko>"
|
||||||
|
local c3=""
|
||||||
|
local state=""
|
||||||
|
if [ ! -z "$2" ]; then
|
||||||
|
state="${cko}FAILED"
|
||||||
|
if [ $2 -eq 0 ]; then
|
||||||
|
state="${cok}SUCCESS"
|
||||||
|
fi
|
||||||
|
s="$cko<"
|
||||||
|
fi
|
||||||
|
echo -e "\n $s $c1[$c2$1$c1] $state$off"
|
||||||
|
}
|
||||||
|
# --------------------------------------------------------
|
||||||
|
function build.lib()
|
||||||
|
{
|
||||||
cd "$DIR"
|
cd "$DIR"
|
||||||
|
build.title "$lib LIB BUILD"
|
||||||
|
echo
|
||||||
meson --prefix=/usr ./ build
|
meson --prefix=/usr ./ build
|
||||||
sudo ninja -v install -C build
|
sudo ninja -v install -C build
|
||||||
if [ $? -eq 0 ]; then
|
local rs=$?
|
||||||
echo "== LIB BUILD SUCCESS =="
|
build.title "$lib LIB BUILD" $rs
|
||||||
valac -v --pkg gee-0.8 --pkg pluie-echo-0.2 --pkg pluie-yaml-0.3 main.vala
|
return $rs
|
||||||
if [ $? -eq 0 ]; then
|
}
|
||||||
echo "== BUILD SUCCESS =="
|
# --------------------------------------------------------
|
||||||
else
|
function build.samples()
|
||||||
echo "== BUILD FAILED =="
|
{
|
||||||
|
for file in ./samples/*.vala
|
||||||
|
do
|
||||||
|
if [[ -f $file ]]; then
|
||||||
|
build.sample "$file"
|
||||||
fi
|
fi
|
||||||
else
|
done
|
||||||
echo "== LIB BUILD FAILED =="
|
echo
|
||||||
|
}
|
||||||
|
# --------------------------------------------------------
|
||||||
|
function build.sample()
|
||||||
|
{
|
||||||
|
local f="$(basename $1)"
|
||||||
|
local fx="${f:0:-5}"
|
||||||
|
local state="FAILED"
|
||||||
|
local cmd="valac -v --pkg gee-0.8 --pkg pluie-echo-0.2 --pkg $lib $1 -o ./bin/$fx"
|
||||||
|
build.title "$f SAMPLE BUILD"
|
||||||
|
echo -e "\n$cmd"
|
||||||
|
$cmd
|
||||||
|
build.title "$f SAMPLE BUILD" $?
|
||||||
|
}
|
||||||
|
# --------------------------------------------------------
|
||||||
|
function build.main()
|
||||||
|
{
|
||||||
|
build.lib
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
build.samples
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
build.main
|
||||||
|
|
22
resources/test.json
Normal file
22
resources/test.json
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
"glossary": {
|
||||||
|
"title": "example glossary",
|
||||||
|
"GlossDiv": {
|
||||||
|
"title": "S",
|
||||||
|
"GlossList": {
|
||||||
|
"GlossEntry": {
|
||||||
|
"ID": "SGML",
|
||||||
|
"SortAs": "SGML",
|
||||||
|
"GlossTerm": "Standard Generalized Markup Language",
|
||||||
|
"Acronym": "SGML",
|
||||||
|
"Abbrev": "ISO 8879:1986",
|
||||||
|
"GlossDef": {
|
||||||
|
"para": "A meta-markup language, used to create markup languages such as DocBook.",
|
||||||
|
"GlossSeeAlso": ["GML", "XML"]
|
||||||
|
},
|
||||||
|
"GlossSee": "markup"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
samples/json-load.vala
Normal file
23
samples/json-load.vala
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
using GLib;
|
||||||
|
using Gee;
|
||||||
|
using Pluie;
|
||||||
|
|
||||||
|
int main (string[] args)
|
||||||
|
{
|
||||||
|
Echo.init(false);
|
||||||
|
|
||||||
|
var path = "resources/test.json";
|
||||||
|
var done = false;
|
||||||
|
|
||||||
|
of.title ("Pluie Yaml Parser", Pluie.Yaml.VERSION, "a-sansara");
|
||||||
|
Pluie.Yaml.Scanner.DEBUG = true;
|
||||||
|
var loader = new Yaml.Loader (path, true, true);
|
||||||
|
if ((done = loader.done)) {
|
||||||
|
Yaml.NodeRoot root = loader.get_nodes ();
|
||||||
|
}
|
||||||
|
|
||||||
|
of.rs (done);
|
||||||
|
of.echo ();
|
||||||
|
return (int) done;
|
||||||
|
|
||||||
|
}
|
|
@ -67,7 +67,6 @@ public class Pluie.Yaml.Processor
|
||||||
public void read ()
|
public void read ()
|
||||||
{
|
{
|
||||||
of.action ("Reading events");
|
of.action ("Reading events");
|
||||||
EVT? prevEvent = null;
|
|
||||||
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 (" [ %s"+@" %$(len)s "+", %d, %s", event.evtype.infos (), " ", event.line, event.style != null ? event.style.to_string () : "0");
|
||||||
|
@ -81,7 +80,7 @@ public class Pluie.Yaml.Processor
|
||||||
}
|
}
|
||||||
stdout.printf (" }");
|
stdout.printf (" }");
|
||||||
}
|
}
|
||||||
of.echo ("]\n");
|
of.echo ("]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,16 +131,17 @@ public class Pluie.Yaml.Processor
|
||||||
*/
|
*/
|
||||||
public bool run ()
|
public bool run ()
|
||||||
{
|
{
|
||||||
|
//~ if (Pluie.Yaml.Scanner.DEBUG) this.read ();
|
||||||
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_indent = this.root.indent;
|
||||||
int indent = this.root.indent +4;
|
int indent = this.root.indent +4;
|
||||||
EVT? prevEvent = null;
|
|
||||||
var it = this.events.iterator ();
|
var it = this.events.iterator ();
|
||||||
var change = false;
|
var change = false;
|
||||||
string? key = null;
|
string? key = null;
|
||||||
string? id = null;
|
string? id = null;
|
||||||
|
bool beginFlowSeq = false;
|
||||||
Yaml.Event? evt;
|
Yaml.Event? evt;
|
||||||
if (Pluie.Yaml.Scanner.DEBUG) of.action ("Processing events");
|
if (Pluie.Yaml.Scanner.DEBUG) of.action ("Processing events");
|
||||||
for (var has_next = it.next (); has_next; has_next = it.next ()) {
|
for (var has_next = it.next (); has_next; has_next = it.next ()) {
|
||||||
|
@ -165,6 +165,17 @@ public class Pluie.Yaml.Processor
|
||||||
indent += 4;
|
indent += 4;
|
||||||
change = true;
|
change = true;
|
||||||
}
|
}
|
||||||
|
else if (evt.evtype.is_scalar ()) {
|
||||||
|
var content = evt.data["data"];
|
||||||
|
this.node = new Yaml.NodeScalar (this.parent_node, indent, content);
|
||||||
|
change = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (beginFlowSeq && evt.evtype.is_scalar ()) {
|
||||||
|
var content = evt.data["data"];
|
||||||
|
this.node = new Yaml.NodeScalar (this.parent_node, indent, content);
|
||||||
|
change = true;
|
||||||
|
beginFlowSeq = false;
|
||||||
}
|
}
|
||||||
if (evt.evtype.is_key () && (evt = this.get_value_key_event (it)) != null) {
|
if (evt.evtype.is_key () && (evt = this.get_value_key_event (it)) != null) {
|
||||||
key = evt.data["data"];
|
key = evt.data["data"];
|
||||||
|
@ -200,6 +211,7 @@ public class Pluie.Yaml.Processor
|
||||||
this.node = new Yaml.NodeSequence (this.parent_node, indent, key);
|
this.node = new Yaml.NodeSequence (this.parent_node, indent, key);
|
||||||
indent += 4;
|
indent += 4;
|
||||||
change = true;
|
change = true;
|
||||||
|
beginFlowSeq = true;
|
||||||
}
|
}
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
if (this.node != null) {
|
if (this.node != null) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user