initial commit

This commit is contained in:
a-Sansara 2018-08-27 11:20:36 +02:00
commit 34dc6053c2
11 changed files with 518 additions and 0 deletions

0
README.md Normal file
View File

13
build.sh Executable file
View File

@ -0,0 +1,13 @@
valac -v \
--pkg gee-0.8 \
--pkg gio-2.0 \
--pkg pluie-echo-0.2 \
--pkg pluie-yaml-0.5 \
src/Pluie/Berel.Meta.vala \
src/Pluie/Berel.HeaderDef.vala \
src/Pluie/Berel.Sepline.vala \
src/Pluie/Berel.Comment.vala \
src/Pluie/Berel.Extension.vala \
src/Pluie/Berel.Key.vala \
src/Pluie/Berel.Keys.vala \
main.vala -o main

36
main.vala Normal file
View File

@ -0,0 +1,36 @@
using GLib;
using Gee;
using Pluie;
int main (string[] args)
{
Echo.init(false);
var path = "./resources/berel.yml";
of.echo (path);
var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
Pluie.Yaml.DEBUG = true;
var config = new Yaml.Config (path, true);
var root = config.root_node ();
if ((done = root != null)) {
root.display_childs ();
var berel = (Berel.Meta) Yaml.Builder.from_node (root.first ());
of.echo("software : %s %s".printf (berel.keys.software.name, berel.keys.software.address));
of.echo("version : %s".printf (berel.keys.version));
of.echo("type : %s".printf (berel.keys.ltype));
of.echo("date : %s".printf (berel.keys.date));
of.echo("license : %s %s".printf (berel.keys.license.name, berel.keys.license.address));
of.echo("author : %s %s".printf (berel.keys.author.name, berel.keys.author.address));
of.echo("copyright : %s %s".printf (berel.keys.copyright.name, berel.keys.copyright.address));
print (berel.tpl);
of.echo ();
print(berel.get_template ("vala"));
}
of.rs (done);
of.echo ();
return (int) done;
}

87
resources/berel.yml Normal file
View File

@ -0,0 +1,87 @@
%YAML 1.2
%TAG !v! tag:pluie.org,2018:vala/
---
!v!Pluie.Berel.Meta meta :
!v!Pluie.Berel.Keys keys :
software :
name : pluie-yaml
address : <https://git.pluie.org/pluie/lib-yaml>
version : 0.53
ltype : library
date : 2018
license :
name : GPLv3.0
address : <http://www.gnu.org/licenses/>
author :
name : a-Sansara
address : <[dev]at[pluie]dot[org]>
copyright :
name : pluie.org
address : <http://www.pluie.org>
!v!Gee.ArrayList headers :
- !v!Pluie.Berel.HeaderDef sh :
file :
- build.sh
startline : 2
!v!Pluie.Berel.Sepline sepline :
motif : "# "
repeat : 40
extension :
- .sh
!v!Pluie.Berel.Comment comment :
start : "#^#"
end : "#^#"
begin : "# "
- !v!Pluie.Berel.HeaderDef meson :
file :
- meson.sh
startline : 1
!v!Pluie.Berel.Sepline sepline :
motif : "# "
repeat : 40
extension :
- .build
!v!Pluie.Berel.Comment comment :
start : "#^#"
end : "#^#"
begin : "# "
- !v!Pluie.Berel.HeaderDef vala :
dir :
- src
- samples
file :
- install.vala.in
extension :
- .vala
- .c
startline : 1
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^

View File

@ -0,0 +1,44 @@
using GLib;
using Pluie;
/**
*
*/
public class Pluie.Berel.Comment : Yaml.Object
{
/**
*
*/
public string start { get; set; }
/**
*
*/
public string end { get; set; }
/**
*
*/
public string begin { get; set; }
/**
*
*/
public bool match_start (string data)
{
return data.index_of (this.start) == 0;
}
/**
*
*/
public bool match_end (string data)
{
return data.last_index_of (this.end) == data.length - begin.length;
}
/**
*
*/
public string get_line (string data)
{
return "%s%s".printf (this.begin, data);
}
}

View File

@ -0,0 +1,7 @@
using GLib;
using Pluie;
public class Pluie.Berel.Extension : Yaml.Object
{
public Gee.ArrayList<string> list { get; set; }
}

View File

@ -0,0 +1,58 @@
using GLib;
using Pluie;
public class Pluie.Berel.HeaderDef : Yaml.Object
{
public Gee.ArrayList<string> file { get; set; }
public Gee.ArrayList<string> dir { get; set; }
public int startline { get; set; }
public Berel.Sepline sepline { get; set; }
public Gee.ArrayList<string> extension { get; set; }
public Berel.Comment comment { get; set; }
/**
*
*/
static construct
{
Yaml.Register.add_type (
typeof (Berel.HeaderDef),
typeof (Gee.ArrayList)
);
}
/**
*
*/
protected override void yaml_construct ()
{
this.file = new Gee.ArrayList<string> ();
this.extension = new Gee.ArrayList<string> ();
this.dir = new Gee.ArrayList<string> ();
}
/**
*
*/
public override void populate_from_node (string name, GLib.Type type, Yaml.Node node) {
if (type == typeof (Gee.ArrayList)) {
foreach (var child in node) {
switch (name) {
case "extension":
this.extension.add(child.data);
break;
case "file":
this.file.add(child.data);
break;
case "dir":
this.dir.add(child.data);
break;
}
}
}
else {
var obj = Yaml.Builder.from_node(node, type);
this.set (node.name, obj);
}
}
}

8
src/Pluie/Berel.Key.vala Normal file
View File

@ -0,0 +1,8 @@
using GLib;
using Pluie;
public class Pluie.Berel.Key : Yaml.Object
{
public string name { get; internal set; }
public string address { get; internal set; }
}

84
src/Pluie/Berel.Keys.vala Normal file
View File

@ -0,0 +1,84 @@
using GLib;
using Pluie;
/**
*
*/
public class Pluie.Berel.Keys : Yaml.Object
{
/**
*
*/
public Berel.Key software { get; internal set; }
/**
*
*/
public string version { get; internal set; }
/**
*
*/
public string ltype { get; internal set; }
/**
*
*/
public string date { get; internal set; }
/**
*
*/
public Berel.Key license { get; internal set; }
/**
*
*/
public Berel.Key author { get; internal set; }
/**
*
*/
public Berel.Key copyright { get; internal set; }
/**
*
*/
public string get_all (HeaderDef hd)
{
var properties = this.get_class ().list_properties;
Berel.Key? ck = null;
string? cs = null;
foreach (var p in properties) {
if (p.value_type.is_a(typeof (Berel.Key))) {
}
}
foreach
var str = """@software : %15s %s
@version : %s %s
@type : %s
@date : %s
".printf (
""";
}
/**
*
*/
public string replace_var (string varname)
{
string val = "";
var list = varname.split(".", 2);
if (list.length == 1) {
if (this.get_class ().find_property (varname) != null) {
this.get(varname, out val);
}
}
else {
Berel.Key? k = null;
this.get(list[0], out k);
if (k != null) {
if (k.get_class ().find_property (list[1]) != null) {
k.get(list[1], out val);
}
}
}
return val;
}
}

147
src/Pluie/Berel.Meta.vala Normal file
View File

@ -0,0 +1,147 @@
using GLib;
using Pluie;
/**
*
*/
public class Pluie.Berel.Meta : Yaml.Object
{
/**
*
*/
public Berel.Keys keys { get; internal set; }
/**
*
*/
public Gee.ArrayList<Berel.HeaderDef> headers { get; internal set; }
/**
*
*/
public string tpl { get; internal set; }
/**
*
*/
private Gee.HashMap<string, string> varlist { get; internal set; }
/**
*
*/
static construct
{
Yaml.Register.add_type (
typeof (Berel.Meta),
typeof (Gee.ArrayList)
);
}
/**
*
*/
protected override void yaml_construct ()
{
this.headers = new Gee.ArrayList<Berel.HeaderDef> ();
this.varlist = new Gee.HashMap<string, string> ();
Yaml.Register.add_namespace("Gee", "Pluie.Berel");
Dbg.msg ("%s (%s) instantiated".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 (Gee.ArrayList)) {
foreach (var child in node) {
switch (name) {
case "headers":
this.headers.add((Berel.HeaderDef) Yaml.Builder.from_node (child, typeof (Berel.HeaderDef)));
break;
}
}
}
else {
var obj = Yaml.Builder.from_node(node, type);
if (name == "keys") {
this.set (node.name, (Berel.Keys ) obj);
}
else {
this.set (node.name, obj);
}
}
}
/**
*
*/
public string get_template (string type)
{
var headerdef = this.get_header_by_type (type);
var count = 1;
this.tpl_replace_var (headerdef);
StringBuilder sb = new StringBuilder ("");
foreach (string line in this.tpl.split ("\\n")) {
if (count == 1) {
//~ sb.append (this.comment.start
}
count++;
}
return "";
}
/**
*
*/
public void tpl_replace_var (HeaderDef hd)
{
MatchInfo? mi = null;
Regex reg = new Regex ("\\^([^\\^]+)\\^");
if (reg.match (this.tpl, 0, out mi)) {
this.replacing (mi.fetch (1), hd);
while (mi.next ()) {;
this.replacing (mi.fetch (1), hd);
}
}
foreach (var entry in this.varlist.entries) {
if (entry.value.length > 0) {
this.tpl = this.tpl.replace("^%s^".printf (entry.key), entry.value);
}
}
var s = this.tpl.split("\\n");
foreach (unowned string str in s) {
print ("%s\n", hd.comment.get_line(str));
}
}
/**
*
*/
private void replacing (string key, HeaderDef hd)
{
if (!this.varlist.has_key (key)) {
switch (key) {
case "sepline" :
this.varlist.set (key, hd.sepline.to_string ());
break;
case "keys" :
this.varlist.set (key, this.keys.get_all (hd));
break;
default :
this.varlist.set (key, this.keys.replace_var(key));
break;
}
}
}
/**
*
*/
public Berel.HeaderDef? get_header_by_type (string type)
{
Berel.HeaderDef? hd = null;
foreach (var def in this.headers) {
if (def.yaml_name == type) {
hd = def;
break;
}
}
return hd;
}
}

View File

@ -0,0 +1,34 @@
using GLib;
using Pluie;
/**
*
*/
public class Pluie.Berel.Sepline : Yaml.Object
{
/**
*
*/
public string motif { get; set; }
/**
*
*/
public int repeat { get; set; }
/**
*
*/
string? data { internal get; internal set; }
/**
*
*/
public string to_string ()
{
if (this.data == null) {
StringBuilder sb = new StringBuilder("");
for (var i = 0; i < this.repeat; i++) sb.append (this.motif);
data = sb.str;
}
return this.data;
}
}