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
79
build.sh
79
build.sh
|
@ -1,16 +1,69 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# --------------------------------------------------------
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
cd "$DIR"
|
lib="pluie-yaml-0.3"
|
||||||
meson --prefix=/usr ./ build
|
c1="\033[1;38;5;215m"
|
||||||
sudo ninja -v install -C build
|
c2="\033[1;38;5;97m"
|
||||||
if [ $? -eq 0 ]; then
|
cok="\033[1;38;5;37m"
|
||||||
echo "== LIB BUILD SUCCESS =="
|
cko="\033[1;38;5;204m"
|
||||||
valac -v --pkg gee-0.8 --pkg pluie-echo-0.2 --pkg pluie-yaml-0.3 main.vala
|
off="\033[m"
|
||||||
if [ $? -eq 0 ]; then
|
# --------------------------------------------------------
|
||||||
echo "== BUILD SUCCESS =="
|
function build.title()
|
||||||
else
|
{
|
||||||
echo "== BUILD FAILED =="
|
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
|
fi
|
||||||
else
|
echo -e "\n $s $c1[$c2$1$c1] $state$off"
|
||||||
echo "== LIB BUILD FAILED =="
|
}
|
||||||
fi
|
# --------------------------------------------------------
|
||||||
|
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
|
||||||
|
|
|
@ -28,7 +28,7 @@ configure_file(
|
||||||
configuration: conf
|
configuration: conf
|
||||||
)
|
)
|
||||||
|
|
||||||
sources = [
|
sources = [
|
||||||
'build/install.vala',
|
'build/install.vala',
|
||||||
'src/vala/Pluie/Io.Reader.vala',
|
'src/vala/Pluie/Io.Reader.vala',
|
||||||
'src/vala/Pluie/Io.StreamLineMark.vala',
|
'src/vala/Pluie/Io.StreamLineMark.vala',
|
||||||
|
|
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 ()
|
||||||
{
|
{
|
||||||
this.root = new Yaml.NodeRoot ();
|
//~ if (Pluie.Yaml.Scanner.DEBUG) this.read ();
|
||||||
this.prev_node = this.root;
|
this.root = new Yaml.NodeRoot ();
|
||||||
this.parent_node = this.root;
|
this.prev_node = this.root;
|
||||||
this.prev_indent = this.root.indent;
|
this.parent_node = this.root;
|
||||||
int indent = this.root.indent +4;
|
this.prev_indent = this.root.indent;
|
||||||
EVT? prevEvent = null;
|
int indent = this.root.indent +4;
|
||||||
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"];
|
||||||
|
@ -197,9 +208,10 @@ public class Pluie.Yaml.Processor
|
||||||
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, 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