From 73a52ff68748966f4e4dc318979b72dfe6415299 Mon Sep 17 00:00:00 2001 From: Koki Fushimi Date: Thu, 20 Jun 2024 12:35:04 +0900 Subject: [PATCH] Add objects to represent YAML versions. Here we use abstract type & subtyping because it's common traits pattern in Julia. We do not need to export these objects because we can use strings for versions in user-facing functions like: ```julia function load(str::AbstractString; version::YAMLVersion) # ... end function load(str::AbstractString; version::AbstractString) version == "1.1" ? load(str, version=YAMLV1_1()) : version == "1.2" ? load(str, version=YAMLV1_2()) : throw(ErrorException()) end load(str, version="1.1") ``` --- src/YAML.jl | 1 + src/versions.jl | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/versions.jl diff --git a/src/YAML.jl b/src/YAML.jl index 477239f..31a0274 100644 --- a/src/YAML.jl +++ b/src/YAML.jl @@ -27,6 +27,7 @@ using Dates using Printf using StringEncodings +include("versions.jl") include("queue.jl") include("buffered_input.jl") include("tokens.jl") diff --git a/src/versions.jl b/src/versions.jl new file mode 100644 index 0000000..30b51c8 --- /dev/null +++ b/src/versions.jl @@ -0,0 +1,25 @@ +""" + YAMLVersion + +A type used for controlling the YAML version. + +Planned to be supported versions are: + +- [`YAMLV1_1`](@ref): YAML version 1.1 +- [`YAMLV1_2`](@ref): YAML version 1.2 +""" +abstract type YAMLVersion end + +""" + YAMLV1_1 + +A singleton type for YAML version 1.1. +""" +struct YAMLV1_1 <: YAMLVersion end + +""" + YAMLV1_2 + +A singleton type for YAML version 1.2. +""" +struct YAMLV1_2 <: YAMLVersion end