vtm/quelldatein/helfer/xmlknoten/normal.ts

154 lines
3.9 KiB
TypeScript
Raw Normal View History

2018-03-26 00:41:10 +02:00
/*
* Verrückte Turing-Maschinen A turing complete game
* Copyright (C) 2016 Christian Fraß <vidofnir@folksprak.org>
*
* This program is free software: 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
2018-03-27 17:24:31 +02:00
module mod_vtm
2018-03-26 00:41:10 +02:00
{
2018-03-27 17:24:31 +02:00
export module mod_helfer
2018-03-26 00:41:10 +02:00
{
2018-03-27 17:24:31 +02:00
export module mod_xml
2018-03-26 00:41:10 +02:00
{
2018-03-27 17:24:31 +02:00
export module mod_normal
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
function einrueckung(tiefe : int, zeichen : string = "\t") : string
{
return ((tiefe === 0) ? "" : (zeichen + einrueckung(tiefe-1)));
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export type typ_normal =
{
name : string;
attribute : {[schluessel : string] : string};
kinder : Array<typ_knoten>;
}
;
/**
* @author kcf <vidofnir@folksprak.org>
*/
function erstellen
(
name : string,
attribute : {[schluessel : string] : string} = {},
kinder : Array<typ_knoten> = []
)
: typ_normal
{
return {
"name": name,
"attribute": attribute,
"kinder": kinder
};
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function erstellen_erweitert
(
name : string,
attribute : {[schluessel : string] : string} = {},
kinder : Array<typ_knoten> = []
)
: typ_knoten
{
return einpacken("normal", erstellen(name, attribute, kinder));
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
function darstellen
(
normal : typ_normal,
tiefe : int
)
: string
2018-03-26 00:41:10 +02:00
{
2018-03-27 17:24:31 +02:00
let str : string = "";
// anfang
{
let str_anfang : string = "";
str_anfang += normal.name;
// attribute
{
let str_attribute : string = "";
Object.keys(normal.attribute).forEach
(
schluessel =>
{
let wert : string = normal.attribute[schluessel];
str_attribute += (" " + schluessel + "=" + ("\"" + wert + "\""));
}
)
;
str_anfang += str_attribute;
}
str_anfang = (einrueckung(tiefe) + "<" + str_anfang + ">" + "\n");
str += str_anfang;
}
// kinder
{
normal.kinder.forEach(kind => (str += mod_xml.darstellen(kind, tiefe+1)));
}
// ende
{
let str_ende : string = "";
str_ende += normal.name;
str_ende = (einrueckung(tiefe) + "<" + "/" + str_ende + ">" + "\n");
str += str_ende;
}
return str;
2018-03-26 00:41:10 +02:00
}
2018-03-27 17:24:31 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
lib_brauch.umsetzen<signatur_knoten>
(
brauch_knoten,
"normal",
{
"darstellen": (knoten, tiefe) => darstellen(knoten.angaben, tiefe),
}
)
;
}
2018-03-26 00:41:10 +02:00
}
2018-03-27 17:24:31 +02:00
2018-03-26 00:41:10 +02:00
}
}