Toml语法
TOML 简介
TOML 是一种最小的配置文件格式,由于明显的语义而易于阅读
官方文档:https://toml.io/en/
格式
bool = true
date = 2006-05-27T07:32:00Z
string = "hello"
number = 42
float = 3.14
scientificNotation = 1e+12
基本类型
- 注释
- 整数
- 浮点数
- 布尔值
- 时间日期
date1 = 1989-05-27T07:32:00Z
date2 = 1989-05-26T15:32:00-07:00
date3 = 1989-05-27T07:32:00
date4 = 1989-05-27
time1 = 07:32:00
time2 = 00:32:00.999999
字符串
- 文字字符串
用单引号括起来,不允许转义
path = 'C:\Users\nodejs\templates'
path2 = '\\User\admin$\system32'
quoted = 'Tom "Dubs" Preston-Werner'
regex = '<\i\c*\s*>'
- 多行字符串
multiLineString = """
Multi-line basic strings are surrounded
by three quotation marks on each side
and allow newlines.
"""
- 多行文字字符串
re = '''\d{2} apps is t[wo]o many'''
lines = '''
The first newline is
trimmed in raw strings.
All other whitespace
is preserved.
'''
数组
友好数组
array1 = [ "Don't mix", "different", "types" ]
array2 = [ [ 1.2, 2.4 ], ["all", 'strings', """are the same""", '''type'''] ]
array3 = [
"Whitespace", "is",
"ignored"
]
Tables
- 基本的 Table
foo
和 bar
是名为 name
的表中的键
- 点分隔
等效的 json 为
- Table 嵌套
- 多嵌套
等效的 json 为
- 忽略空格
[a.b.c] # this is best practice
[ d.e.f ] # same as [d.e.f]
[ g . h .i ] # same as [g.h.i]
[ j . "ʞ" .'l' ] # same as [j."ʞ".'l']
- 类数组
[[comments]]
author = "Nate"
text = "Great Article!"
[[comments]]
author = "Anonymous"
text = "Love it!"
等效的 json 为
{
"comments": [
{
"author": "Nate",
"text": "Great Article!"
},
{
"author": "Anonymous",
"text": "Love It!"
}
]
}
- 内联表