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/
|
||||
main
|
||||
bin/
|
||||
|
|
0
bin/.gitkeep
Normal file
0
bin/.gitkeep
Normal file
79
build.sh
79
build.sh
|
@ -1,16 +1,69 @@
|
|||
#!/bin/bash
|
||||
# --------------------------------------------------------
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd "$DIR"
|
||||
meson --prefix=/usr ./ build
|
||||
sudo ninja -v install -C build
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "== LIB BUILD SUCCESS =="
|
||||
valac -v --pkg gee-0.8 --pkg pluie-echo-0.2 --pkg pluie-yaml-0.3 main.vala
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "== BUILD SUCCESS =="
|
||||
else
|
||||
echo "== BUILD FAILED =="
|
||||
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
|
||||
else
|
||||
echo "== LIB BUILD FAILED =="
|
||||
fi
|
||||
s="$cko<"
|
||||
fi
|
||||
echo -e "\n $s $c1[$c2$1$c1] $state$off"
|
||||
}
|
||||
# --------------------------------------------------------
|
||||
function build.lib()
|
||||
{
|
||||
cd "$DIR"
|
||||
build.title "$lib LIB BUILD"
|
||||
echo
|
||||
meson --prefix=/usr ./ build
|
||||
sudo ninja -v install -C build
|
||||
local rs=$?
|
||||
build.title "$lib LIB BUILD" $rs
|
||||
return $rs
|
||||
}
|
||||
# --------------------------------------------------------
|
||||
function build.samples()
|
||||
{
|
||||
for file in ./samples/*.vala
|
||||
do
|
||||
if [[ -f $file ]]; then
|
||||
build.sample "$file"
|
||||
fi
|
||||
done
|
||||
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
|
||||
}
|
||||
|
||||
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 ()
|
||||
{
|
||||
of.action ("Reading events");
|
||||
EVT? prevEvent = null;
|
||||
foreach (Yaml.Event event in this.events) {
|
||||
int len = 24 - event.evtype.infos ().length;
|
||||
stdout.printf (" [ %s"+@" %$(len)s "+", %d, %s", event.evtype.infos (), " ", event.line, event.style != null ? event.style.to_string () : "0");
|
||||
|
@ -81,7 +80,7 @@ public class Pluie.Yaml.Processor
|
|||
}
|
||||
stdout.printf (" }");
|
||||
}
|
||||
of.echo ("]\n");
|
||||
of.echo ("]");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,16 +131,17 @@ public class Pluie.Yaml.Processor
|
|||
*/
|
||||
public bool run ()
|
||||
{
|
||||
//~ if (Pluie.Yaml.Scanner.DEBUG) this.read ();
|
||||
this.root = new Yaml.NodeRoot ();
|
||||
this.prev_node = this.root;
|
||||
this.parent_node = this.root;
|
||||
this.prev_indent = this.root.indent;
|
||||
int indent = this.root.indent +4;
|
||||
EVT? prevEvent = null;
|
||||
var it = this.events.iterator ();
|
||||
var change = false;
|
||||
string? key = null;
|
||||
string? id = null;
|
||||
bool beginFlowSeq = false;
|
||||
Yaml.Event? evt;
|
||||
if (Pluie.Yaml.Scanner.DEBUG) of.action ("Processing events");
|
||||
for (var has_next = it.next (); has_next; has_next = it.next ()) {
|
||||
|
@ -165,6 +165,17 @@ public class Pluie.Yaml.Processor
|
|||
indent += 4;
|
||||
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) {
|
||||
key = evt.data["data"];
|
||||
|
@ -200,6 +211,7 @@ public class Pluie.Yaml.Processor
|
|||
this.node = new Yaml.NodeSequence (this.parent_node, indent, key);
|
||||
indent += 4;
|
||||
change = true;
|
||||
beginFlowSeq = true;
|
||||
}
|
||||
if (id != null) {
|
||||
if (this.node != null) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user