tree-sitter-toml/corpus/spec.txt

1506 lines
32 KiB
Plaintext
Raw Permalink Normal View History

2019-08-18 06:30:34 -04:00
================================================================================
VALID - comment - basic
================================================================================
# This is a full-line comment
key = "value" # This is a comment at the end of a line
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(comment)
(pair
(bare_key)
(string)
(comment)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - key/value pair - basic
================================================================================
key = "value"
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(string)))
2019-08-18 06:30:34 -04:00
================================================================================
INVALID - key/value pair - empty value
2019-08-18 06:30:34 -04:00
================================================================================
key = # INVALID
--------------------------------------------------------------------------------
(document
(ERROR
(bare_key)
(comment)))
2019-08-18 06:30:34 -04:00
================================================================================
INVALID - key/value pair - no newline between pairs
================================================================================
first = "Tom" last = "Preston-Werner" # INVALID
--------------------------------------------------------------------------------
(document
(pair
(bare_key)
(string)
(MISSING _line_ending_or_eof))
(pair
(bare_key)
(string)
(comment)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - keys - bare keys
================================================================================
key = "value"
bare_key = "value"
bare-key = "value"
1234 = "value"
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(string))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(string))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(string))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(string)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - keys - quoted keys
================================================================================
"127.0.0.1" = "value"
"character encoding" = "value"
"ʎǝʞ" = "value"
'key2' = "value"
'quoted "value"' = "value"
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(pair
(quoted_key)
(string))
2019-08-18 06:30:34 -04:00
(pair
(quoted_key)
(string))
2019-08-18 06:30:34 -04:00
(pair
(quoted_key)
(string))
2019-08-18 06:30:34 -04:00
(pair
(quoted_key)
(string))
2019-08-18 06:30:34 -04:00
(pair
(quoted_key)
(string)))
2019-08-18 06:30:34 -04:00
================================================================================
INVALID - keys - empty bare key
2019-08-18 06:30:34 -04:00
================================================================================
= "no key name" # INVALID
"" = "blank" # VALID but discouraged
'' = 'blank' # VALID but discouraged
--------------------------------------------------------------------------------
(document
(ERROR)
2019-08-18 06:30:34 -04:00
(pair
(quoted_key)
(comment)
(ERROR)
(string)
(comment))
2019-08-18 06:30:34 -04:00
(pair
(quoted_key)
(string)
(comment)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - keys - dotted keys
================================================================================
name = "Orange"
physical.color = "orange"
physical.shape = "round"
site."google.com" = true
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(string))
2019-08-18 06:30:34 -04:00
(pair
(dotted_key
(bare_key)
(bare_key))
2019-08-22 05:22:58 -04:00
(string))
2019-08-18 06:30:34 -04:00
(pair
(dotted_key
(bare_key)
(bare_key))
2019-08-22 05:22:58 -04:00
(string))
2019-08-18 06:30:34 -04:00
(pair
(dotted_key
(bare_key)
(quoted_key))
2019-08-22 05:22:58 -04:00
(boolean)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - keys - duplicate keys (semantically INVALID)
================================================================================
# DO NOT DO THIS
name = "Tom"
name = "Pradyun"
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(comment)
(pair
(bare_key)
(string))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(string)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - keys - directly defined nested keys
================================================================================
# This makes the key "fruit" into a table.
fruit.apple.smooth = true
# So then you can add to the table "fruit" like so:
fruit.orange = 2
2019-08-18 06:30:34 -04:00
--------------------------------------------------------------------------------
(document
(comment)
2019-08-18 06:30:34 -04:00
(pair
(dotted_key
(dotted_key
(bare_key)
(bare_key))
(bare_key))
(boolean))
(comment)
2019-08-18 06:30:34 -04:00
(pair
(dotted_key
(bare_key)
(bare_key))
2019-08-22 05:22:58 -04:00
(integer)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - keys - overlapped keys (semantically INVALID)
================================================================================
# THE FOLLOWING IS INVALID
# This defines the value of fruit.apple to be an integer.
fruit.apple = 1
# But then this treats fruit.apple like it's a table.
# You can't turn an integer into a table.
fruit.apple.smooth = true
2019-08-18 06:30:34 -04:00
--------------------------------------------------------------------------------
(document
(comment)
2019-08-18 06:30:34 -04:00
(comment)
(pair
(dotted_key
(bare_key)
(bare_key))
2019-08-22 05:22:58 -04:00
(integer))
(comment)
(comment)
2019-08-18 06:30:34 -04:00
(pair
(dotted_key
(dotted_key
(bare_key)
(bare_key))
(bare_key))
(boolean)))
================================================================================
VALID - keys - order
================================================================================
# VALID BUT DISCOURAGED
apple.type = "fruit"
orange.type = "fruit"
apple.skin = "thin"
orange.skin = "thick"
apple.color = "red"
orange.color = "orange"
# RECOMMENDED
apple.type = "fruit"
apple.skin = "thin"
apple.color = "red"
orange.type = "fruit"
orange.skin = "thick"
orange.color = "orange"
--------------------------------------------------------------------------------
(document
(comment)
(pair
(dotted_key
(bare_key)
(bare_key))
(string))
(pair
(dotted_key
(bare_key)
(bare_key))
(string))
(pair
(dotted_key
(bare_key)
(bare_key))
(string))
(pair
(dotted_key
(bare_key)
(bare_key))
(string))
(pair
(dotted_key
(bare_key)
(bare_key))
(string))
(pair
(dotted_key
(bare_key)
(bare_key))
(string))
(comment)
(pair
(dotted_key
(bare_key)
(bare_key))
(string))
(pair
(dotted_key
(bare_key)
(bare_key))
(string))
(pair
(dotted_key
(bare_key)
(bare_key))
(string))
(pair
(dotted_key
(bare_key)
(bare_key))
(string))
(pair
(dotted_key
(bare_key)
(bare_key))
(string))
(pair
(dotted_key
(bare_key)
(bare_key))
(string)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - string - basic strings
================================================================================
str = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF."
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
2019-08-18 06:30:34 -04:00
(string
(escape_sequence)
(escape_sequence)
(escape_sequence)
(escape_sequence)
(escape_sequence)
(escape_sequence))))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - string - multi-line basic strings
================================================================================
str1 = """
Roses are red
Violets are blue"""
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(string)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - string - multi-line basic strings with trailing backslashes
================================================================================
# The following strings are byte-for-byte equivalent:
str1 = "The quick brown fox jumps over the lazy dog."
str2 = """
The quick brown \
fox jumps over \
the lazy dog."""
str3 = """\
The quick brown \
fox jumps over \
the lazy dog.\
"""
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(comment)
(pair
(bare_key)
(string))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
2019-08-18 06:30:34 -04:00
(string
(escape_sequence)
(escape_sequence)))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
2019-08-18 06:30:34 -04:00
(string
(escape_sequence)
(escape_sequence)
(escape_sequence)
(escape_sequence))))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - string - multi-line basic strings with double quotes
================================================================================
str4 = """Here are two quotation marks: "". Simple enough."""
# str5 = """Here are three quotation marks: """.""" # INVALID
str5 = """Here are three quotation marks: ""\"."""
str6 = """Here are fifteen quotation marks: ""\"""\"""\"""\"""\"."""
# "This," she said, "is just a pointless statement."
str7 = """"This," she said, "is just a pointless statement.""""
--------------------------------------------------------------------------------
(document
(pair
(bare_key)
(string))
(comment)
(pair
(bare_key)
(string
(escape_sequence)))
(pair
(bare_key)
(string
(escape_sequence)
(escape_sequence)
(escape_sequence)
(escape_sequence)
(escape_sequence)))
(comment)
(pair
(bare_key)
(string)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - string - literal strings
================================================================================
# What you see is what you get.
winpath = 'C:\Users\nodejs\templates'
winpath2 = '\\ServerX\admin$\system32\'
quoted = 'Tom "Dubs" Preston-Werner'
regex = '<\i\c*\s*>'
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(comment)
(pair
(bare_key)
(string))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(string))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(string))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(string)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - string - multi-line literal strings
================================================================================
regex2 = '''I [dw]on't need \d{2} apples'''
lines = '''
The first newline is
trimmed in raw strings.
All other whitespace
is preserved.
'''
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(string))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(string)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - string - multi-line literal strings with single quotes
================================================================================
quot15 = '''Here are fifteen quotation marks: """""""""""""""'''
# apos15 = '''Here are fifteen apostrophes: '''''''''''''''''' # INVALID
apos15 = "Here are fifteen apostrophes: '''''''''''''''"
# 'That's still pointless', she said.
str = ''''That's still pointless', she said.'''
--------------------------------------------------------------------------------
(document
(pair
(bare_key)
(string))
(comment)
(pair
(bare_key)
(string))
(comment)
(pair
(bare_key)
(string)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - integer - signed/unsigned decimal integer
================================================================================
int1 = +99
int2 = 42
int3 = 0
int4 = -17
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(integer))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(integer))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(integer))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(integer)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - integer - decimal integer with underscores
================================================================================
int5 = 1_000
int6 = 5_349_221
int7 = 1_2_3_4_5 # VALID but discouraged
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(integer))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(integer))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(integer)
(comment)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - integer - hexadecimal/octal/binary integer
================================================================================
# hexadecimal with prefix `0x`
hex1 = 0xDEADBEEF
hex2 = 0xdeadbeef
hex3 = 0xdead_beef
# octal with prefix `0o`
oct1 = 0o01234567
oct2 = 0o755 # useful for Unix file permissions
# binary with prefix `0b`
bin1 = 0b11010110
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(comment)
(pair
(bare_key)
(integer))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(integer))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(integer))
2019-08-18 06:30:34 -04:00
(comment)
(pair
(bare_key)
(integer))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(integer)
(comment))
2019-08-18 06:30:34 -04:00
(comment)
(pair
(bare_key)
(integer)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - float - float with fractional or exponent or both
================================================================================
# fractional
flt1 = +1.0
flt2 = 3.1415
flt3 = -0.01
# exponent
flt4 = 5e+22
flt5 = 1e06
2019-08-18 06:30:34 -04:00
flt6 = -2E-2
# both
flt7 = 6.626e-34
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(comment)
(pair
(bare_key)
(float))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(float))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(float))
2019-08-18 06:30:34 -04:00
(comment)
(pair
(bare_key)
(float))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(float))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(float))
2019-08-18 06:30:34 -04:00
(comment)
(pair
(bare_key)
(float)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - float - float with underscores
================================================================================
flt8 = 224_617.445_991_228
2019-08-18 06:30:34 -04:00
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(float)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - float - special float values
================================================================================
# infinity
sf1 = inf # positive infinity
sf2 = +inf # positive infinity
sf3 = -inf # negative infinity
# not a number
sf4 = nan # actual sNaN/qNaN encoding is implementation specific
sf5 = +nan # same as `nan`
sf6 = -nan # valid, actual encoding is implementation specific
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(comment)
(pair
(bare_key)
(float)
(comment))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(float)
(comment))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(float)
(comment))
2019-08-18 06:30:34 -04:00
(comment)
(pair
(bare_key)
(float)
(comment))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(float)
(comment))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(float)
(comment)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - boolean - basic
================================================================================
bool1 = true
bool2 = false
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(boolean))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(boolean)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - offset date time - basic
================================================================================
odt1 = 1979-05-27T07:32:00Z
odt2 = 1979-05-27T00:32:00-07:00
odt3 = 1979-05-27T00:32:00.999999-07:00
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(offset_date_time))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(offset_date_time))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(offset_date_time)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - offset date time - whitespace as delimiter
================================================================================
odt4 = 1979-05-27 07:32:00Z
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(offset_date_time)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - local date time - basic
================================================================================
ldt1 = 1979-05-27T07:32:00
ldt2 = 1979-05-27T00:32:00.999999
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(local_date_time))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(local_date_time)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - local date - basic
================================================================================
ld1 = 1979-05-27
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(local_date)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - local time - basic
================================================================================
lt1 = 07:32:00
lt2 = 00:32:00.999999
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(local_time))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(local_time)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - array - basic
2019-08-18 06:30:34 -04:00
================================================================================
integers = [ 1, 2, 3 ]
colors = [ "red", "yellow", "green" ]
nested_array_of_int = [ [ 1, 2 ], [3, 4, 5] ]
nested_mixed_array = [ [ 1, 2 ], ["a", "b", "c"] ]
string_array = [ "all", 'strings', """are the same""", '''type''' ]
2019-08-18 06:30:34 -04:00
# Mixed-type arrays are allowed
numbers = [ 0.1, 0.2, 0.5, 1, 2, 5 ]
contributors = [
"Foo Bar <foo@example.com>",
{ name = "Baz Qux", email = "bazqux@example.com", url = "https://example.com/bazqux" }
]
2019-08-18 06:30:34 -04:00
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
2019-08-18 06:30:34 -04:00
(array
(integer)
(integer)
(integer)))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
2019-08-18 06:30:34 -04:00
(array
(string)
(string)
(string)))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
2019-08-18 06:30:34 -04:00
(array
(array
(integer)
(integer))
2019-08-18 06:30:34 -04:00
(array
(integer)
(integer)
(integer))))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
2019-08-18 06:30:34 -04:00
(array
(array
(integer)
(integer))
2019-08-18 06:30:34 -04:00
(array
(string)
(string)
(string))))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
2019-08-18 06:30:34 -04:00
(array
(string)
(string)
(string)
(string)))
(comment)
(pair
(bare_key)
(array
(float)
(float)
(float)
(integer)
(integer)
(integer)))
(pair
(bare_key)
(array
(string)
(inline_table
(pair
(bare_key)
(string))
(pair
(bare_key)
(string))
(pair
(bare_key)
(string))))))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - array - allow newlines
================================================================================
integers2 = [
2019-08-18 06:30:34 -04:00
1, 2, 3
]
integers3 = [
2019-08-18 06:30:34 -04:00
1,
2, # this is ok
]
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
2019-08-18 06:30:34 -04:00
(array
(integer)
(integer)
(integer)))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
2019-08-18 06:30:34 -04:00
(array
(integer)
(integer)
(comment))))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - table - header
================================================================================
[table]
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(table
(bare_key)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - table - basic
================================================================================
[table-1]
key1 = "some string"
key2 = 123
[table-2]
key1 = "another string"
key2 = 456
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(table
(bare_key)
(pair
(bare_key)
(string))
(pair
(bare_key)
(integer)))
2019-08-18 06:30:34 -04:00
(table
(bare_key)
(pair
(bare_key)
(string))
(pair
(bare_key)
(integer))))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - table - header with dotted key
================================================================================
[dog."tater.man"]
type.name = "pug"
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(table
(dotted_key
(bare_key)
(quoted_key))
(pair
(dotted_key
(bare_key)
(bare_key))
(string))))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - table- header with whitespaces
================================================================================
[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']
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(table
(dotted_key
(dotted_key
(bare_key)
(bare_key))
(bare_key))
2019-08-22 05:22:58 -04:00
(comment))
2019-08-18 06:30:34 -04:00
(table
(dotted_key
(dotted_key
(bare_key)
(bare_key))
(bare_key))
2019-08-22 05:22:58 -04:00
(comment))
2019-08-18 06:30:34 -04:00
(table
(dotted_key
(dotted_key
(bare_key)
(bare_key))
(bare_key))
2019-08-22 05:22:58 -04:00
(comment))
2019-08-18 06:30:34 -04:00
(table
(dotted_key
(dotted_key
(bare_key)
(quoted_key))
(quoted_key))
2019-08-22 05:22:58 -04:00
(comment)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - table - directly defined nested header key
================================================================================
# [x] you
# [x.y] don't
# [x.y.z] need these
[x.y.z.w] # for this to work
[x] # defining a super-table afterwards is ok
2019-08-18 06:30:34 -04:00
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(comment)
(comment)
(comment)
(table
(dotted_key
(dotted_key
(dotted_key
(bare_key)
(bare_key))
(bare_key))
(bare_key))
(comment))
(table
(bare_key)
2019-08-22 05:22:58 -04:00
(comment)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - table - duplicate header key (semantically INVALID)
================================================================================
# DO NOT DO THIS
[fruit]
apple = "red"
2019-08-18 06:30:34 -04:00
[fruit]
orange = "orange"
2019-08-18 06:30:34 -04:00
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(comment)
(table
(bare_key)
(pair
(bare_key)
(string)))
2019-08-18 06:30:34 -04:00
(table
(bare_key)
(pair
(bare_key)
(string))))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - table - overlapped header key (semantically INVALID)
================================================================================
# DO NOT DO THIS EITHER
[fruit]
apple = "red"
2019-08-18 06:30:34 -04:00
[fruit.apple]
texture = "smooth"
2019-08-18 06:30:34 -04:00
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(comment)
(table
(bare_key)
(pair
(bare_key)
(string)))
2019-08-18 06:30:34 -04:00
(table
(dotted_key
(bare_key)
(bare_key))
(pair
(bare_key)
(string))))
================================================================================
VALID - table - order
================================================================================
# VALID BUT DISCOURAGED
[fruit.apple]
[animal]
[fruit.orange]
# RECOMMENDED
[fruit.apple]
[fruit.orange]
[animal]
--------------------------------------------------------------------------------
(document
(comment)
(table
(dotted_key
(bare_key)
(bare_key)))
(table
(bare_key))
(table
(dotted_key
(bare_key)
(bare_key))
(comment))
(table
(dotted_key
(bare_key)
(bare_key)))
(table
(dotted_key
(bare_key)
(bare_key)))
(table
(bare_key)))
================================================================================
VALID - table - sub-table
================================================================================
[fruit]
apple.color = "red"
apple.taste.sweet = true
# [fruit.apple] # INVALID
# [fruit.apple.taste] # INVALID
[fruit.apple.texture] # you can add sub-tables
smooth = true
--------------------------------------------------------------------------------
(document
(table
(bare_key)
(pair
(dotted_key
(bare_key)
(bare_key))
(string))
(pair
(dotted_key
(dotted_key
(bare_key)
(bare_key))
(bare_key))
(boolean))
(comment)
(comment))
(table
(dotted_key
(dotted_key
(bare_key)
(bare_key))
(bare_key))
(comment)
(pair
(bare_key)
(boolean))))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - inline table - basic
================================================================================
name = { first = "Tom", last = "Preston-Werner" }
point = { x = 1, y = 2 }
animal = { type.name = "pug" }
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
2019-08-18 06:30:34 -04:00
(inline_table
(pair
(bare_key)
(string))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(string))))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
2019-08-18 06:30:34 -04:00
(inline_table
(pair
(bare_key)
(integer))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
(integer))))
2019-08-18 06:30:34 -04:00
(pair
(bare_key)
2019-08-18 06:30:34 -04:00
(inline_table
(pair
(dotted_key
(bare_key)
(bare_key))
2019-08-22 05:22:58 -04:00
(string)))))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - inline table - overlapped key (semantically INVALID)
================================================================================
[product]
type = { name = "Nail" }
# type.edible = false # INVALID
[product]
type.name = "Nail"
# type = { edible = false } # INVALID
--------------------------------------------------------------------------------
(document
(table
(bare_key)
(pair
(bare_key)
(inline_table
(pair
(bare_key)
(string))))
(comment))
(table
(bare_key)
(pair
(dotted_key
(bare_key)
(bare_key))
(string))
(comment)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - array of tables - basic
================================================================================
[[products]]
name = "Hammer"
sku = 738594937
[[products]]
[[products]]
name = "Nail"
sku = 284758393
2019-08-18 06:30:34 -04:00
color = "gray"
--------------------------------------------------------------------------------
(document
(table_array_element
(bare_key)
(pair
(bare_key)
(string))
(pair
(bare_key)
(integer)))
(table_array_element
(bare_key))
(table_array_element
(bare_key)
(pair
(bare_key)
(string))
(pair
(bare_key)
(integer))
(pair
(bare_key)
(string))))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - array of tables - nested arrays of tables
================================================================================
[[fruit]]
name = "apple"
[fruit.physical] # subtable
2019-08-18 06:30:34 -04:00
color = "red"
shape = "round"
[[fruit.variety]] # nested array of tables
2019-08-18 06:30:34 -04:00
name = "red delicious"
[[fruit.variety]]
name = "granny smith"
[[fruit]]
name = "banana"
[[fruit.variety]]
name = "plantain"
--------------------------------------------------------------------------------
(document
(table_array_element
(bare_key)
(pair
(bare_key)
(string)))
2019-08-18 06:30:34 -04:00
(table
(dotted_key
(bare_key)
(bare_key))
(comment)
(pair
(bare_key)
(string))
(pair
(bare_key)
(string)))
(table_array_element
2019-08-18 06:30:34 -04:00
(dotted_key
(bare_key)
(bare_key))
(comment)
(pair
(bare_key)
(string)))
(table_array_element
2019-08-18 06:30:34 -04:00
(dotted_key
(bare_key)
(bare_key))
(pair
(bare_key)
(string)))
(table_array_element
(bare_key)
(pair
(bare_key)
(string)))
(table_array_element
2019-08-18 06:30:34 -04:00
(dotted_key
(bare_key)
(bare_key))
(pair
(bare_key)
(string))))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - array of tables - append to array in undefined table (semantically INVALID)
================================================================================
# INVALID TOML DOC
[fruit.physical] # subtable, but to which parent element should it belong?
color = "red"
shape = "round"
[[fruit]] # parser must throw an error upon discovering that "fruit" is
# an array rather than a table
name = "apple"
--------------------------------------------------------------------------------
(document
(comment)
(table
(dotted_key
(bare_key)
(bare_key))
(comment)
(pair
(bare_key)
(string))
(pair
(bare_key)
(string)))
(table_array_element
(bare_key)
(comment)
(comment)
(pair
(bare_key)
(string))))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - array of tables - append to statically defined array (semantically INVALID)
================================================================================
# INVALID TOML DOC
fruit = []
[[fruit]] # Not allowed
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(comment)
(pair
(bare_key)
(array))
(table_array_element
(bare_key)
(comment)))
2019-08-18 06:30:34 -04:00
================================================================================
VALID - array of tables - append to table (semantically INVALID)
================================================================================
# INVALID TOML DOC
[[fruit]]
name = "apple"
[[fruit.variety]]
name = "red delicious"
# INVALID: This table conflicts with the previous array of tables
2019-08-18 06:30:34 -04:00
[fruit.variety]
name = "granny smith"
[fruit.physical]
color = "red"
shape = "round"
# INVALID: This array of tables conflicts with the previous table
[[fruit.physical]]
color = "green"
2019-08-18 06:30:34 -04:00
--------------------------------------------------------------------------------
(document
2019-08-18 06:30:34 -04:00
(comment)
(table_array_element
(bare_key)
(pair
(bare_key)
(string)))
(table_array_element
2019-08-18 06:30:34 -04:00
(dotted_key
(bare_key)
(bare_key))
(pair
(bare_key)
(string))
(comment))
2019-08-18 06:30:34 -04:00
(table
(dotted_key
(bare_key)
(bare_key))
(pair
(bare_key)
(string)))
(table
(dotted_key
(bare_key)
(bare_key))
(pair
(bare_key)
(string))
(pair
(bare_key)
(string))
(comment))
(table_array_element
2019-08-18 06:30:34 -04:00
(dotted_key
(bare_key)
(bare_key))
(pair
(bare_key)
(string))))