public DbSlc(Reach smb) { Db db = new Db(new ctx().DbDrivers); init(); DbSlc ret = new DbGrid(smb.before(-1, ".SL")).SLC; smb = smb.after(-1, ".SL"); if (smb.startsWith("D")) { ret = ret.DST; } smb = smb.from(3); while (smb.len > 0) { if (smb.startsWith("DST")) { ret = ret.DST; smb = smb.from(5); continue; } if (smb.startsWith("TOP(")) { ret = ret.TOP(long.Parse(smb.from(5).before(1, ")").text)); smb = smb.after(1, ")").from(2); continue; } if (smb.startsWith("ORD(")) { ret = ret.ORD(smb.from(5).before(1, ")").after(1, "\"").before(1, "\"").text); smb = smb.after(1, ")").from(2); continue; } } this.count = ret.count; this.fields = ret.fields.Clone(); //new Pile<string>(ret.fieldNames); this.from = new KeyPile <string, string>(ret.from); this.join = ret.join.Clone(); //new Pile<Cnd>(ret.join); this.where = ret.where.Clone(); //new Pile<Cnd>(ret.where); this.order = ret.order; }
internal DbIns(Reach smb) { init(); //TBD Db db = new Db(new ctx().DbDrivers); DbIns ret = null; Zone bktFilter = new Zone(new Pile <string>(), new Pile <string>("", true, "(", ")", "||:0")); Zone strFilter = new Zone(new Pile <string>(), new Pile <string>("", true, "\"", "\"", "||:1")); /* * string insstr = "Grid(\"prdrln\").sC(\"sbj, obj, vb, rul, steps, excerpt, trust\").INS(XXXX)"; * insstr = insstr.Replace("XXXX", "Grid(\"prdrln p1, prdvrb pv1, prdrln p2, prdvrb pv2, kndrln sc, itmrln si, prdvrb pv, prdrul pr, itmrln oi, kndrln oc\", cd(\"p1.obj\").EQ(\"p2.sbj\")).sC(\"si.id, oi.id, pv.id, pr.id, 0, '', 0.5\").sR(XXXX).SLD"); * insstr = insstr.Replace("XXXX", "cd(\"0\").EQ(Grid(\"prdrln prdrln\").sC(\"count(*)\").sR(cd(\"sbj\").EQ(\"si.id\"), cd(\"obj\").EQ(\"oi.id\"), cd(\"vb\").EQ(\"pr.vb\")).SLC ), XXXX"); * insstr = bktFilter.on(insstr).text; * insstr = insstr.Replace("XXXX", "cd(\"0\").EQ(Grid(\"prdrln prdrln\").sC(\"count(*)\").sR(cd(\"sbj\").EQ(\"si.id\"), cd(\"obj\").EQ(\"oi.id\"), cd(\"vb\").EQ(\"pr.vb\")).SLC ), XXXX"); */ Reach gridDef = smb - bktFilter.on(smb); Reach ins = gridDef.at(".INS("); if (ins.len == 0) { throw new Exception("DbIns Constructor: invalid symbolic Definition"); } DbGrid res = db.Grid(smb.before(ins)); smb = smb.after(ins).before(-1, ")"); if (smb.startsWith("Grid(")) { ret = res.INS(new DbSlc(smb)); } else { Pile <string> val = new Pile <string>(); while (smb.len > 0) { if (smb.startsWith("ds(")) { val.Push(db.ds(smb.after(1, "\"").before(1, "\""))); smb = smb.after(1, "),").Trim(); } else { val.Push(smb.before(1, ",").Trim()); smb = smb.after(1, ",").Trim(); } } ret = res.INS(val.array()); } into = ret.into; fields = ret.fields.Clone(); //new Pile<string>(ret.fieldNames); values = ret.values; slc = ret.slc; }
internal DbGrid(Reach smb) { init(); Zone bktFilter = new Zone(new Pile <string>(), new Pile <string>("", true, "(", ")", "||:1")); Zone strFilter = new Zone(new Pile <string>(), new Pile <string>("", true, "\"", "\"", "||:1")); if (smb.at(".OR").len > 0) { smb = smb; } //def = new Reach("Grid(\"cpt cpt\").sC(\"id\").sR(cd(\"idnm\").EQ(ds(\"TS\")).OR(cd(\"idnm\").EQ(ds(\"TO\"))).OR(cd(\"idnm\").EQ(ds(\"TO\")))).SLC"); smb = new Reach(smb.text); Reach gridDef = bktFilter.on(smb); Reach tblDef = strFilter.on(gridDef); addTables(tblDef); Reach jCnd = smb.after(tblDef).after(1, ", "); joinCnd.Add(DbCnd.fromSymbolicDef(jCnd)); string testsql = this.SLC.sql(); smb = smb.after(gridDef).from(3); while (smb.len > 0) { if (smb.startsWith("sR(")) { Reach selCnds = bktFilter.on(smb); joinCnd = sR(DbCnd.fromSymbolicDef(selCnds)).joinCnd; selCnd = sR(DbCnd.fromSymbolicDef(selCnds)).selCnd; smb = smb.after(selCnds).from(3); } else if (smb.startsWith("sC(")) { Reach colDef = strFilter.on(bktFilter.on(smb)); fields = sC(colDef).fields; smb = smb.after(colDef).from(4); } else if (smb.startsWith("SL")) { smb = smb.from(4); } } allFields = fields; //addTables(tables); }
public string struc(long indent) { string ret = new string(' ', Math.Max(0, (int)indent)); if (this != root) { ret += def + ctn.before(1, "<"); } string lastType = ""; foreach (Tag t in _tags) { if ((t.type.len == 0) && ((t.def + t.ctn.before(1, "<")).len > 0)) { ret += t.def + t.ctn.before(1, "<"); } else if (t.type.text.ToLower().Equals("/" + lastType)) { ret += t.def; } else { ret += "\n".Substring(0, Math.Min(1, ret.Length)) + t.struc(indent + 1); } lastType = t.type.text.ToLower(); } if (closingTag != null) { if (closingTag != this) { ret += closingTag.def; } else if (!type.Equals("") && !type.Equals("!") && !type.startsWith("/")) { if (!def.at(-2).equals("/")) { ret += "</" + type + ">"; } } } return(ret); }
private void splitparts() { Pile <Reach> res = new Pile <Reach>(); Reach s = parts[1].Trim(); while (s.len > 0) { Reach first = s.At(1, false, ops.array()); if (first.len == 0) { res.Push(s); s = ""; } else { if (s.startsWith(first)) { if (first.Equals("\"")) { res.Push("`dsF`"); res.Push(Zone.quotation.on(s)); res.Push(s.after(res[-1]).Trim()); s = ""; } if (first.Equals("'")) { res.Push("`dsF`"); res.Push(Zone.charray.on(s)); res.Push(s.after(res[-1]).Trim()); s = ""; } if (first.Equals("(")) { res.Push(Zone.bracelet.on(s)); res.Push(s.after(res[-1]).Trim()); s = ""; } if (first.Equals("[")) { res.Push(Zone.bracket.on(s)); res.Push(s.after(res[-1]).Trim()); s = ""; } if (first.Equals("{")) { res.Push(Zone.curlybrack.on(s)); res.Push(s.after(res[-1]).Trim()); s = ""; } if (first.Equals("+")) { res.Push("`cct`"); res.Push(Zone.curlybrack.on(s)); res.Push(s.after(res[-1]).Trim()); s = ""; } if (first.Equals("||")) { res.Push("`cct`"); res.Push(Zone.curlybrack.on(s)); res.Push(s.after(res[-1]).Trim()); s = ""; } if (first.Equals("ltrim(")) { res.Push("`ltr`"); res.Push(Zone.bracelet.on(s)); res.Push(s.after(res[-1]).Trim()); s = ""; } if (first.Equals("rtrim(")) { res.Push("`rtr`"); res.Push(Zone.bracelet.on(s)); res.Push(s.after(res[-1]).Trim()); s = ""; } } else { res.Push("`dF`"); res.Push(s.before(first).Trim()); res.Push(s.from(first).Trim()); s = ""; } } } parts = res; }
private void splitparts() { if (operators == null) { operators = ops.Clone(); foreach (string key in Dtv.Keys) { operators.Push(new Reach(Dtv[key]).before(1, "``")); } } int inx = 1; while (inx <= Len) { Reach rest = null; object lOp = null; object rOp = null; object tOp = null; //if (this[inx].GetType() == typeof(string)) rest = new Reach((string)this[inx]).Trim(); //AttGeTr SEVERE BUGS HERE!! the middle chars of "word" will be detected as Operator "or" ! if (rest == null) { inx++; } else { Reach firstOptorSmb = rest.At(1, false, operators.array()).Trim(); if (firstOptorSmb.At(1, "(").len == 0) { if (operators.Contains((firstOptorSmb + "(").uText)) { if (rest.after(firstOptorSmb).startsWith("(")) { firstOptorSmb = firstOptorSmb + rest.after(firstOptorSmb).upto(1); // both the infix OR and the prefix OR( may be defined as directive } } } String firstOptor = optorForSymbolicOptor(firstOptorSmb.text); if (rest.startsWith(firstOptorSmb)) { } else { } if (firstOptorSmb.len == 0) { Reach fieldVal = new Reach((string)this[inx]).Trim(); this[inx] = new Reach((string)this[inx]); rest = ""; } // this term has no operand, it is a literal like 3 or a Symbol like a DbField Name or a composite field definition else { if (rest.startsWith(firstOptorSmb)) { if (firstOptorSmb.Equals("(")) { this[inx] = new Trm(Zone.bracelet.on(rest).text); optor = ""; rest = rest.after(Zone.bracelet.upon(rest)).Trim(); } else { string newOptor = firstOptorSmb.Trim().text.Replace("(", ""); bool prefix = (firstOptorSmb.at(1, "(").len > 0); if (prefix) { this[inx] = new Trm(Zone.bracelet.on(rest.after(1, optor).Trim()).text); rest = rest.after(Zone.bracelet.upon(rest.after(1, optor))).Trim(); } else { rest = ""; if (optor.Length > 0) { this[1] = new Trm(optor, this[1]); for (int i = 2; i < inx; i++) { ((Trm)this[1]).Push(this[i]); } for (int i = 2; i <= Len - (inx - 2); i++) { this[i] = this[i + (inx - 2)]; } for (int i = 1; i <= (inx - 2); i++) { Del(Len); } inx = 2; } this[inx] = new Trm(rest.after(1, optor).Trim().text); rest = ""; } if ((((Trm)this[inx]).Len == 1 && ((Trm)this[inx]).optor.Length == 0)) { this[inx] = ((Trm)this[inx]).lOpnd; } optor = optorForSymbolicOptor(firstOptorSmb.Trim().text); } } else { if ((Len == 1) && (optor.Length == 0)) { optor = optorForSymbolicOptor(firstOptorSmb.Trim().text); this[inx] = rest.before(firstOptorSmb).Trim(); Push(rest.after(firstOptorSmb).Trim().text); } else { this[inx] = new Trm(optorForSymbolicOptor(firstOptorSmb.Trim().text), new object[] { rest.before(firstOptorSmb).Trim(), rest.after(firstOptorSmb).Trim().text }); } rest = ""; } } if (rest.len > 0) { Push(rest.text); } rest = ""; inx++; } } }
private void init(Reach src, Tag parent, bool xml) { isRelevant = true; type = src.upto(0); //AttGeTr: type was null in new Tag("", false) ctn = src.upto(0); //AttGeTr: ctn was null in some TestCase ... isXmlTag = xml; _tags = new Pile <Tag>(); this.parent = parent; def = src; if (parent == null) { root = this; all = new Pile <Tag>(); int done = 0; while (done < def.len) { all.Add(new Tag(def.after(done), this, xml)); if (all[-1].isWhiteSpace()) { all[-1].isRelevant = false; } if (all.Len == 1) { all[-1].parent = this; } else { if (all[-1].type.startsWith("/")) { for (int i = all.Len - 1; i > 0; i--) { if ((all[-1].type.Equals("/" + all[i].type.text)) && (all[i].closingTag == null)) { all[i].closingTag = all[-1]; all[-1].parent = all[i].parent; break; } } if (all[-1].parent == null) { all[-1].parent = all[-2].parent; // orphaned closing tag } } else { if ((all[-1].type.len == 0) && (!all[-2].type.startsWith("/"))) // new definition: a "plain text tag" may be contained in any tag but may not always be relevant ... { if (!all[-2].mayContain(all[-1].type.text)) { all[-1].isRelevant = false; } if (all[-2].closingTag == null) { all[-1].parent = all[-2]; } else { all[-1].parent = all[-2].parent; } } else { if ((all[-2].mayContain(all[-1].type.text))) { all[-1].parent = all[-2]; } else { all[-1].parent = all[-2].parent; if (all[-2].closingTag == null) { all[-2].closingTag = all[-2]; } } } } } done = done + all[-1]._htm.len; } for (int i = 1; i <= all.Len; i++) { if ((all[i].isRelevant) && (!all[i].type.startsWith("/"))) { all[i].parent._tags.Add(all[i]); } } } else { root = parent.root; if (def.startsWith("<")) { def = def.upto(1, ">"); type = def.after(1).before(-1).before(1, " "); if (type.startsWith("!")) { if (type.startsWith("!--")) { type = type.upto(3); } else { type = type.upto(1); } } if (type.endsWith("/")) { type = type.before(-1); } if (type.Equals("!--")) { closingTag = this; type = type.upto(1); def = root.def.from(def).upto(1, "-->"); ctn = def.after(-1).upto(0); _htm = def; attrib = def.after(type).upto(-2).lTrim().rTrim(); if (attrib.endsWith("/")) { closingTag = this; attrib = attrib.before(-1); } } else { if (type.startsWith("!")) { closingTag = this; type = type.upto(1); } if (type.Equals("script")) { ctn = root.def.from(def).Before(1, "</script"); _htm = ctn.upto(-1); //htm = def + ctn + root.def.after(ctn).upto(1, ">"); attrib = def.after(type).upto(-2).lTrim().rTrim(); if (attrib.endsWith("/")) { closingTag = this; attrib = attrib.before(-1); } } else { ctn = root.def.after(def).upto(0); _htm = def.upto(-1); //_htm = def.plus(ctn); attrib = def.after(type).upto(-2).lTrim().rTrim(); if (attrib.endsWith("/")) { closingTag = this; attrib = attrib.before(-1); } } } } else { closingTag = this; ctn = def.before(1, "<"); type = def.upto(0); def = def.upto(0); attrib = def.upto(0); _htm = ctn.upto(-1); } } }