Variable GetFromArray() { SkipCharWS('['); VarDeque kids = new VarDeque(); P6opaque obj = new P6opaque(Kernel.ArrayMO); obj.SetSlot("items", kids); obj.SetSlot("rest", new VarDeque()); bool comma = false; string a_tag = null; if (SkipWhite(true) == '"') { GetString(); comma = true; } if (comma) { if (s_content_type == NONE) { a_tag = s_tag; if (s_anchor != null) { AddAnchor(s_anchor, obj); } } else { kids.Push(GetFromString()); } } while (true) { if (SkipWhite(true) == ']') { break; } if (comma) { SkipChar(','); } kids.Push(GetObj()); comma = true; } SkipCharWS(']'); if (a_tag != null) { Err("Typed arrays are NYI in Niecza Perl 6"); } return(Kernel.NewRWScalar(Kernel.AnyMO, obj)); }
public static Variable BoxLoS(string[] los) { VarDeque items = new VarDeque(); foreach (string i in los) items.Push(Kernel.BoxAnyMO(i, Kernel.StrMO)); P6any l = new P6opaque(Kernel.ListMO); l.SetSlot("rest", new VarDeque()); l.SetSlot("items", items); return Kernel.NewRWListVar(l); }
public static Variable array_constructor(Variable bits) { VarDeque rest = start_iter(bits); VarDeque items = new VarDeque(); while (Kernel.IterHasFlat(rest, true)) items.Push(Kernel.NewMuScalar(rest.Shift().Fetch())); P6any l = new P6opaque(Kernel.ArrayMO); l.SetSlot("rest", rest); l.SetSlot("items", items); return Kernel.NewROScalar(l); }
public static Variable pair(Variable key, Variable value) { P6any l = new P6opaque(Kernel.PairMO); l.SetSlot("key", key); l.SetSlot("value", value); return Kernel.NewROScalar(l); }
Variable GetFromJson(bool top_level) { char look = SkipWhite(true); if (look == '[') { VarDeque q = new VarDeque(); SkipChar('['); while (true) { look = SkipWhite(true); if (look == ']') { break; } if (q.Count() != 0) { SkipChar(','); } q.Push(GetFromJson(false)); } SkipWhite(true); SkipChar(']'); P6any i = new P6opaque(Kernel.ArrayMO); i.SetSlot("items", q); i.SetSlot("rest", new VarDeque()); return(Kernel.NewROScalar(i)); } else if (look == '{') { VarHash q = new VarHash(); int ct = 0; SkipChar('{'); while (true) { look = SkipWhite(true); if (look == '}') { break; } if (ct != 0) { SkipCharWS(','); } ct++; string key = GetJsonString(); SkipWhite(true); SkipChar(':'); q[key] = GetFromJson(false); } SkipWhite(true); SkipChar('}'); return(BoxRW <VarHash>(q, Kernel.HashMO)); } else if (top_level) { Err("Top-level scalar found"); return(null); } else if (look == '"') { return(BoxRW <string>(GetJsonString(), Kernel.StrMO)); } else if (look == 'n') { SkipToken("null"); return(Kernel.NewMuScalar(Kernel.AnyP)); } else if (look == 't') { SkipToken("true"); return(Kernel.NewMuScalar(Kernel.TrueV.Fetch())); } else if (look == 'f') { SkipToken("false"); return(Kernel.NewMuScalar(Kernel.FalseV.Fetch())); } else { double d; string tx = GetJsonNumber(); if (!Utils.S2NB(tx, out d)) { Err("Unparsable number " + tx); } return(BoxRW <double>(d, Kernel.NumMO)); } }
public static P6any MakePair(Variable key, Variable value) { P6any l = new P6opaque(Kernel.PairMO); l.SetSlot(Kernel.EnumMO, "$!key", key); l.SetSlot(Kernel.EnumMO, "$!value", value); return l; }
public static P6any MakeList(VarDeque items, VarDeque rest) { P6any l = new P6opaque(Kernel.ListMO); l.SetSlot(Kernel.ListMO, "$!rest", rest); l.SetSlot(Kernel.ListMO, "$!items", items); return l; }