TOML profile

Toml is a readable, Mini language from github former CEO , Tom created. Obvious's tom, Minimal Language .

TOML committed to miniaturization and legibility of the configuration file. Wiki : https://github.com/toml-lang/toml/wiki , official website: https://github.com/toml-lang/toml , Go language parsing: https://github.com/BurntSushi/toml .

Comparison with other formats

TOML with other file formats and applications for configuring the sequence of data ( such as YAML and JSON) have the same characteristics. TOML and JSON are simple, using common data types, which makes them easy to use to write the machine code or parsing. TOML and YAML emphasize human readability, such as notes, it makes understanding the purpose of a given row easier. TOML except that it supports annotations ( unlike the JSON) , but maintains simplicity ( like YAML) .

Since TOML be explicitly designed into a configuration file format, so it is easy to parse, it is not intended any sequence of data structures. TOML file is the top level of a hash table, it's easy nested data in the key, but it does not allow an array of top-level or float, so it can not directly serialize some data. There is no standard to identify TOML the beginning or end of the file, it will send the file through the stream becomes complicated. These details must be negotiated in the application layer.

INI file is often associated with TOML compared, because of their similarity in terms of syntax and as the configuration file. However, the INI format is not standardized, they do not gracefully handle over twelve levels of nesting.

Basic grammar

 

# This is a TOML document.

title = "TOML Example"

[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00 # First class dates

[database]
server = "192.168.1.1"
ports = [ 8001, 8001, 8002 ]
connection_max = 5000
enabled = true

[servers]

  # Indentation (tabs and/or spaces) is allowed but not required
  [servers.alpha]
  ip = "10.0.0.1"
  dc = "eqdc10"

  [servers.beta]
  ip = "10.0.0.2"
  dc = "eqdc10"

[clients]
data = [ ["gamma", "delta"], [1, 2] ]

# Line breaks are OK when inside arrays
hosts = [
  "alpha",
  "omega"
]
  • Case-sensitive, must be UTF-8 encoding

  • Notes: #

  • Whitespace: Tab (0x09) or a space (0x20)

  • Newline: LF (0x0A) or CRLF (0x0D 0x0A)

  • Key-value pairs: one line, no key value is not available, each line can only hold a key-value pair

TOML The main structure is a key-value pairs with json similar. Value must be of the type: String, Integer, the Float, Boolean, Datetime, the Array, or Inline the Table .

keys

Recommended naked characters including quotation marks and periods, such as "127.0.0.1" = "value"

String

TOML there . 4 Species string representation: the basic, multi-line - basic, literal, a plurality of rows - Literals

Basic String

Wrapped in double quotes, all Unicode characters can occur, in addition to double quotes, backslash, control characters (U + 0000 to U + 001F ) need to escape.

Multiline - Basic String

Double quotation marks consists of three packages, in addition to the start delimiter newline, for about to be retained within a string

str1 = """
Roses are red
Violets are blue"""

Literal string

Wrapped by a single quotation mark, which does not allow the escape, and therefore the contents can easily represent the basic string need escaping

winpath = 'C:\Users\nodejs\templates'

Multiline - literal strings

And multi-line - substantially similar string

str1 = '''
Roses are red
Violets are blue'''

Value and BOOL value

int1 = +99

flt3 = -0.01

bool1 = true

Date Time

date1 = 1979-05-27T07:32:00Z

Array

Array enclosed in square brackets. Spaces will be ignored, including line breaks. Elements separated by commas.

arr1 = [1, 2, 3 ]
arr2 = [ "red", "yellow", "green" ]
arr3 = [ [ 1, 2 ], [3, 4, 5] ]

form

Form is also known as a hash table or dictionary, used to store key-value pairs. By the table name enclosed in square brackets, and its own line.

[dog]
onekey = onevalue

[dog.tater]
type = "pug"

TOML configuration Go deal

Reference: golang learning --TOML configuration process or https://studygolang.com/articles/12032?fr=sidebar

 

Guess you like

Origin www.cnblogs.com/embedded-linux/p/11140989.html