This repository has been archived by the owner on Jul 28, 2021. It is now read-only.
forked from kylelemons/go-gypsy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.go
142 lines (140 loc) · 4.83 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright 2013 Google, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Gypsy is a simplified YAML parser written in Go. It is intended to be used as
// a simple configuration file, and as such does not support a lot of the more
// nuanced syntaxes allowed in full-fledged YAML. YAML does not allow indent with
// tabs, and GYPSY does not ever consider a tab to be a space character. It is
// recommended that your editor be configured to convert tabs to spaces when
// editing Gypsy config files.
//
// Gypsy understands the following to be a list:
//
// - one
// - two
// - three
//
// This is parsed as a `yaml.List`, and can be retrieved from the
// `yaml.Node.List()` method. In this case, each element of the `yaml.List` would
// be a `yaml.Scalar` whose value can be retrieved with the `yaml.Scalar.String()`
// method.
//
// Gypsy understands the following to be a mapping:
//
// key: value
// foo: bar
// running: away
//
// A mapping is an unordered list of `key:value` pairs. All whitespace after the
// colon is stripped from the value and is used for alignment purposes during
// export. If the value is not a list or a map, everything after the first
// non-space character until the end of the line is used as the `yaml.Scalar`
// value.
//
// Gypsy allows arbitrary nesting of maps inside lists, lists inside of maps, and
// maps and/or lists nested inside of themselves.
//
// A map inside of a list:
//
// - name: John Smith
// age: 42
// - name: Jane Smith
// age: 45
//
// A list inside of a map:
//
// schools:
// - Meadow Glen
// - Forest Creek
// - Shady Grove
// libraries:
// - Joseph Hollingsworth Memorial
// - Andrew Keriman Memorial
//
// A list of lists:
//
// - - one
// - two
// - three
// - - un
// - deux
// - trois
// - - ichi
// - ni
// - san
//
// A map of maps:
//
// google:
// company: Google, Inc.
// ticker: GOOG
// url: http://google.com/
// yahoo:
// company: Yahoo, Inc.
// ticker: YHOO
// url: http://yahoo.com/
//
// In the case of a map of maps, all sub-keys must be on subsequent lines and
// indented equally. It is allowable for the first key/value to be on the same
// line if there is more than one key/value pair, but this is not recommended.
//
// Values can also be expressed in long form (leading whitespace of the first line
// is removed from it and all subsequent lines). In the normal (baz) case,
// newlines are treated as spaces, all indentation is removed. In the folded case
// (bar), newlines are treated as spaces, except pairs of newlines (e.g. a blank
// line) are treated as a single newline, only the indentation level of the first
// line is removed, and newlines at the end of indented lines are preserved. In
// the verbatim (foo) case, only the indent at the level of the first line is
// stripped. The example:
//
// foo: |
// lorem ipsum dolor
// sit amet
// bar: >
// lorem ipsum
//
// dolor
//
// sit amet
// baz:
// lorem ipsum
// dolor sit amet
//
// The YAML subset understood by Gypsy can be expressed (loosely) in the following
// grammar (not including comments):
//
// OBJECT = MAPPING | SEQUENCE | SCALAR .
// SHORT-OBJECT = SHORT-MAPPING | SHORT-SEQUENCE | SHORT-SCALAR .
// EOL = '\n'
//
// MAPPING = { LONG-MAPPING | SHORT-MAPPING } .
// SEQUENCE = { LONG-SEQUENCE | SHORT-SEQUENCE } .
// SCALAR = { LONG-SCALAR | SHORT-SCALAR } .
//
// LONG-MAPPING = { INDENT KEY ':' OBJECT EOL } .
// SHORT-MAPPING = '{' KEY ':' SHORT-OBJECT { ',' KEY ':' SHORT-OBJECT } '}' EOL .
//
// LONG-SEQUENCE = { INDENT '-' OBJECT EOL } EOL .
// SHORT-SEQUENCE = '[' SHORT-OBJECT { ',' SHORT-OBJECT } ']' EOL .
//
// LONG-SCALAR = ( '|' | '>' | ) EOL { INDENT SHORT-SCALAR EOL }
// SHORT-SCALAR = { alpha | digit | punct | ' ' | '\t' } .
//
// KEY = { alpha | digit }
// INDENT = { ' ' }
//
// Any line where the first non-space character is a sharp sign (#) is a comment.
// It will be ignored.
// Only full-line comments are allowed.
package yaml
// BUG(kevlar): Multi-line strings are currently not supported.