| 1 |
################################################################################ |
| 2 |
## Comment |
| 3 |
|
| 4 |
# Speak your mind with the hash symbol. They go from the symbol to the end of |
| 5 |
# the line. |
| 6 |
|
| 7 |
|
| 8 |
################################################################################ |
| 9 |
## Table |
| 10 |
|
| 11 |
# Tables (also known as hash tables or dictionaries) are collections of |
| 12 |
# key/value pairs. They appear in square brackets on a line by themselves. |
| 13 |
|
| 14 |
[table] |
| 15 |
|
| 16 |
key = "value" # Yeah, you can do this. |
| 17 |
|
| 18 |
# Nested tables are denoted by table names with dots in them. Name your tables |
| 19 |
# whatever crap you please, just don't use #, ., [ or ]. |
| 20 |
|
| 21 |
[table.subtable] |
| 22 |
|
| 23 |
key = "another value" |
| 24 |
|
| 25 |
# You don't need to specify all the super-tables if you don't want to. TOML |
| 26 |
# knows how to do it for you. |
| 27 |
|
| 28 |
# [x] you |
| 29 |
# [x.y] don't |
| 30 |
# [x.y.z] need these |
| 31 |
[x.y.z.w] # for this to work |
| 32 |
|
| 33 |
|
| 34 |
################################################################################ |
| 35 |
## Inline Table |
| 36 |
|
| 37 |
# Inline tables provide a more compact syntax for expressing tables. They are |
| 38 |
# especially useful for grouped data that can otherwise quickly become verbose. |
| 39 |
# Inline tables are enclosed in curly braces `{` and `}`. No newlines are |
| 40 |
# allowed between the curly braces unless they are valid within a value. |
| 41 |
|
| 42 |
[table.inline] |
| 43 |
|
| 44 |
name = { first = "Tom", last = "Preston-Werner" } |
| 45 |
point = { x = 1, y = 2 } |
| 46 |
|
| 47 |
|
| 48 |
################################################################################ |
| 49 |
## String |
| 50 |
|
| 51 |
# There are four ways to express strings: basic, multi-line basic, literal, and |
| 52 |
# multi-line literal. All strings must contain only valid UTF-8 characters. |
| 53 |
|
| 54 |
[string.basic] |
| 55 |
|
| 56 |
basic = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF." |
| 57 |
|
| 58 |
[string.multiline] |
| 59 |
|
| 60 |
# The following strings are byte-for-byte equivalent: |
| 61 |
key1 = "One\nTwo" |
| 62 |
key2 = """One\nTwo""" |
| 63 |
key3 = """ |
| 64 |
One |
| 65 |
Two""" |
| 66 |
|
| 67 |
[string.multiline.continued] |
| 68 |
|
| 69 |
# The following strings are byte-for-byte equivalent: |
| 70 |
key1 = "The quick brown fox jumps over the lazy dog." |
| 71 |
|
| 72 |
key2 = """ |
| 73 |
The quick brown \ |
| 74 |
|
| 75 |
|
| 76 |
fox jumps over \ |
| 77 |
the lazy dog.""" |
| 78 |
|
| 79 |
key3 = """\ |
| 80 |
The quick brown \ |
| 81 |
fox jumps over \ |
| 82 |
the lazy dog.\ |
| 83 |
""" |
| 84 |
|
| 85 |
[string.literal] |
| 86 |
|
| 87 |
# What you see is what you get. |
| 88 |
winpath = 'C:\Users\nodejs\templates' |
| 89 |
winpath2 = '\\ServerX\admin$\system32\' |
| 90 |
quoted = 'Tom "Dubs" Preston-Werner' |
| 91 |
regex = '<\i\c*\s*>' |
| 92 |
|
| 93 |
|
| 94 |
[string.literal.multiline] |
| 95 |
|
| 96 |
regex2 = '''I [dw]on't need \d{2} apples''' |
| 97 |
lines = ''' |
| 98 |
The first newline is |
| 99 |
trimmed in raw strings. |
| 100 |
All other whitespace |
| 101 |
is preserved. |
| 102 |
''' |
| 103 |
|
| 104 |
|
| 105 |
################################################################################ |
| 106 |
## Integer |
| 107 |
|
| 108 |
# Integers are whole numbers. Positive numbers may be prefixed with a plus sign. |
| 109 |
# Negative numbers are prefixed with a minus sign. |
| 110 |
|
| 111 |
[integer] |
| 112 |
|
| 113 |
key1 = +99 |
| 114 |
key2 = 42 |
| 115 |
key3 = 0 |
| 116 |
key4 = -17 |
| 117 |
|
| 118 |
[integer.underscores] |
| 119 |
|
| 120 |
# For large numbers, you may use underscores to enhance readability. Each |
| 121 |
# underscore must be surrounded by at least one digit. |
| 122 |
key1 = 1_000 |
| 123 |
key2 = 5_349_221 |
| 124 |
key3 = 1_2_3_4_5 # valid but inadvisable |
| 125 |
|
| 126 |
|
| 127 |
################################################################################ |
| 128 |
## Float |
| 129 |
|
| 130 |
# A float consists of an integer part (which may be prefixed with a plus or |
| 131 |
# minus sign) followed by a fractional part and/or an exponent part. |
| 132 |
|
| 133 |
[float.fractional] |
| 134 |
|
| 135 |
key1 = +1.0 |
| 136 |
key2 = 3.1415 |
| 137 |
key3 = -0.01 |
| 138 |
|
| 139 |
[float.exponent] |
| 140 |
|
| 141 |
[float.both] |
| 142 |
|
| 143 |
[float.underscores] |
| 144 |
|
| 145 |
|
| 146 |
################################################################################ |
| 147 |
## Boolean |
| 148 |
|
| 149 |
# Booleans are just the tokens you're used to. Always lowercase. |
| 150 |
|
| 151 |
[boolean] |
| 152 |
|
| 153 |
True = true |
| 154 |
False = false |
| 155 |
|
| 156 |
|
| 157 |
################################################################################ |
| 158 |
## Datetime |
| 159 |
|
| 160 |
# Datetimes are RFC 3339 dates. |
| 161 |
|
| 162 |
[datetime] |
| 163 |
|
| 164 |
#key1 = 1979-05-27T07:32:00Z |
| 165 |
#key2 = 1979-05-27T00:32:00-07:00 |
| 166 |
#key3 = 1979-05-27T00:32:00.999999-07:00 |
| 167 |
|
| 168 |
|
| 169 |
################################################################################ |
| 170 |
## Array |
| 171 |
|
| 172 |
# Arrays are square brackets with other primitives inside. Whitespace is |
| 173 |
# ignored. Elements are separated by commas. Since 2019-11-06 data types can be |
| 174 |
# mixed. |
| 175 |
|
| 176 |
[array] |
| 177 |
|
| 178 |
key1 = [ 1, 2, 3 ] |
| 179 |
key2 = [ "red", "yellow", "green" ] |
| 180 |
key3 = [ [ 1, 2 ], [3, 4, 5] ] |
| 181 |
key4 = [ [ 1, 2 ], ["a", "b", "c"] ] # this is ok |
| 182 |
|
| 183 |
# Arrays can also be multiline. So in addition to ignoring whitespace, arrays |
| 184 |
# also ignore newlines between the brackets. Terminating commas are ok before |
| 185 |
# the closing bracket. |
| 186 |
|
| 187 |
key5 = [ |
| 188 |
1, 2, 3 |
| 189 |
] |
| 190 |
key6 = [ |
| 191 |
1, |
| 192 |
2, # this is ok |
| 193 |
] |
| 194 |
|
| 195 |
|
| 196 |
################################################################################ |
| 197 |
## Array of Tables |
| 198 |
|
| 199 |
# These can be expressed by using a table name in double brackets. Each table |
| 200 |
# with the same double bracketed name will be an element in the array. The |
| 201 |
# tables are inserted in the order encountered. |
| 202 |
|
| 203 |
[[products]] |
| 204 |
|
| 205 |
name = "Hammer" |
| 206 |
sku = 738594937 |
| 207 |
|
| 208 |
[[products]] |
| 209 |
|
| 210 |
[[products]] |
| 211 |
|
| 212 |
name = "Nail" |
| 213 |
sku = 284758393 |
| 214 |
color = "gray" |
| 215 |
|
| 216 |
|
| 217 |
# You can create nested arrays of tables as well. |
| 218 |
|
| 219 |
[[fruit]] |
| 220 |
name = "apple" |
| 221 |
|
| 222 |
[fruit.physical] |
| 223 |
color = "red" |
| 224 |
shape = "round" |
| 225 |
|
| 226 |
[[fruit.variety]] |
| 227 |
name = "red delicious" |
| 228 |
|
| 229 |
[[fruit.variety]] |
| 230 |
name = "granny smith" |
| 231 |
|
| 232 |
[[fruit]] |
| 233 |
name = "banana" |
| 234 |
|
| 235 |
[[fruit.variety]] |
| 236 |
name = "plantain" |