cable_yaml_mod Module

Minimal YAML reading interface for CABLE.

The YAML file is parsed with yaFyaml and immediately copied into a plain tree of cable_yaml_node_t values, so no yaFyaml types are visible outside this module. Every node is a scalar, a mapping or a sequence. Mapping entries keep their file order, and each child node stores the key it was found under.



Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: CABLE_YAML_UNDEFINED = 0
integer, public, parameter :: CABLE_YAML_SCALAR = 1
integer, public, parameter :: CABLE_YAML_MAPPING = 2
integer, public, parameter :: CABLE_YAML_SEQUENCE = 3

Derived Types

type, public ::  cable_yaml_node_t

A node of a parsed YAML document.

Components

Type Visibility Attributes Name Initial
integer, public :: node_kind = CABLE_YAML_UNDEFINED

One of the CABLE_YAML_* kind constants.

character(len=:), public, allocatable :: key

The mapping key this node was found under. Unallocated for the root node and for sequence items.

character(len=:), public, allocatable :: text

The scalar value as text. Only allocated for scalar nodes.

type(cable_yaml_node_t), public, allocatable :: children(:)

Mapping values (in file order) or sequence items.

Type-Bound Procedures

procedure, public :: copy_node
generic, public :: assignment(=) => copy_node
procedure, public :: is_scalar => node_is_scalar
procedure, public :: is_mapping => node_is_mapping
procedure, public :: is_sequence => node_is_sequence
procedure, public :: size => node_size
procedure, public :: has => node_has
procedure, public :: get => node_get
procedure, public :: at => node_at
procedure, public :: as_string => node_as_string
procedure, public :: as_integer => node_as_integer
procedure, public :: as_real => node_as_real
procedure, public :: as_logical => node_as_logical
procedure, public :: get_string => node_get_string
procedure, public :: get_integer => node_get_integer
procedure, public :: get_real => node_get_real
procedure, public :: get_logical => node_get_logical

Functions

public function cable_yaml_load_file(file_name) result(root)

Parse the YAML file at file_name. Aborts if the file cannot be read or is not valid YAML.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: file_name

Return Value type(cable_yaml_node_t)

public function cable_yaml_parse_text(text) result(root)

Parse YAML held in a string. Aborts if the text is not valid YAML.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: text

Return Value type(cable_yaml_node_t)

private recursive function convert_node(parsed_node) result(converted)

Copy a yaFyaml node and everything below it into a cable_yaml_node_t.

Arguments

Type IntentOptional Attributes Name
class(YAML_Node), intent(in), target :: parsed_node

Return Value type(cable_yaml_node_t)

private function scalar_text(parsed_node) result(text)

The text of a scalar yaFyaml node. Non-string scalars are rendered in the form they are written in YAML (true/false for booleans).

Arguments

Type IntentOptional Attributes Name
class(YAML_Node), intent(in), target :: parsed_node

Return Value character(len=:), allocatable

private pure function node_is_scalar(this)

Arguments

Type IntentOptional Attributes Name
class(cable_yaml_node_t), intent(in) :: this

Return Value logical

private pure function node_is_mapping(this)

Arguments

Type IntentOptional Attributes Name
class(cable_yaml_node_t), intent(in) :: this

Return Value logical

private pure function node_is_sequence(this)

Arguments

Type IntentOptional Attributes Name
class(cable_yaml_node_t), intent(in) :: this

Return Value logical

private pure function node_size(this)

Number of children of a mapping or sequence. Zero for scalars.

Arguments

Type IntentOptional Attributes Name
class(cable_yaml_node_t), intent(in) :: this

Return Value integer

private pure function node_index(this, key) result(child_index)

Position of key among the children of a mapping, or 0 if absent.

Arguments

Type IntentOptional Attributes Name
class(cable_yaml_node_t), intent(in) :: this
character(len=*), intent(in) :: key

Return Value integer

private pure function node_has(this, key)

Whether this node is a mapping containing key.

Arguments

Type IntentOptional Attributes Name
class(cable_yaml_node_t), intent(in) :: this
character(len=*), intent(in) :: key

Return Value logical

private function node_get(this, key) result(child)

The value stored under key. Aborts if this node has no such key.

Arguments

Type IntentOptional Attributes Name
class(cable_yaml_node_t), intent(in) :: this
character(len=*), intent(in) :: key

Return Value type(cable_yaml_node_t)

private function node_at(this, child_index) result(child)

The child_index-th child (1-based) of a mapping or sequence.

Arguments

Type IntentOptional Attributes Name
class(cable_yaml_node_t), intent(in) :: this
integer, intent(in) :: child_index

Return Value type(cable_yaml_node_t)

private function node_as_string(this) result(text)

The text of a scalar node. Aborts for mappings and sequences.

Arguments

Type IntentOptional Attributes Name
class(cable_yaml_node_t), intent(in) :: this

Return Value character(len=:), allocatable

private function node_as_integer(this) result(value)

The scalar value as an integer. Aborts if it is not one.

Arguments

Type IntentOptional Attributes Name
class(cable_yaml_node_t), intent(in) :: this

Return Value integer

private function node_as_real(this) result(value)

The scalar value as a real. Aborts if it is not one.

Arguments

Type IntentOptional Attributes Name
class(cable_yaml_node_t), intent(in) :: this

Return Value real

private function node_as_logical(this) result(value)

The scalar value as a logical (true or false). Aborts otherwise.

Arguments

Type IntentOptional Attributes Name
class(cable_yaml_node_t), intent(in) :: this

Return Value logical

private function node_get_string(this, key) result(text)

Shorthand for this%get(key)%as_string().

Arguments

Type IntentOptional Attributes Name
class(cable_yaml_node_t), intent(in) :: this
character(len=*), intent(in) :: key

Return Value character(len=:), allocatable

private function node_get_integer(this, key) result(value)

Shorthand for this%get(key)%as_integer().

Arguments

Type IntentOptional Attributes Name
class(cable_yaml_node_t), intent(in) :: this
character(len=*), intent(in) :: key

Return Value integer

private function node_get_real(this, key) result(value)

Shorthand for this%get(key)%as_real().

Arguments

Type IntentOptional Attributes Name
class(cable_yaml_node_t), intent(in) :: this
character(len=*), intent(in) :: key

Return Value real

private function node_get_logical(this, key) result(value)

Shorthand for this%get(key)%as_logical().

Arguments

Type IntentOptional Attributes Name
class(cable_yaml_node_t), intent(in) :: this
character(len=*), intent(in) :: key

Return Value logical


Subroutines

private recursive subroutine copy_node(destination, source)

Deep copy of a node and everything below it.

Read more…

Arguments

Type IntentOptional Attributes Name
class(cable_yaml_node_t), intent(inout) :: destination
type(cable_yaml_node_t), intent(in) :: source