toml-rb 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d550c310fb16cc57d0bd5f2b5ca269d300c79268
4
- data.tar.gz: e5be2acd18c3ee096743c749c59ef893f1f96058
3
+ metadata.gz: d7c6222b73b280deabe97bc55a0eee9224412f76
4
+ data.tar.gz: b48c90b9abef1ab81ffb5051be7a575ed9b6383f
5
5
  SHA512:
6
- metadata.gz: 2d3c00589a249387ead32123e022bb1387a39f887e9f155111b94d6e782ab29d50ecf1b5e5d464b6cec811a05f76505f35abe1b65c9a831b2eae6bfcd60f8c80
7
- data.tar.gz: 6ff8631b538415e1f7806298dbc216beb952d05b944b478bad5281a78b5b393afdaacee4e3c8782e068d9f39a5d4b23ed7e545a6a7fc78a6ab491085a9d489d2
6
+ metadata.gz: 0bfb79b2cd16c3291d315d94d52be611d581c6a2e7eaca967f9d838af3fc56250f377ebbf2126a11e1153318fe642b16479c2895dcc75366274c8c3ef7623c07
7
+ data.tar.gz: 236b967fa06c531cf2a50cca3ea22a69ea4ae9bad978ceba75fd43c381c32b7b49b10796f7c150c9d96dede5decd2c36f6c7c3b1e0332c34a2d24b906199cc55
data/README.md CHANGED
@@ -8,7 +8,7 @@ toml-rb
8
8
 
9
9
  A [TOML](https://github.com/mojombo/toml) parser using [Citrus](http://mjackson.github.io/citrus) library.
10
10
 
11
- TOML specs supported: `0.3.1`
11
+ TOML specs supported: `0.4.0`
12
12
 
13
13
  Installation
14
14
  ------------
data/init.rb CHANGED
@@ -4,6 +4,7 @@ ROOT = File.dirname(File.expand_path(__FILE__))
4
4
 
5
5
  require "#{ROOT}/lib/toml/string"
6
6
  require "#{ROOT}/lib/toml/table_array"
7
+ require "#{ROOT}/lib/toml/inline_table"
7
8
  require "#{ROOT}/lib/toml/keyvalue"
8
9
  require "#{ROOT}/lib/toml/keygroup"
9
10
  require "#{ROOT}/lib/toml/parser"
@@ -41,7 +41,7 @@ module TOML
41
41
  end
42
42
  end
43
43
 
44
- return simple_pairs, nested_pairs, table_array_pairs
44
+ [simple_pairs, nested_pairs, table_array_pairs]
45
45
  end
46
46
 
47
47
  def dump_simple_pairs(simple_pairs)
@@ -15,6 +15,24 @@ grammar Document
15
15
  end
16
16
 
17
17
  rule keyvalue
18
- (space? key space? '=' space? v:(primitive | array) comment?) <Keyvalue>
18
+ (space? key space? '=' space? v:(toml_values) comment?) <Keyvalue>
19
19
  end
20
+
21
+ rule inline_table
22
+ (space? '{' (keyvalue (',' keyvalue)*)? space? '}' ) <InlineTable>
23
+ end
24
+
25
+ rule inline_table_array
26
+ ("[" indent? (hash_array)* ","? indent? comment? indent? "]" indent?) <InlineTableArray>
27
+ end
28
+
29
+ rule hash_array
30
+ comment | (inline_table ("," indent? (inline_table | comment))*)
31
+ end
32
+
33
+ rule toml_values
34
+ primitive | inline_table_array | inline_table | array
35
+ end
36
+
37
+
20
38
  end
@@ -72,7 +72,7 @@ grammar Primitive
72
72
  end
73
73
 
74
74
  rule integer
75
- (sign? [0-9]+) { to_str.to_i }
75
+ (sign? [0-9_]+) { to_str.to_i }
76
76
  end
77
77
 
78
78
  rule sign
@@ -104,7 +104,7 @@ grammar Primitive
104
104
  end
105
105
 
106
106
  rule bare_key
107
- [a-zA-Z_] [a-zA-Z_0-9_-]*
107
+ [a-zA-Z_] [a-zA-Z0-9_-]*
108
108
  end
109
109
 
110
110
  rule quoted_key
@@ -0,0 +1,15 @@
1
+ module InlineTable
2
+ def value
3
+ keyvalue_pairs = captures[:keyvalue].map(&:value)
4
+
5
+ Hash[keyvalue_pairs.map { |kv| [kv.key, kv.value] }]
6
+ end
7
+ end
8
+
9
+ module InlineTableArray
10
+ def value
11
+ tables = captures[:hash_array].map { |x| x.captures[:inline_table] }
12
+
13
+ tables.flatten.map(&:value)
14
+ end
15
+ end
@@ -2,6 +2,8 @@ module TOML
2
2
  class ValueOverwriteError < StandardError; end
3
3
 
4
4
  class Keyvalue
5
+ attr_reader :key, :value
6
+
5
7
  def initialize(key, value)
6
8
  @key, @value = key, value
7
9
  end
@@ -13,7 +15,7 @@ module TOML
13
15
  end
14
16
 
15
17
  def accept_visitor(parser)
16
- parser.visit_keyvalue(self)
18
+ parser.visit_keyvalue self
17
19
  end
18
20
  end
19
21
  end
@@ -24,11 +24,15 @@ module TOML
24
24
  end
25
25
 
26
26
  def visit_keygroup(keygroup)
27
- @current = keygroup.navigate_keys(@hash, @symbolize_keys)
27
+ @current = keygroup.navigate_keys @hash, @symbolize_keys
28
28
  end
29
29
 
30
30
  def visit_keyvalue(keyvalue)
31
- keyvalue.assign(@current, @symbolize_keys)
31
+ keyvalue.assign @current, @symbolize_keys
32
+ end
33
+
34
+ def visit_inline_table(inline_table)
35
+ inline_table.assign @current, @symbolize_keys
32
36
  end
33
37
  end
34
38
  end
@@ -0,0 +1,244 @@
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
+ key1 = 5e+22
142
+ key2 = 1e6
143
+ key3 = -2E-2
144
+
145
+ [float.both]
146
+
147
+ key = 6.626e-34
148
+
149
+ [float.underscores]
150
+
151
+ key1 = 9_224_617.445_991_228_313
152
+ key2 = 1e1_000
153
+
154
+
155
+ ################################################################################
156
+ ## Boolean
157
+
158
+ # Booleans are just the tokens you're used to. Always lowercase.
159
+
160
+ [boolean]
161
+
162
+ True = true
163
+ False = false
164
+
165
+
166
+ ################################################################################
167
+ ## Datetime
168
+
169
+ # Datetimes are RFC 3339 dates.
170
+
171
+ [datetime]
172
+
173
+ key1 = 1979-05-27T07:32:00Z
174
+ key2 = 1979-05-27T00:32:00-07:00
175
+ key3 = 1979-05-27T00:32:00.999999-07:00
176
+
177
+
178
+ ################################################################################
179
+ ## Array
180
+
181
+ # Arrays are square brackets with other primitives inside. Whitespace is
182
+ # ignored. Elements are separated by commas. Data types may not be mixed.
183
+
184
+ [array]
185
+
186
+ key1 = [ 1, 2, 3 ]
187
+ key2 = [ "red", "yellow", "green" ]
188
+ key3 = [ [ 1, 2 ], [3, 4, 5] ]
189
+ key4 = [ [ 1, 2 ], ["a", "b", "c"] ] # this is ok
190
+
191
+ # Arrays can also be multiline. So in addition to ignoring whitespace, arrays
192
+ # also ignore newlines between the brackets. Terminating commas are ok before
193
+ # the closing bracket.
194
+
195
+ key5 = [
196
+ 1, 2, 3
197
+ ]
198
+ key6 = [
199
+ 1,
200
+ 2, # this is ok
201
+ ]
202
+
203
+
204
+ ################################################################################
205
+ ## Array of Tables
206
+
207
+ # These can be expressed by using a table name in double brackets. Each table
208
+ # with the same double bracketed name will be an element in the array. The
209
+ # tables are inserted in the order encountered.
210
+
211
+ [[products]]
212
+
213
+ name = "Hammer"
214
+ sku = 738594937
215
+
216
+ [[products]]
217
+
218
+ [[products]]
219
+
220
+ name = "Nail"
221
+ sku = 284758393
222
+ color = "gray"
223
+
224
+
225
+ # You can create nested arrays of tables as well.
226
+
227
+ [[fruit]]
228
+ name = "apple"
229
+
230
+ [fruit.physical]
231
+ color = "red"
232
+ shape = "round"
233
+
234
+ [[fruit.variety]]
235
+ name = "red delicious"
236
+
237
+ [[fruit.variety]]
238
+ name = "granny smith"
239
+
240
+ [[fruit]]
241
+ name = "banana"
242
+
243
+ [[fruit.variety]]
244
+ name = "plantain"
@@ -83,17 +83,26 @@ class GrammarTest < Test::Unit::TestCase
83
83
  def test_integer
84
84
  match = Document.parse('26', root: :number)
85
85
  assert_equal(26, match.value)
86
+
87
+ match = Document.parse('1_200_000_999', root: :number)
88
+ assert_equal(1_200_000_999, match.value)
86
89
  end
87
90
 
88
91
  def test_float
89
92
  match = Document.parse('1.69', root: :number)
90
93
  assert_equal(1.69, match.value)
91
94
 
95
+ match = Document.parse('1_000.69', root: :number)
96
+ assert_equal(1000.69, match.value)
97
+
92
98
  match = Document.parse('1e6', root: :number)
93
99
  assert_equal(1e6, match.value)
94
100
 
95
101
  match = Document.parse('1.02e-46', root: :number)
96
102
  assert_equal(1.02e-46, match.value)
103
+
104
+ match = Document.parse('+1e4_000_000', root: :number)
105
+ assert_equal(1e4_000_000, match.value)
97
106
  end
98
107
 
99
108
  def test_signed_numbers
@@ -135,6 +144,10 @@ class GrammarTest < Test::Unit::TestCase
135
144
 
136
145
  match = Document.parse('[ ["hey", "TOML"], [2,4] ]', root: :array)
137
146
  assert_equal([%w(hey TOML), [2, 4]], match.value)
147
+
148
+ match = Document.parse('[ { one = 1 }, { two = 2, three = 3} ]',
149
+ root: :inline_table_array)
150
+ assert_equal([{ 'one' => 1 }, { 'two' => 2, 'three' => 3 }], match.value)
138
151
  end
139
152
 
140
153
  def test_multiline_array
@@ -162,6 +175,17 @@ class GrammarTest < Test::Unit::TestCase
162
175
  assert_equal(Time.utc(1986, 8, 28, 18, 15, 0.123), match.value)
163
176
  end
164
177
 
178
+ def test_inline_table
179
+ match = Document.parse('{ }', root: :inline_table)
180
+ assert_equal({}, match.value)
181
+
182
+ match = Document.parse('{ simple = true, params = 2 }', root: :inline_table)
183
+ assert_equal({ 'simple' => true, 'params' => 2 }, match.value)
184
+
185
+ match = Document.parse('{ nest = { hard = true } }', root: :inline_table)
186
+ assert_equal({ 'nest' => { 'hard' => true } }, match.value)
187
+ end
188
+
165
189
  private
166
190
 
167
191
  # Creates all the alternatives of valid indentations to test
@@ -1,77 +1,98 @@
1
1
  class TomlExamples
2
- def self.example_v_0_3_1
2
+ def self.example_v_0_4_0
3
3
  {
4
- 'Table' => {
5
- 'key' => 'value'
6
- },
7
- 'dog' => {
8
- 'tater' => {
9
- 'type' => 'pug'
4
+ "table" => {
5
+ "key" => "value",
6
+ "subtable" => {
7
+ "key" => "another value"
8
+ },
9
+ "inline" => {
10
+ "name" => {
11
+ "first" => "Tom",
12
+ "last" => "Preston-Werner"
13
+ },
14
+ "point" => {
15
+ "x" => 1,
16
+ "y" => 2
17
+ }
10
18
  }
11
19
  },
12
- 'x' => {
13
- 'y' => {
14
- 'z' => {
15
- 'w' => {}
20
+ "x" => {
21
+ "y" => {
22
+ "z" => {
23
+ "w" => {}
16
24
  }
17
25
  }
18
26
  },
19
- 'String' => {
20
- 'basic' => "I'm a string. \"You can quote me\". Name\tJos\\u00E9\nLocation\tSF.",
21
- 'Multiline' => {
22
- 'key1' => "One\nTwo",
23
- 'key2' => "One\nTwo",
24
- 'key3' => "One\nTwo"
27
+ "string" => {
28
+ "basic" => {
29
+ "basic" => "I'm a string. \"You can quote me\". Name\tJos\\u00E9\nLocation\tSF."
25
30
  },
26
- 'Multilined' => {
27
- 'Singleline' => {
28
- 'key1' => 'The quick brown fox jumps over the lazy dog.',
29
- 'key2' => 'The quick brown fox jumps over the lazy dog.',
30
- 'key3' => 'The quick brown fox jumps over the lazy dog.'
31
+ "multiline" => {
32
+ "key1" => "One\nTwo",
33
+ "key2" => "One\nTwo",
34
+ "key3" => "One\nTwo",
35
+ "continued" => {
36
+ "key1" => "The quick brown fox jumps over the lazy dog.",
37
+ "key2" => "The quick brown fox jumps over the lazy dog.",
38
+ "key3" => "The quick brown fox jumps over the lazy dog."
31
39
  }
32
40
  },
33
- 'Literal' => {
34
- 'winpath' => 'C:\\Users\nodejs\templates',
35
- 'winpath2' => "\\\\ServerX\\admin$\\system32\\",
36
- 'quoted' => 'Tom "Dubs" Preston-Werner',
37
- 'regex' => '<\i\c*\s*>',
38
- 'Multiline' => {
39
- "regex2" => "I [dw]on't need \\d{2} apples",
40
- "lines" => "The first newline is\ntrimmed in raw strings.\n All other whitespace\n is preserved.\n"
41
+ "literal" => {
42
+ "winpath" => "C:\\Users\\nodejs\\templates",
43
+ "winpath2" => "\\\\ServerX\\admin$\\system32\\",
44
+ "quoted" => "Tom\"Dubs\"Preston-Werner",
45
+ "regex" => "<\\i\\c*\\s*>",
46
+ "multiline" => {
47
+ "regex2" => "I[
48
+ dw
49
+ ]on'tneed\\d{
50
+ 2
51
+ }apples",
52
+ "lines" => "Thefirstnewlineis\ntrimmedinrawstrings.\nAllotherwhitespace\nispreserved.\n"
41
53
  }
42
54
  }
43
55
  },
44
- "Integer" => {
56
+ "integer" => {
45
57
  "key1" => 99,
46
58
  "key2" => 42,
47
59
  "key3" => 0,
48
- "key4" => -17
60
+ "key4" => -17,
61
+ "underscores" => {
62
+ "key1" => 1000,
63
+ "key2" => 5349221,
64
+ "key3" => 12345
65
+ }
49
66
  },
50
- "Float" => {
67
+ "float" => {
51
68
  "fractional" => {
52
69
  "key1" => 1.0,
53
70
  "key2" => 3.1415,
54
71
  "key3" => -0.01
55
72
  },
56
- "both" => {
57
- "key" => 6.626e-34
58
- },
59
73
  "exponent" => {
60
74
  "key1" => 5.0e+22,
61
75
  "key2" => 1000000.0,
62
76
  "key3" => -0.02
77
+ },
78
+ "both" => {
79
+ "key" => 6.626e-34
80
+ },
81
+ "underscores" => {
82
+ "key1" => 9224617.445991227,
83
+ "key2" => 1e1_000
63
84
  }
64
85
  },
65
- "Booleans" => {
86
+ "boolean" => {
66
87
  "True" => true,
67
88
  "False" => false
68
89
  },
69
- "Datetime" => {
90
+ "datetime" => {
70
91
  "key1" => Time.utc(1979, 05, 27, 07, 32, 0),
71
92
  "key2" => Time.new(1979, 05, 27, 00, 32, 0, '-07:00'),
72
93
  "key3" => Time.new(1979, 05, 27, 00, 32, 0.999999, '-07:00')
73
94
  },
74
- "Array" => {
95
+ "array" => {
75
96
  "key1" => [1, 2, 3],
76
97
  "key2" => %w(red yellow green),
77
98
  "key3" => [[1, 2], [3, 4, 5]],
@@ -2,10 +2,10 @@ require_relative 'helper'
2
2
  require_relative 'toml_examples'
3
3
 
4
4
  class TomlTest < Test::Unit::TestCase
5
- def test_file_v_0_3_1
6
- path = File.join(File.dirname(__FILE__), 'example-v0.3.1.toml')
5
+ def test_file_v_0_4_0
6
+ path = File.join(File.dirname(__FILE__), 'example-v0.4.0.toml')
7
7
  parsed = TOML.load_file(path)
8
- hash = TomlExamples.example_v_0_3_1
8
+ hash = TomlExamples.example_v_0_4_0
9
9
 
10
10
  assert_equal hash['Array'], parsed['Array']
11
11
  assert_equal hash['Booleans'], parsed['Booleans']
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'toml-rb'
3
- s.version = '0.2.1'
3
+ s.version = '0.3.0'
4
4
  s.date = Time.now.strftime('%Y-%m-%d')
5
5
  s.summary = 'TOML parser in ruby, for ruby.'
6
6
  s.description = 'A TOML parser using Citrus parsing library. '
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toml-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emiliano Mancuso
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-05 00:00:00.000000000 Z
12
+ date: 2015-02-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: citrus
@@ -48,6 +48,7 @@ files:
48
48
  - lib/toml/grammars/document.citrus
49
49
  - lib/toml/grammars/helper.citrus
50
50
  - lib/toml/grammars/primitive.citrus
51
+ - lib/toml/inline_table.rb
51
52
  - lib/toml/keygroup.rb
52
53
  - lib/toml/keyvalue.rb
53
54
  - lib/toml/parser.rb
@@ -55,7 +56,7 @@ files:
55
56
  - lib/toml/table_array.rb
56
57
  - test/dumper_test.rb
57
58
  - test/errors_test.rb
58
- - test/example-v0.3.1.toml
59
+ - test/example-v0.4.0.toml
59
60
  - test/example.toml
60
61
  - test/grammar_test.rb
61
62
  - test/hard_example.toml
@@ -1,180 +0,0 @@
1
- # Comment
2
- # I am a comment. Hear me roar. Roar.
3
-
4
- # Table
5
- # Tables (also known as hash tables or dictionaries) are collections of key/value pairs.
6
- # They appear in square brackets on a line by themselves.
7
-
8
- [Table]
9
-
10
- key = "value" # Yeah, you can do this.
11
-
12
- # Nested tables are denoted by table names with dots in them. Name your tables whatever crap you please, just don't use #, ., [ or ].
13
-
14
- [dog.tater]
15
- type = "pug"
16
-
17
- # You don't need to specify all the super-tables if you don't want to. TOML knows how to do it for you.
18
-
19
- # [x] you
20
- # [x.y] don't
21
- # [x.y.z] need these
22
- [x.y.z.w] # for this to work
23
-
24
- # String
25
- # There are four ways to express strings: basic, multi-line basic, literal, and multi-line literal.
26
- # All strings must contain only valid UTF-8 characters.
27
-
28
- [String]
29
- basic = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF."
30
-
31
- [String.Multiline]
32
-
33
- # The following strings are byte-for-byte equivalent:
34
- key1 = "One\nTwo"
35
- key2 = """One\nTwo"""
36
- key3 = """
37
- One
38
- Two"""
39
-
40
- [String.Multilined.Singleline]
41
-
42
- # The following strings are byte-for-byte equivalent:
43
- key1 = "The quick brown fox jumps over the lazy dog."
44
-
45
- key2 = """
46
- The quick brown \
47
-
48
-
49
- fox jumps over \
50
- the lazy dog."""
51
-
52
- key3 = """\
53
- The quick brown \
54
- fox jumps over \
55
- the lazy dog.\
56
- """
57
-
58
- [String.Literal]
59
-
60
- # What you see is what you get.
61
- winpath = 'C:\Users\nodejs\templates'
62
- winpath2 = '\\ServerX\admin$\system32\'
63
- quoted = 'Tom "Dubs" Preston-Werner'
64
- regex = '<\i\c*\s*>'
65
-
66
- [String.Literal.Multiline]
67
-
68
- regex2 = '''I [dw]on't need \d{2} apples'''
69
- lines = '''
70
- The first newline is
71
- trimmed in raw strings.
72
- All other whitespace
73
- is preserved.
74
- '''
75
-
76
- # Integer
77
- # Integers are whole numbers. Positive numbers may be prefixed with a plus sign.
78
- # Negative numbers are prefixed with a minus sign.
79
-
80
- [Integer]
81
- key1 = +99
82
- key2 = 42
83
- key3 = 0
84
- key4 = -17
85
-
86
- # Float
87
- # A float consists of an integer part (which may be prefixed with a plus or minus sign)
88
- # followed by a fractional part and/or an exponent part.
89
-
90
- [Float.fractional]
91
-
92
- # fractional
93
- key1 = +1.0
94
- key2 = 3.1415
95
- key3 = -0.01
96
-
97
- [Float.exponent]
98
-
99
- # exponent
100
- key1 = 5e+22
101
- key2 = 1e6
102
- key3 = -2E-2
103
-
104
- [Float.both]
105
-
106
- # both
107
- key = 6.626e-34
108
-
109
- # Boolean
110
- # Booleans are just the tokens you're used to. Always lowercase.
111
-
112
- [Booleans]
113
- True = true
114
- False = false
115
-
116
- # Datetime
117
- # Datetimes are RFC 3339 dates.
118
-
119
- [Datetime]
120
- key1 = 1979-05-27T07:32:00Z
121
- key2 = 1979-05-27T00:32:00-07:00
122
- key3 = 1979-05-27T00:32:00.999999-07:00
123
-
124
- # Array
125
- # Arrays are square brackets with other primitives inside. Whitespace is ignored. Elements are separated by commas. Data types may not be mixed.
126
-
127
- [Array]
128
- key1 = [ 1, 2, 3 ]
129
- key2 = [ "red", "yellow", "green" ]
130
- key3 = [ [ 1, 2 ], [3, 4, 5] ]
131
- key4 = [ [ 1, 2 ], ["a", "b", "c"] ] # this is ok
132
-
133
- #Arrays can also be multiline. So in addition to ignoring whitespace, arrays also ignore newlines between the brackets.
134
- # Terminating commas are ok before the closing bracket.
135
-
136
- key5 = [
137
- 1, 2, 3
138
- ]
139
- key6 = [
140
- 1,
141
- 2, # this is ok
142
- ]
143
-
144
- # Array of Tables
145
- # These can be expressed by using a table name in double brackets.
146
- # Each table with the same double bracketed name will be an element in the array.
147
- # The tables are inserted in the order encountered.
148
-
149
- [[products]]
150
- name = "Hammer"
151
- sku = 738594937
152
-
153
- [[products]]
154
-
155
- [[products]]
156
- name = "Nail"
157
- sku = 284758393
158
- color = "gray"
159
-
160
-
161
- # You can create nested arrays of tables as well.
162
-
163
- [[fruit]]
164
- name = "apple"
165
-
166
- [fruit.physical]
167
- color = "red"
168
- shape = "round"
169
-
170
- [[fruit.variety]]
171
- name = "red delicious"
172
-
173
- [[fruit.variety]]
174
- name = "granny smith"
175
-
176
- [[fruit]]
177
- name = "banana"
178
-
179
- [[fruit.variety]]
180
- name = "plantain"