@@ -29,15 +29,29 @@ abstract const class YamlObj
2929
3030 ** The node's tag. Either a specific tag (e.g. 'tag:yaml.org,2002:str')
3131 ** or the non-specific tag '?'.
32- const Str tag := "?"
32+ Str tag() { tagRef }
33+ internal const Str tagRef
3334
34- ** The node's content. [YamlScalars]`yaml::YamlScalar` always have
35+ ** The node's content value . [YamlScalars]`yaml::YamlScalar` always have
3536 ** content of type 'Str', [YamlLists]`yaml::YamlList` with content
3637 ** type 'YamlObj[]', and [YamlMaps]`yaml::YamlMap` with 'YamlObj:YamlObj'.
37- const Obj content := 0 //the "?" and 0 are placeholders
38+ virtual Obj val() { valRef }
39+ internal const Obj valRef
40+
41+ @Deprecated { msg = "Use val" }
42+ @NoDoc Obj content() { valRef }
3843
3944 ** The text location from which this node was parsed.
40- const FileLoc loc := FileLoc.unknown
45+ FileLoc loc() { locRef }
46+ internal const FileLoc locRef
47+
48+ ** Internal make
49+ internal new make(Obj val, Str tag, FileLoc loc)
50+ {
51+ this .valRef = val
52+ this .tagRef = tag
53+ this .locRef = loc
54+ }
4155
4256//////////////////////////////////////////////////////////////////////////
4357// Public methods
@@ -64,11 +78,11 @@ abstract const class YamlObj
6478 {
6579 this .typeof == that?. typeof &&
6680 this .tag == (that as YamlObj).tag &&
67- this .content == (that as YamlObj).content
81+ this .val == (that as YamlObj).val
6882 }
6983
7084 ** Hash is based on tag and content
71- override Int hash() { 31 * tag.hash + content .hash }
85+ override Int hash() { 31 * tag.hash + val .hash }
7286
7387 ** Returns 'write' written into a string.
7488 override Str toStr()
@@ -97,21 +111,26 @@ const class YamlScalar : YamlObj
97111{
98112 // content : Str
99113
100- ** Creates a YamlScalar with the string 's ' as content,
114+ ** Creates a YamlScalar with the string 'val ' as content,
101115 ** found at location 'loc', with 'tag' as its tag.
102- new make(Str s, Str tag := "?" , FileLoc loc := FileLoc.unknown)
116+ new make(Str val, Str tag := "?" , FileLoc loc := FileLoc.unknown)
117+ : super (val, normTag(tag), loc)
103118 {
104- this .content = s
105- this .loc = loc
119+ }
106120
107- if (tag == "!" ) this .tag = "tag:yaml.org,2002:str"
108- else if (tag != "" ) this .tag = tag
109- else this .tag = "?"
121+ private static Str normTag(Str tag)
122+ {
123+ if (tag == "!" ) return "tag:yaml.org,2002:str"
124+ if (tag != "" ) return tag
125+ return "?"
110126 }
111127
112128 ** Convenience for creating a YamlScalar with an explicit file location but
113129 ** implicit tag.
114- new makeLoc(Str s, FileLoc loc) : this .make(s, "?" , loc) {}
130+ @NoDoc new makeLoc(Str s, FileLoc loc) : this .make(s, "?" , loc) {}
131+
132+ ** Content value as a string
133+ override Str val() { valRef }
115134
116135 override internal Void writeInd(OutStream out, Int first, Int next := first)
117136 {
@@ -121,7 +140,7 @@ const class YamlScalar : YamlObj
121140 // Plain scalar
122141 {
123142 //cover when a plain scalar contains '\n'
124- out.writeChars(Regex("\\ n(?=.)" ).matcher(content ).replaceAll("\n\n " + (" " * next)) + "\n " )
143+ out.writeChars(Regex("\\ n(?=.)" ).matcher(val ).replaceAll("\n\n " + (" " * next)) + "\n " )
125144 }
126145 else
127146 // Non-plain - use quotation marks & escape chars
@@ -131,7 +150,7 @@ const class YamlScalar : YamlObj
131150
132151 out.writeChar('"' )
133152
134- (content as Str ).each |c|
153+ (val as Str ).each |c|
135154 {
136155 // Escape chars
137156 switch (c)
@@ -182,28 +201,30 @@ const class YamlList : YamlObj
182201{
183202 // content : YamlObj[]
184203
185- ** Creates a YamlList with the list 's ' as content,
204+ ** Creates a YamlList with the list 'val ' as content,
186205 ** found at location 'loc', with 'tag' as its tag.
187- new make(YamlObj[] s, Str tag := "!" , FileLoc loc := FileLoc.unknown)
206+ new make(YamlObj[] val, Str tag := "!" , FileLoc loc := FileLoc.unknown)
207+ : super (val, normTag(tag), loc)
188208 {
189- this .content = s
190- this .loc = loc
209+ }
191210
192- if (tag == "!" || tag == "" ) this .tag = "tag:yaml.org,2002:seq"
193- else this .tag = tag
211+ private static Str normTag(Str tag)
212+ {
213+ if (tag == "!" || tag == "" ) return "tag:yaml.org,2002:seq"
214+ return tag
194215 }
195216
196217 ** Convenience for creating a YamlList with an explicit file location but
197218 ** implicit tag.
198- new makeLoc(YamlObj[] s, FileLoc loc) : this .make(s, "!" , loc) {}
219+ @NoDoc new makeLoc(YamlObj[] s, FileLoc loc) : this .make(s, "!" , loc) {}
199220
200- ** Content as a list
201- YamlObj[] list () { content }
221+ ** Content value as a list
222+ override YamlObj[] val () { valRef }
202223
203224 ** Iterate the list items
204225 Void each(|YamlObj| f)
205226 {
206- ((YamlObj[])content ).each(f)
227+ ((YamlObj[])val ).each(f)
207228 }
208229
209230 override internal Void writeInd(OutStream out, Int first, Int next := first)
@@ -215,7 +236,7 @@ const class YamlList : YamlObj
215236 // normal list
216237 else
217238 {
218- contList := content as YamlObj[]
239+ contList := val as YamlObj[]
219240 isEmpty := contList.size == 0
220241 isTagged := tag != "?" && tag != "tag:yaml.org,2002:seq"
221242
@@ -237,7 +258,7 @@ const class YamlList : YamlObj
237258 ** Writes the content as a stream of YAML documents instead of a list
238259 private Void writeStream(OutStream out)
239260 {
240- contList := content as YamlObj[]
261+ contList := val as YamlObj[]
241262
242263 if (contList.size != 0 )
243264 out.writeChars("%YAML 1.2\n " )
@@ -267,27 +288,29 @@ const class YamlMap : YamlObj
267288{
268289 // content : [YamlObj:YamlObj]
269290
270- ** Creates a YamlMap with the map 's ' as content,
291+ ** Creates a YamlMap with the map 'val ' as content,
271292 ** found at location 'loc', with 'tag' as its tag.
272- new make([YamlObj: YamlObj] s, Str tag := "!" , FileLoc loc := FileLoc.unknown)
293+ new make([YamlObj: YamlObj] val, Str tag := "!" , FileLoc loc := FileLoc.unknown)
294+ : super (val, normTag(tag), loc)
273295 {
274- this .content = s
275- this .loc = loc
296+ }
276297
277- if (tag == "!" || tag == "" ) this .tag = "tag:yaml.org,2002:map"
278- else this .tag = tag
298+ private static Str normTag(Str tag)
299+ {
300+ if (tag == "!" || tag == "" ) return "tag:yaml.org,2002:map"
301+ return tag
279302 }
280303
281304 ** Convenience for creating a YamlMap with an explicit file location but
282305 ** implicit tag.
283- new makeLoc([YamlObj: YamlObj] s, FileLoc loc) : this .make(s, "!" , loc) {}
306+ @NoDoc new makeLoc([YamlObj: YamlObj] s, FileLoc loc) : this .make(s, "!" , loc) {}
284307
285- ** Content as a map
286- [YamlObj: YamlObj] map () { content }
308+ ** Content value as a map
309+ override [YamlObj: YamlObj] val () { valRef }
287310
288311 override internal Void writeInd(OutStream out, Int first, Int next := first)
289312 {
290- contMap := content as YamlObj: YamlObj
313+ contMap := val as YamlObj: YamlObj
291314 isEmpty := contMap.keys.size == 0
292315 isTagged := tag != "?" && tag != "tag:yaml.org,2002:map"
293316
@@ -307,14 +330,14 @@ const class YamlMap : YamlObj
307330 kStr := buf.toStr[0 .. - 2 ] //strip ending '\n'
308331
309332 // Key fits on single line
310- if ((k.typeof == YamlScalar# || k.content == YamlObj[,] || k.content == [YamlObj: YamlObj][: ]) &&
333+ if ((k.typeof == YamlScalar# || k.val == YamlObj[,] || k.val == [YamlObj: YamlObj][: ]) &&
311334 ! kStr.containsChar('\n' ) &&
312335 kStr.size <= 1024 )
313336 {
314337 out.writeChars(kStr + ":" )
315338
316339 // Scalar
317- if (v.typeof == YamlScalar# || v.content == YamlObj[,] || v.content == [YamlObj: YamlObj][: ])
340+ if (v.typeof == YamlScalar# || v.val == YamlObj[,] || v.val == [YamlObj: YamlObj][: ])
318341 v.writeInd(out, 1 , next + 1 )
319342 // Non-scalar
320343 else
0 commit comments