[ANNOUNCEMENT] WONTON - JSON-ish Object Serialization
WONTON
Wenyan's Own Number, Text & Object Notation
Inspired by #539 (thanks!), An object serialization method made its way to wenyan-lang STDLIB 🚀
The parser/serializer is written in pure wenyan and can be found in lib/渾沌經.wy - Yet another small step towards bootstrapping :)
Syntax
李白.wonton:
物
之「名」言「李白」
之「字」言「太白」
之「號」言「青蓮」
之「壽考」數「六一」
之「生年」言「長安元年」
之「卒年」言「上元三年」
之「存詩」數「九〇〇」
之「擅詩」爻「陽」
之「官」物
之「銜」言「翰林」。
之「年」言「天寶元年」。
也
之「名句」列
物
之「題」言「清平調」
之「文」言「雲想衣裳花相容。春風拂檻露華濃。」
也
物
之「題」言「長相思」
之「文」言「長相思。在長安。絡緯秋啼金井闌。微霜淒淒簟色寒。」
也
物
之「題」言「襄陽歌」
之「文」言「落日欲沒峴山西。倒著接蘺花下迷。襄陽小兒齊拍手。攔街爭唱「白銅鞮」。」
也
物
之「題」言「楊叛兒」
之「文」言「烏啼隱楊花。君醉留妾家。博山爐中沉香火。雙煙一氣凌紫霞。」
也
也
之「子女」列
言「伯禽」言「平陽」言「頗黎」
也
也
And to parse, (assuming you have loaded the .wonton file with appropriate fs hacks ;)
吾嘗觀「「渾沌經」」之書。方悟「包渾沌」「食渾沌」之義。
施「食渾沌」於「李翰林」。名之曰「太白餛飩」。
To serialize, use:
施「包渾沌」於「太白餛飩」。書之。
You can use JSON.stringify to check correctness of result:
{
"名": "李白",
"字": "太白",
"號": "青蓮",
"壽考": 61,
"生年": "長安元年",
"卒年": "上元三年",
"存詩": 900,
"擅詩": true,
"官": {
"銜": "翰林",
"年": "天寶元年"
},
"名句": [{
"題": "清平調",
"文": "雲想衣裳花相容。春風拂檻露華濃。"
}, {
"題": "長相思",
"文": "長相思。在長安。絡緯秋啼金井闌。微霜淒淒簟色寒。"
}, {
"題": "襄陽歌",
"文": "落日欲沒峴山西。倒著接蘺花下迷。襄陽小兒齊拍手。攔街爭唱「白銅鞮」。"
}, {
"題": "楊叛兒",
"文": "烏啼隱楊花。君醉留妾家。博山爐中沉香火。雙煙一氣凌紫霞。"
}],
"子女": ["伯禽", "平陽", "頗黎"]
}
This also means that for printing 物, we will no longer need JSON.stringify hack, being able to replace them with 「包渾沌」
You can check out more usage in examples/serialization.wy.
- All types of data are surrounded by single quotes
「」for simplicity. - Unlike wenyan-lang, where literary merits of the code are more heavily valued, wonton's design philosophy is to be concise.
- Limitation: only positional number notation is supported, i.e. 九〇 instead of 九十九... Until we rewrite the sophisticated algorithms in hanzi2num in wenyan
Haven't tested heavily, just excited to show off the new feature. So please Let me know if you spot any bugs or have any suggestion/ideas!
包渾沌、食渾沌…… 新年快乐这是,好应景
然后我仍是觉得用双引号会与 wenyan-lang 更一致,毕竟单引号用于标识符分词。 『』也是一个字符