dict-to-dict-yaml/json可序列化模板语言
girolamo的Python项目详细描述
#girolamo
json/yaml可序列化的dict到dict转换模板。
``` python
来自girolamo导入模板
]]},
>
dictin={
'a':'hello',
'b':'world'
>ctemplate=template.compile(hello世界)compile(hello世界)compile(hello世界)dictout=ctemplate.eval(data=dictin)打印dictout
>
````````
>>
>>>
>打印dictout
`````````````````````是的}
``
\yaml/json中的模板
*girolamo*模板可以直接用yaml表示:
```yaml
a:girolamo fecit
hw:
$list join:
-'
-[$$a,$$b,'!']
```
``json
{
"a":"girolamo fecit",
"hw":{
"$list join":[
",
["$$a","$$b","!"]
]
}
}
````
模板中每个键的值都是表达式。模板中的每个键都将成为输出字典中的键,其值为关联表达式的求值结果。
*|
{key1:*exp1*,key2:*exp2*,…}字典{key1:*eval(exp1)*,key2:*eval(exp2)*,…}
[*exp1*,*exp2*,…]|列表[*eval(exp1)*,*eval(exp2)*,…]|
$$*键*输入字典中*键*的值
$*符号*当前环境中*符号*的值
{$*函数*:[*exp1*,*exp2*,…]}使用[*eval(exp1)*,*eval(exp2)*,…调用*函数*的结果…]|
{$*函数*:*exp1*}用[*eval(exp1)*]*调用*函数*的结果
格式为:
``python
{
"$if":[
pred,
conseq,
alt
]
}
```
,其中,*pred*,*conseq*和*alt*是表达式。如果*pred*为真,则对*conseq*求值并返回结果,否则对*conseq*求值并返回结果。
示例:
``yaml
-false
-true
```
格式为:
``python
{
"$match":[
var,
[pred1,exp1],[pred2,exp2],…],
default
]
}
```
当谓词表达式为true时,将计算关联的表达式并返回结果。如果谓词表达式都不是真的,则计算*default*并返回结果。
示例:
``yaml
/>$match:
-$$type
-[["ipv4",4],"ipv6",6]]
-null
`````
```assignments
格式为:
`` python
{
"$define":[
符号,
值
]
}
```
在当前环境中计算表达式*值*并将结果分配给*符号*。define*的返回值是*n一个*.
lambdas
特殊函数*lambda*可用于定义匿名函数。格式为:
`` python
{
"$lambda":[
[formal1,formal2,…。]
body
>如果需要一个形式的话,所需要的也可以是:
`` python
{
"$lambda":[
forml1,
body
` ` `
` ` ` `
` ` ` ` ` `
` ` ` ` ` ` ` ` ` ` ` ` `
``python
{
"$function":[exp1,expp2,"$\"]
` ` ` `
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` python
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `模板中的全局键($keys)
*$*作为全局符号的定义处理,可用于评估所有模板键。
示例:
``python
{
edfuture实体url",
"验证点智能最大得分",
"验证点智能分类",
"bambenkconsulting描述",
"bambenkconsulting信息"
]
}
"```
json/yaml可序列化的dict到dict转换模板。
``` python
来自girolamo导入模板
]]},
>
dictin={
'a':'hello',
'b':'world'
>ctemplate=template.compile(hello世界)compile(hello世界)compile(hello世界)dictout=ctemplate.eval(data=dictin)打印dictout
>
````````
>>
>>>
>打印dictout
`````````````````````是的}
``
\yaml/json中的模板
*girolamo*模板可以直接用yaml表示:
```yaml
a:girolamo fecit
hw:
$list join:
-'
-[$$a,$$b,'!']
```
``json
{
"a":"girolamo fecit",
"hw":{
"$list join":[
",
["$$a","$$b","!"]
]
}
}
````
模板中每个键的值都是表达式。模板中的每个键都将成为输出字典中的键,其值为关联表达式的求值结果。
*|
{key1:*exp1*,key2:*exp2*,…}字典{key1:*eval(exp1)*,key2:*eval(exp2)*,…}
[*exp1*,*exp2*,…]|列表[*eval(exp1)*,*eval(exp2)*,…]|
$$*键*输入字典中*键*的值
$*符号*当前环境中*符号*的值
{$*函数*:[*exp1*,*exp2*,…]}使用[*eval(exp1)*,*eval(exp2)*,…调用*函数*的结果…]|
{$*函数*:*exp1*}用[*eval(exp1)*]*调用*函数*的结果
格式为:
``python
{
"$if":[
pred,
conseq,
alt
]
}
```
,其中,*pred*,*conseq*和*alt*是表达式。如果*pred*为真,则对*conseq*求值并返回结果,否则对*conseq*求值并返回结果。
示例:
``yaml
-false
-true
```
格式为:
``python
{
"$match":[
var,
[pred1,exp1],[pred2,exp2],…],
default
]
}
```
当谓词表达式为true时,将计算关联的表达式并返回结果。如果谓词表达式都不是真的,则计算*default*并返回结果。
示例:
``yaml
/>$match:
-$$type
-[["ipv4",4],"ipv6",6]]
-null
`````
```assignments
格式为:
`` python
{
"$define":[
符号,
值
]
}
```
在当前环境中计算表达式*值*并将结果分配给*符号*。define*的返回值是*n一个*.
lambdas
特殊函数*lambda*可用于定义匿名函数。格式为:
`` python
{
"$lambda":[
[formal1,formal2,…。]
body
>如果需要一个形式的话,所需要的也可以是:
`` python
{
"$lambda":[
forml1,
body
` ` `
` ` ` `
` ` ` ` ` `
` ` ` ` ` ` ` ` ` ` ` ` `
``python
{
"$function":[exp1,expp2,"$\"]
` ` ` `
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` python
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `模板中的全局键($keys)
*$*作为全局符号的定义处理,可用于评估所有模板键。
示例:
``python
{
edfuture实体url",
"验证点智能最大得分",
"验证点智能分类",
"bambenkconsulting描述",
"bambenkconsulting信息"
]
}
"```