- •Table of Contents
- •Chapter 1. Introduction
- •1.1. Goals
- •1.2. Prior Art
- •1.3. Relation to XML
- •1.4. Terminology
- •Chapter 2. Preview
- •2.1. Collections
- •2.2. Structures
- •2.3. Scalars
- •2.4. Tags
- •2.5. Full Length Example
- •Chapter 3. Processing YAML Information
- •3.1. Processes
- •3.1.1. Represent
- •3.1.2. Serialize
- •3.1.3. Present
- •3.1.4. Parse
- •3.1.5. Compose
- •3.1.6. Construct
- •3.2. Information Models
- •3.2.1. Representation Graph
- •3.2.1.1. Nodes
- •3.2.1.2. Tags
- •3.2.1.3. Nodes Comparison
- •3.2.2. Serialization Tree
- •3.2.2.1. Keys Order
- •3.2.2.2. Anchors and Aliases
- •3.2.3. Presentation Stream
- •3.2.3.1. Node Styles
- •3.2.3.2. Scalar Formats
- •3.2.3.3. Comments
- •3.2.3.4. Directives
- •3.3. Loading Failure Points
- •3.3.1. Well-Formed and Identified
- •3.3.2. Resolved
- •3.3.3. Recognized and Valid
- •3.3.4. Available
- •Chapter 4. Syntax
- •4.1. Characters
- •4.1.1. Character Set
- •4.1.2. Character Encoding
- •4.1.3. Indicator Characters
- •4.1.4. Line Break Characters
- •4.1.5. Miscellaneous Characters
- •4.1.6. Escape Sequences
- •4.2. Syntax Primitives
- •4.2.1. Production Parameters
- •4.2.2. Indentation Spaces
- •4.2.3. Comments
- •4.2.4. Separation Spaces
- •4.2.5. Ignored Line Prefix
- •4.2.6. Line Folding
- •4.3. YAML Character Stream
- •4.3.1. Directives
- •4.3.1.2.1. Tag Prefixes
- •4.3.1.2.2. Tag Handles
- •4.3.2. Document Boundary Markers
- •4.3.3. Documents
- •4.3.4. Complete Stream
- •4.4. Nodes
- •4.4.1. Node Anchors
- •4.4.2. Node Tags
- •4.4.3. Node Content
- •4.4.4. Alias Nodes
- •4.4.5. Complete Nodes
- •4.4.5.1. Flow Nodes
- •4.4.5.2. Block Nodes
- •4.5. Scalar Styles
- •4.5.1. Flow Scalar Styles
- •4.5.1.1. Double Quoted
- •4.5.1.2. Single Quoted
- •4.5.1.3. Plain
- •4.5.2. Block Scalar Header
- •4.5.2.1. Block Style Indicator
- •4.5.2.2. Block Indentation Indicator
- •4.5.2.3. Block Chomping Indicator
- •4.5.3. Block Scalar Styles
- •4.5.3.1. Literal
- •4.5.3.2. Folded
- •4.6. Collection Styles
- •4.6.1. Sequence Styles
- •4.6.1.1. Flow Sequences
- •4.6.1.2. Block Sequences
- •4.6.2. Mapping Styles
- •4.6.2.1. Flow Mappings
- •4.6.2.2. Block Mappings
- •Terms Index
|
Syntax |
|
Example 4.67. Plain Line Breaks |
|
|
as space →↓ |
%YAML 1.1 |
|
trimmed ·↓ |
--- |
|
↓ |
!!str "as space \ |
|
trimmed\n\ |
||
specific |
||
specific\L\n\ |
||
↓ |
none" |
|
none |
|
|
|
Legend: |
|
|
s-l-plain-break(n) |
|
|
s-ignored-white |
A multi-line plain scalar contains additional continuation lines following the first line.
[162] ns-plain-multi(n,c) ::= ns-plain-single(c) s-ns-plain-more(n,c)*
Each continuation line must contain at least one non-space character. Note that it may be preceded by any number of empty lines.
[163] s-ns-plain-more(n,c) ::= s-l-plain-break(n) s-ignored-prefix(n,plain) ns-plain-char(c) ( nb-plain-char(c)* ns-plain-char(c) )?
Example 4.68. Plain Scalars
first line ·↓ |
%YAML 1.1 |
|
···↓ |
--- |
|
··more line |
!!str "first line\n\ |
|
more line" |
||
|
Legend:
ns-plain-single(c)
s-l-plain-break(n)
s-ignored-prefix(n,s)
s-ns-plain-more(n,c)
4.5.2. Block Scalar Header
Block scalars are specified by several indicators given in a header preceding the content itself. The header is followed by an ignored line break (with an optional comment).
[164] c-b-block-header(s,m,t) ::= c-style-indicator(s)
( ( c-indentation-indicator(m) c-chomping-indicator(t) )
| ( c-chomping-indicator(t) c-indentation-indicator(m) ) )
s-b-comment
60
XSL• FO
RenderX
Syntax
Example 4.69. Block Scalar Header
-
| # Just the style¯
literal
-
>1 # Indentation indicator¯
·folded
-
|+ # Chomping indicator¯
keep
-
>-1 # Both indicators¯
·strip
%YAML 1.1
---
!!seq [
!!str "literal\n", !!str "·folded\n", !!str "keep\n\n", !!str "·strip",
]
Legend:
c-b-block-header(s,m,t)
4.5.2.1. Block Style Indicator
The first character of the block scalar header is either “|” for a literal scalar or “>” for a folded scalar.
[165] c-style-indicator(s) ::= s = literal Þ “|”
|
s = folded |
Þ “>” |
|
Example 4.70. Block Style Indicator |
|
||
- |
| |
%YAML 1.1 |
|
|
literal |
--- |
|
|
!!seq [ |
||
- |
> |
||
|
|||
!!str "literal\n", folded
!!str "folded\n",
]
Legend:
c-style-indicator(s)
4.5.2.2. Block Indentation Indicator
Typically, the indentation level of a block scalar is detected from its first non-empty line. This detection fails when this line contains leading space characters (note it may safely start with a tab or a “#” character). When detection fails, YAML requires that the indentation level for the content be given using an explicit indentation indicator. This level is specified as the integer number of the additional indentation spaces used for the content. If the block scalar begins with leading empty lines followed by a non-empty line, the indentation level is deduced from the non-empty line. In this case, it is an error for any such leading empty line to contain more spaces than the indentation level deduced from the non-empty line. It is always valid to specify an indentation indicator for a block scalar node, though a YAML processor should only do so in cases where detection will fail.
[166] c-indentation-indicator(m) ::= explicit(m) Þ ns-dec-digit - “0” detect(m) Þ /* empty */
61
XSL• FO
RenderX
Syntax
Example 4.71. Block Indentation Indicator
- |
·
detected - >
· 
·· 
··
# detected
- |1
·
·explicit
- >
·
®
·
detected
%YAML 1.1
---
!!seq [
!!str "detected\n", !!str "\n\n# detected\n", !!str "·explicit\n", !!str "\t·detected\n",
]
Legend:
c-indentation-indicator(m)
s-indent(n)
Example 4.72. Invalid Block Scalar Indentation Indicators
- | ·
·
·text - >
··text
·
text
- |1
·
text
ERROR:
-A leading all-space line must not have too many
spaces
.
-A following text line must
not be
less indented
.
-The text is
less indented
than the indicated level.
4.5.2.3. Block Chomping Indicator
YAML supports three possible block chomping methods:
Strip Stripping is specified using the “-” chomping indicator. In this case, the line break character of the last non-empty line (if any) is excluded from the scalar's content. Any trailing empty lines are considered to be (empty) comment lines and are also discarded.
Clip Clipping the default behavior used if no explicit chomping indicator is specified. In this case, The line break character of the last non-empty line (if any) is preserved in the scalar's content. However, any trailing empty lines are considered to be (empty) comment lines and are discarded.
Keep Keeping is specified using the “+” chomping indicator. In this case, the line break character of the last non-empty line (if any) is preserved in the scalar's content. In addition, any trailing empty lines are each considered to present a single trailng content line break. Note that these line breaks are not subject to folding.
The chomping method ised is a presentation detail and is not reflected in the serialization tree (and hence the representation graph).
[167] c-chomping-indicator(t) ::= t |
= strip |
Þ “-” |
|
t |
= |
clip |
Þ /* empty */ |
t |
= |
keep |
Þ “+” |
|
|
62 |
|
XSL• FO
RenderX
Syntax
Thus, the final line break of a block scalar may be included or excluded from the content, depending on the specified chomping indicator.
[168] b-chomped-last(t) ::= t |
= strip |
Þ b-strip-last |
t |
= clip |
Þ b-keep-last |
t |
= keep |
Þ b-keep-last |
[169]b-strip-last ::= b-ignored-any
[170]b-keep-last ::= b-normalized
Example 4.73. Chomping Final Line Break
strip: |- text
¶ 
clip: | text
¯
keep: |+ text
ß 
Legend:
b-strip-last
b-keep-last
%YAML 1.1
---
!!map {
?!!str "strip" : !!str "text",
?!!str "clip"
:!!str "text\n", ? !!str "keep"
:!!str "text\L",
}
Similarly, empty lines immediately following the block scalar may be interpreted either as presenting trailing line breaks or as (empty) comment lines, depending on the specified chomping indicator.
[171] l-chomped-empty(n,t) ::= t |
= strip |
Þ l-strip-empty(n) |
|
t |
= |
clip |
Þ l-strip-empty(n) |
t |
= |
keep |
Þ l-keep-empty(n) |
[172]l-strip-empty(n) ::= ( s-indent(£n) b-ignored-any )* l-trail-comments(n)?
[173]l-keep-empty(n) ::= l-empty(n,literal)* l-trail-comments(n)?
Explicit comment lines may then follow. To prevent ambiguity, the first such comment line must be less indented than the block scalar content. Additional comment lines, if any, are not so restricted.
[174] l-trail-comments(n) ::= s-indent(<n) c-nb-comment-text b-ignored-any l-comment*
63
XSL• FO
RenderX
