...

Text file src/cuelang.org/go/cue/testdata/cycle/issue990.txtar

Documentation: cuelang.org/go/cue/testdata/cycle

     1-- in.cue --
     2// A simple discriminated element
     3#AC: {
     4	k: "simple"
     5	d: #C
     6}
     7
     8// A recursive discriminated element
     9#AS: {
    10	k: "complex"
    11	d: #S
    12}
    13
    14#R: {
    15	a: #AC | #AS
    16}
    17
    18// The structure of the recursive element
    19#S: {
    20	n: string
    21	r: [string]: #R
    22}
    23
    24// The structure of the simple element
    25#C: {
    26	n: string
    27}
    28
    29#sub: {
    30	$p=#p: #AS
    31	dict: [string]: _
    32
    33	for rn, rd in $p.d.r if rd.a.k == "complex" {
    34		let subs = #sub & {#p: rd.a}
    35		for sn, sd in subs.dict {
    36			dict: "\(rn)_\(sn)": sd
    37		}
    38	}
    39	for rn, rd in $p.d.r if rd.a.k == "simple" {
    40		dict: "\(rn)": rd
    41	}
    42}
    43
    44// Data
    45_test: {
    46	c1: #AC
    47	c1: d: {
    48		n: "c1"
    49	}
    50
    51
    52	s3: #AS
    53	s3: d: {
    54		n: "s3"
    55		r: r1: a:c1
    56	}
    57
    58	s2: #AS
    59	s2: d: {
    60		n: "s2"
    61		r: {
    62			r1: a: c1
    63			r2: a: s3
    64		}
    65	}
    66
    67	s1: #AS
    68	s1: d: {
    69		n: "s1"
    70		r: {
    71			r1: a: c1
    72			r2: a: s2
    73		}
    74	}
    75}
    76
    77//  Test
    78
    79out: #sub & {#p: _test.s1}
    80-- out/compile --
    81--- in.cue
    82{
    83  #AC: {
    84    k: "simple"
    85    d: 〈1;#C〉
    86  }
    87  #AS: {
    88    k: "complex"
    89    d: 〈1;#S〉
    90  }
    91  #R: {
    92    a: (〈1;#AC〉|〈1;#AS〉)
    93  }
    94  #S: {
    95    n: string
    96    r: {
    97      [string]: 〈2;#R〉
    98    }
    99  }
   100  #C: {
   101    n: string
   102  }
   103  #sub: {
   104    #p: 〈1;#AS〉
   105    dict: {
   106      [string]: _
   107    }
   108    for rn, rd in 〈0;#p〉.d.r if (〈0;rd〉.a.k == "complex") {
   109      let subs#1multi = (〈3;#sub〉 & {
   110        #p: 〈2;rd〉.a
   111      })
   112      for sn, sd in 〈0;let subs#1〉.dict {
   113        dict: {
   114          "\(〈4;rn〉)_\(〈2;sn〉)": 〈2;sd〉
   115        }
   116      }
   117    }
   118    for rn, rd in 〈0;#p〉.d.r if (〈0;rd〉.a.k == "simple") {
   119      dict: {
   120        "\(〈2;rn〉)": 〈2;rd〉
   121      }
   122    }
   123  }
   124  _test: {
   125    c1: 〈1;#AC〉
   126    c1: {
   127      d: {
   128        n: "c1"
   129      }
   130    }
   131    s3: 〈1;#AS〉
   132    s3: {
   133      d: {
   134        n: "s3"
   135        r: {
   136          r1: {
   137            a: 〈4;c1〉
   138          }
   139        }
   140      }
   141    }
   142    s2: 〈1;#AS〉
   143    s2: {
   144      d: {
   145        n: "s2"
   146        r: {
   147          r1: {
   148            a: 〈4;c1〉
   149          }
   150          r2: {
   151            a: 〈4;s3〉
   152          }
   153        }
   154      }
   155    }
   156    s1: 〈1;#AS〉
   157    s1: {
   158      d: {
   159        n: "s1"
   160        r: {
   161          r1: {
   162            a: 〈4;c1〉
   163          }
   164          r2: {
   165            a: 〈4;s2〉
   166          }
   167        }
   168      }
   169    }
   170  }
   171  out: (〈0;#sub〉 & {
   172    #p: 〈1;_test〉.s1
   173  })
   174}
   175-- out/eval/stats --
   176Leaks:  6
   177Freed:  3232
   178Reused: 3213
   179Allocs: 25
   180Retain: 26
   181
   182Unifications: 2588
   183Conjuncts:    12056
   184Disjuncts:    3258
   185-- out/eval --
   186(struct){
   187  #AC: (#struct){
   188    k: (string){ "simple" }
   189    d: (#struct){
   190      n: (string){ string }
   191    }
   192  }
   193  #AS: (#struct){
   194    k: (string){ "complex" }
   195    d: (#struct){
   196      n: (string){ string }
   197      r: (#struct){
   198      }
   199    }
   200  }
   201  #R: (#struct){
   202    a: (#struct){ |((#struct){
   203        k: (string){ "simple" }
   204        d: (#struct){
   205          n: (string){ string }
   206        }
   207      }, (#struct){
   208        k: (string){ "complex" }
   209        d: (#struct){
   210          n: (string){ string }
   211          r: (#struct){
   212          }
   213        }
   214      }) }
   215  }
   216  #S: (#struct){
   217    n: (string){ string }
   218    r: (#struct){
   219    }
   220  }
   221  #C: (#struct){
   222    n: (string){ string }
   223  }
   224  #sub: (#struct){
   225    #p: (#struct){
   226      k: (string){ "complex" }
   227      d: (#struct){
   228        n: (string){ string }
   229        r: (#struct){
   230        }
   231      }
   232    }
   233    dict: (#struct){
   234    }
   235    let subs#1multi = (〈3;#sub〉 & {
   236      #p: 〈2;rd〉.a
   237    })
   238  }
   239  _test: (struct){
   240    c1: (#struct){
   241      k: (string){ "simple" }
   242      d: (#struct){
   243        n: (string){ "c1" }
   244      }
   245    }
   246    s3: (#struct){
   247      k: (string){ "complex" }
   248      d: (#struct){
   249        n: (string){ "s3" }
   250        r: (#struct){
   251          r1: (#struct){
   252            a: (#struct){
   253              k: (string){ "simple" }
   254              d: (#struct){
   255                n: (string){ "c1" }
   256              }
   257            }
   258          }
   259        }
   260      }
   261    }
   262    s2: (#struct){
   263      k: (string){ "complex" }
   264      d: (#struct){
   265        n: (string){ "s2" }
   266        r: (#struct){
   267          r1: (#struct){
   268            a: (#struct){
   269              k: (string){ "simple" }
   270              d: (#struct){
   271                n: (string){ "c1" }
   272              }
   273            }
   274          }
   275          r2: (#struct){
   276            a: (#struct){
   277              k: (string){ "complex" }
   278              d: (#struct){
   279                n: (string){ "s3" }
   280                r: (#struct){
   281                  r1: (#struct){
   282                    a: (#struct){
   283                      k: (string){ "simple" }
   284                      d: (#struct){
   285                        n: (string){ "c1" }
   286                      }
   287                    }
   288                  }
   289                }
   290              }
   291            }
   292          }
   293        }
   294      }
   295    }
   296    s1: (#struct){
   297      k: (string){ "complex" }
   298      d: (#struct){
   299        n: (string){ "s1" }
   300        r: (#struct){
   301          r1: (#struct){
   302            a: (#struct){
   303              k: (string){ "simple" }
   304              d: (#struct){
   305                n: (string){ "c1" }
   306              }
   307            }
   308          }
   309          r2: (#struct){
   310            a: (#struct){
   311              k: (string){ "complex" }
   312              d: (#struct){
   313                n: (string){ "s2" }
   314                r: (#struct){
   315                  r1: (#struct){
   316                    a: (#struct){
   317                      k: (string){ "simple" }
   318                      d: (#struct){
   319                        n: (string){ "c1" }
   320                      }
   321                    }
   322                  }
   323                  r2: (#struct){
   324                    a: (#struct){
   325                      k: (string){ "complex" }
   326                      d: (#struct){
   327                        n: (string){ "s3" }
   328                        r: (#struct){
   329                          r1: (#struct){
   330                            a: (#struct){
   331                              k: (string){ "simple" }
   332                              d: (#struct){
   333                                n: (string){ "c1" }
   334                              }
   335                            }
   336                          }
   337                        }
   338                      }
   339                    }
   340                  }
   341                }
   342              }
   343            }
   344          }
   345        }
   346      }
   347    }
   348  }
   349  out: (#struct){
   350    #p: (#struct){
   351      k: (string){ "complex" }
   352      d: (#struct){
   353        n: (string){ "s1" }
   354        r: (#struct){
   355          r1: (#struct){
   356            a: (#struct){
   357              k: (string){ "simple" }
   358              d: (#struct){
   359                n: (string){ "c1" }
   360              }
   361            }
   362          }
   363          r2: (#struct){
   364            a: (#struct){
   365              k: (string){ "complex" }
   366              d: (#struct){
   367                n: (string){ "s2" }
   368                r: (#struct){
   369                  r1: (#struct){
   370                    a: (#struct){
   371                      k: (string){ "simple" }
   372                      d: (#struct){
   373                        n: (string){ "c1" }
   374                      }
   375                    }
   376                  }
   377                  r2: (#struct){
   378                    a: (#struct){
   379                      k: (string){ "complex" }
   380                      d: (#struct){
   381                        n: (string){ "s3" }
   382                        r: (#struct){
   383                          r1: (#struct){
   384                            a: (#struct){
   385                              k: (string){ "simple" }
   386                              d: (#struct){
   387                                n: (string){ "c1" }
   388                              }
   389                            }
   390                          }
   391                        }
   392                      }
   393                    }
   394                  }
   395                }
   396              }
   397            }
   398          }
   399        }
   400      }
   401    }
   402    dict: (#struct){
   403      r1: (#struct){
   404        a: (#struct){
   405          k: (string){ "simple" }
   406          d: (#struct){
   407            n: (string){ "c1" }
   408          }
   409        }
   410      }
   411      r2_r1: (#struct){
   412        a: (#struct){
   413          k: (string){ "simple" }
   414          d: (#struct){
   415            n: (string){ "c1" }
   416          }
   417        }
   418      }
   419      r2_r2_r1: (#struct){
   420        a: (#struct){
   421          k: (string){ "simple" }
   422          d: (#struct){
   423            n: (string){ "c1" }
   424          }
   425        }
   426      }
   427    }
   428    let subs#1multi = (〈3;#sub〉 & {
   429      #p: 〈2;rd〉.a
   430    })
   431  }
   432}

View as plain text