Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Ben-Kiki O.YAML ain't markup language.V1.1.pdf
Скачиваний:
8
Добавлен:
23.08.2013
Размер:
1.06 Mб
Скачать

 

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

XSLFO

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

XSLFO

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

 

XSLFO

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

XSLFO

RenderX

Соседние файлы в предмете Электротехника