Skip to content

TUTO~3b: Adding the remaining atomic types

famished-tiger edited this page Feb 18, 2022 · 4 revisions

The QuotedKey class

Up to now our TOML implementation supported only unquoted keys, this time we want to cover quoted keys as well:

"this is a quoted key" = true

A quoted key resembles closely to a string, one may be therefore tempted to represent it with a TOMLString instance.
This would be incorrect, although quoted keys and strings look similar they differ from a syntax point of view:

  • A quoted key may appear on the left-hand side of a key-value pair,
  • A string, as a data value, is allowed on the right side only.

Furthermore, they are semantically different: a quoted key is ... a key.

The key class hierarchy is changed as follows:

Resulting key class hierarchy

Expanding the data type hierarchy

The toml_datatype.rb file starts with the following lines:

# Re-use datatypes defined in iteration 2
require_relative '../iter_2/toml_datatype'

In other words, we reuse “as is” the data types already implemented in the previous iteration.
That's a pretty good news.
What is more, the new data classes fit neatly in the existing data type hierarchy:

Expanded data type hierachy Legend:

  • In light gray, the classes from iteration 2,
  • In light yellow, the new class implemented for the present iteration.

The date/time classes

Here are the date / time data types implemented in this third iteration:

TOML Data type Examples Implementation
Offset Date-Time 1979-05-27T00:32:00-07:00 TOMLOffsetDateTime
Local Date-Time 1979-05-27T07:32:00 TOMLLocalDateTime
Local Date 1979-05-27 TOMLLocalDate
Local Time 7:32:00 TOMLLocalTime