github.com/joomcode/cue@v0.4.4-0.20221111115225-539fe3512047/cue/testdata/references/labels.txtar (about) 1 -- in.cue -- 2 // Label aliases 3 4 // direct 5 a: [X=string]: X 6 a: bar: _ 7 8 // in struct 9 b: [X=string]: {X} 10 b: bar: _ 11 12 // in structs 13 c: [X=string]: X 14 c: [Y=string]: {{{Y}}} 15 c: bar: _ 16 17 // in sub field 18 d: [X=string]: name: X 19 d: bar: {} 20 21 // nested 22 e: [X=string]: [Y=string]: X + Y 23 e: foo: bar: _ 24 25 // Field aliases 26 27 bar: 3 28 f1: C="foo\(bar)": { 29 name: "xx" 30 foo: C.name 31 } 32 33 // nested 34 f1: D="foo\(bar)": E="foo\(bar)baz": { 35 name: "xx" 36 a: D["foo\(bar)baz"].name 37 b: E.name 38 } 39 40 // Combo 41 42 c1: C="foo\(bar)": [D=string]: { 43 name: D 44 foo: C.x.name 45 } 46 c1: foo3: x: _ 47 48 emptyLabel: { 49 "": 1 50 a: emptyLabel[""] 51 } 52 53 underscore: a: { 54 // Issue #1454 55 foo: #Foo 56 foo: "_": "bar" 57 #Foo: [=~""]: string 58 } 59 60 underscore: c: { 61 foo: "_": "any" 62 foo: [=~""]: string 63 } 64 65 underscore: d: { 66 bar: "_": "any" 67 #bar: [string]: string 68 bar: #bar 69 } 70 71 underscore: e: { 72 baz: "_h": "any" 73 #baz: [=~"_"]: string 74 baz: #baz 75 } 76 77 // TODO: support. Also not yet supported in old implementation. 78 // c10: { 79 // C=[string]: { 80 // name: "x" 81 // foo: C.name 82 // } 83 // } 84 // c2: c1 & { x: _ } 85 -- out/eval -- 86 (struct){ 87 a: (struct){ 88 bar: (string){ "bar" } 89 } 90 b: (struct){ 91 bar: (string){ "bar" } 92 } 93 c: (struct){ 94 bar: (string){ "bar" } 95 } 96 d: (struct){ 97 bar: (struct){ 98 name: (string){ "bar" } 99 } 100 } 101 e: (struct){ 102 foo: (struct){ 103 bar: (string){ "foobar" } 104 } 105 } 106 bar: (int){ 3 } 107 f1: (struct){ 108 foo3: (struct){ 109 name: (string){ "xx" } 110 foo: (string){ "xx" } 111 foo3baz: (struct){ 112 name: (string){ "xx" } 113 a: (string){ "xx" } 114 b: (string){ "xx" } 115 } 116 } 117 } 118 c1: (struct){ 119 foo3: (struct){ 120 x: (struct){ 121 name: (string){ "x" } 122 foo: (string){ "x" } 123 } 124 } 125 } 126 emptyLabel: (struct){ 127 "": (int){ 1 } 128 a: (int){ 1 } 129 } 130 underscore: (struct){ 131 a: (struct){ 132 foo: (#struct){ 133 "_": (string){ "bar" } 134 } 135 #Foo: (#struct){ 136 } 137 } 138 c: (struct){ 139 foo: (struct){ 140 "_": (string){ "any" } 141 } 142 } 143 d: (struct){ 144 bar: (#struct){ 145 "_": (string){ "any" } 146 } 147 #bar: (#struct){ 148 } 149 } 150 e: (struct){ 151 baz: (#struct){ 152 "_h": (string){ "any" } 153 } 154 #baz: (#struct){ 155 } 156 } 157 } 158 } 159 -- out/compile -- 160 --- in.cue 161 { 162 a: { 163 [string]: 〈0;-〉 164 } 165 a: { 166 bar: _ 167 } 168 b: { 169 [string]: { 170 〈1;-〉 171 } 172 } 173 b: { 174 bar: _ 175 } 176 c: { 177 [string]: 〈0;-〉 178 } 179 c: { 180 [string]: { 181 { 182 { 183 〈3;-〉 184 } 185 } 186 } 187 } 188 c: { 189 bar: _ 190 } 191 d: { 192 [string]: { 193 name: 〈1;-〉 194 } 195 } 196 d: { 197 bar: {} 198 } 199 e: { 200 [string]: { 201 [string]: (〈1;-〉 + 〈0;-〉) 202 } 203 } 204 e: { 205 foo: { 206 bar: _ 207 } 208 } 209 bar: 3 210 f1: { 211 "foo\(〈1;bar〉)": { 212 name: "xx" 213 foo: 〈1;("foo\(〈1;bar〉)")〉.name 214 } 215 } 216 f1: { 217 "foo\(〈1;bar〉)": { 218 "foo\(〈2;bar〉)baz": { 219 name: "xx" 220 a: 〈2;("foo\(〈1;bar〉)")〉["foo\(〈3;bar〉)baz"].name 221 b: 〈1;("foo\(〈2;bar〉)baz")〉.name 222 } 223 } 224 } 225 c1: { 226 "foo\(〈1;bar〉)": { 227 [string]: { 228 name: 〈1;-〉 229 foo: 〈2;("foo\(〈1;bar〉)")〉.x.name 230 } 231 } 232 } 233 c1: { 234 foo3: { 235 x: _ 236 } 237 } 238 emptyLabel: { 239 "": 1 240 a: 〈1;emptyLabel〉[""] 241 } 242 underscore: { 243 a: { 244 foo: 〈0;#Foo〉 245 foo: { 246 "_": "bar" 247 } 248 #Foo: { 249 [=~""]: string 250 } 251 } 252 } 253 underscore: { 254 c: { 255 foo: { 256 "_": "any" 257 } 258 foo: { 259 [=~""]: string 260 } 261 } 262 } 263 underscore: { 264 d: { 265 bar: { 266 "_": "any" 267 } 268 #bar: { 269 [string]: string 270 } 271 bar: 〈0;#bar〉 272 } 273 } 274 underscore: { 275 e: { 276 baz: { 277 "_h": "any" 278 } 279 #baz: { 280 [=~"_"]: string 281 } 282 baz: 〈0;#baz〉 283 } 284 } 285 }