intro.bbdoc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. The text.toml is a module designed for parsing TOML (Tom's Obvious, Minimal Language) documents.
  2. TOML is a human-readable data serialization format used for configuration files and data interchange
  3. between languages with different data structures. It is similar to JSON, YAML, and INI files but aims
  4. to be more minimal and easier to read and write.
  5. TOML documents consist of key-value pairs, which are organized into sections called tables.
  6. Each key-value pair is represented by a key followed by an equals sign (=) and a value.
  7. Tables can be nested, allowing for a hierarchical structure. TOML supports several data
  8. types, including strings, integers, floating-point numbers, booleans, dates, times, and arrays.
  9. ## Key-Value Pairs
  10. In TOML, key-value pairs are the basic building blocks of the document. Each key-value pair is
  11. represented by a key followed by an equals sign (=) and a value. Here's a simple example:
  12. ```toml
  13. key = "value"
  14. ```
  15. ## Tables
  16. Tables are sections within a TOML document used to organize key-value pairs. They are defined
  17. by square brackets `[` and `]`. Here's an example of a table:
  18. ```toml
  19. [table]
  20. key = "value"
  21. ```
  22. ## Nested Tables
  23. TOML allows for nesting tables to create a hierarchical structure. Nested tables are defined
  24. using dot notation within the square brackets. Here's an example of nested tables:
  25. ```toml
  26. [table]
  27. key = "value"
  28. [table.subtable]
  29. nested_key = "nested_value"
  30. ```
  31. ## Data Types
  32. TOML supports several data types, including:
  33. ### Strings
  34. Enclosed in double quotes `"`. They can be single-line or multi-line (using triple quotes `"""`).
  35. ```toml
  36. string_key = "This is a string"
  37. multiline_string_key = """
  38. This is a
  39. multiline string
  40. """
  41. ```
  42. ### Integers
  43. Whole numbers without a decimal point.
  44. ```toml
  45. integer_key = 42
  46. ```
  47. ### Floating-point numbers
  48. Numbers with a decimal point.
  49. ```toml
  50. float_key = 3.14
  51. ```
  52. ### Booleans
  53. Represented as true or false.
  54. ```toml
  55. boolean_key = true
  56. ```
  57. ### Dates
  58. Represented in the format YYYY-MM-DD.
  59. ```toml
  60. date_key = 2021-09-01
  61. ```
  62. ### Times
  63. Represented in the format hh:mm:ss (optionally with fractional seconds).
  64. ```toml
  65. time_key = 12:34:56
  66. time_with_fractional_key = 12:34:56.789
  67. ```
  68. ### Date-times
  69. Represented as a combination of date and time, separated by a T or a space.
  70. ```toml
  71. datetime_key = 2021-09-01T12:34:56
  72. datetime_with_space_key = 2021-09-01 12:34:56
  73. ```
  74. ### Arrays
  75. A collection of values enclosed in square brackets and separated by commas.
  76. ```toml
  77. array_key = [1, 2, 3]
  78. ```
  79. Here's a complete example of a TOML document using various data types and tables:
  80. ```toml
  81. title = "TOML Example"
  82. [author]
  83. name = "John Doe"
  84. age = 35
  85. is_member = true
  86. [book]
  87. title = "The TOML Guide"
  88. published_date = 2022-03-15
  89. price = 19.99
  90. keywords = ["TOML", "guide", "configuration"]
  91. [book.publication_time]
  92. hour = 15
  93. minute = 30
  94. ```
  95. ## Working with TOML documents
  96. The module is composed of several types and interfaces, including:
  97. #TToml: The main class responsible for parsing TOML documents. It provides functions for loading
  98. and parsing TOML files or strings, returning a #TTomlTable object.
  99. #TTomlTable: Represents a TOML table and implements the #ITomlNode interface. It offers methods
  100. for adding and retrieving nodes with specified keys and enumerating the keys.
  101. #TTomlArray: Represents a TOML array and implements the #ITomlNode interface.
  102. #TTomlString, #TTomlInteger, #TTomlFloatingPoint, #TTomlBoolean, #TTomlDate, #TTomlTime, and #TTomlDateTime:
  103. Each represents a specific TOML data type and implements the #ITomlNode interface.
  104. #ITomlNode: An interface implemented by all TOML nodes. It includes methods for determining
  105. the type of the node and converting it to the desired data type.