示例#1
0
 private Pile <Reach> splitBraces(Reach formula)
 {
     while (formula.at(1, utl.dmyBool("al(occur, token) is planned"), "(").len > 0)
     {
         Reach part     = braces.upon(formula);
         Reach lastPart = formula;
         while (part.startsWith("("))
         {
             lastPart = part;
             part     = braces.upon(part.from(2));
         }
         if (lastPart.startsWith("("))
         {
             terms.Add(braces.on(lastPart).Trim());
         }
         else
         {
             terms.Add(lastPart.Trim());
         }
         formula = formula.RPW("«" + terms.Len + "»").at(lastPart);
     }
     if (formula.startsWith("("))
     {
         terms.Add(braces.on(formula).Trim());
     }
     else
     {
         terms.Add(formula.Trim());
     }
     return(terms);
 }
示例#2
0
        private Reach extract(Reach source, bool includeTokens)
        {
            Reach ret = source.upto(0) + source.from(source.len + 1); // FromLeftToRight strategy Reach ret = source.from(source.len + 1)

            for (long i = 1; i <= def.Length; i++)
            {
                long k = 1;
                while ((k <= rpt[i - 1]) || ((rpt[i - 1] == 0) && (source.len > 0)))
                {
                    Reach leadIn = source.at(1, utl.dmyBool("al(occur, token) is planned"), def[i - 1].Name);
                    if ((leadIn.len == 0) && (def[i - 1].Name.Length > 0))
                    {
                        return(ret);
                    }
                    if (includeTokens)
                    {
                        if (ret.len == 0)
                        {
                            ret = leadIn;
                        }
                        else
                        {
                            ret = ret + leadIn;
                        }
                    }
                    Reach res     = source.after(leadIn);
                    Reach leadOut = null;
                    int   occur   = 0; // first we try the first closing bracelet, only in case that this will be a non-matching bracelet then wee will try the second, third, fourth etc. closing closing bracelet
                    do
                    {
                        occur++; for (int j = (def[i - 1]).Len; j > 0; j--)
                        {
                            Reach token = res.at(occur, utl.dmyBool("al(occur, token) is planned"), (def[i - 1])[j]); if (token.len > 0)
                            {
                                leadOut = token;
                            }
                        }
                    } while (nested[i - 1] && (res.upto(leadOut).at(-occur, utl.dmyBool("al(occur, token) is planned"), leadIn.text).len > 0));
                    if (leadOut != null)
                    {
                        res = res.before(leadOut);
                    }
                    if (leadOut == null)
                    {
                        return((ret.len == 0) ? res : ret + res);
                    }
                    if (ret.len == 0)
                    {
                        ret = includeTokens ? source.after(leadIn).upto(leadOut) : source.after(leadIn).before(leadOut);
                    }
                    else
                    {
                        ret = includeTokens ? ret + source.after(leadIn).upto(leadOut) : ret + source.after(leadIn).before(leadOut);
                    }
                    source = source.after(leadOut);
                    k++;
                }
            }
            return(ret);
        }
示例#3
0
// ******************* (int pos) //supported: backward index (eInx < 0) where -1 == last Element
        public Operator before(int pos)
        {
            if (Part == null)
            {
                Part = Base;
            }
            return(new Operator(Base, Part.before(pos)));
        }
示例#4
0
//
        public Operator Before(string token)
        {
            if (Part == null)
            {
                Part = Base;
            }
            return(new Operator(Base, Part.Before(1, token)));
        }
示例#5
0
 public Operator After(long occur, string token)
 {
     if (Part == null)
     {
         Part = Base;
     }
     return(new Operator(Base, Part.After(occur, token)));
 }
示例#6
0
 public Operator From(string token)
 {
     if (Part == null)
     {
         Part = Base;
     }
     return(new Operator(Base, Part.From(1, token)));
 }
示例#7
0
 public Operator After(string token)
 {
     if (Part == null)
     {
         Part = Base;
     }
     return(new Operator(Base, Part.After(1, token)));
 }
示例#8
0
 public Operator From(long occur, bool prio, params string[] token)
 {
     if (Part == null)
     {
         Part = Base;
     }
     return(new Operator(Base, Part.From(occur, prio, token)));
 }
示例#9
0
 public Operator upto(Reach other)
 {
     if (Part == null)
     {
         Part = Base;
     }
     return(new Operator(Base, Part.upto(other)));
 }
示例#10
0
 public Operator from(Reach other)
 {
     if (Part == null)
     {
         Part = Base;
     }
     return(new Operator(Base, Part.from(other)));
 }
示例#11
0
 public Operator After(bool prio, params string[] token)
 {
     if (Part == null)
     {
         Part = Base;
     }
     return(new Operator(Base, Part.After(1, prio, token)));
 }
示例#12
0
 public Operator After(bool match, long occur, string chrs)
 {
     if (Part == null)
     {
         Part = Base;
     }
     return(new Operator(Base, Part.After(match, occur, chrs)));
 }
示例#13
0
// ******************* (int occur, String token)
        public Operator Before(long occur, string token)
        {
            if (Part == null)
            {
                Part = Base;
            }
            return(new Operator(Base, Part.Before(occur, token)));
        }
示例#14
0
 public Operator from(int pos)
 {
     if (Part == null)
     {
         Part = Base;
     }
     return(new Operator(Base, Part.from(pos)));
 }
示例#15
0
 public Operator after(int pos)
 {
     if (Part == null)
     {
         Part = Base;
     }
     return(new Operator(Base, Part.after(pos)));
 }
示例#16
0
 public Operator upto(int pos)
 {
     if (Part == null)
     {
         Part = Base;
     }
     return(new Operator(Base, Part.upto(pos)));
 }
示例#17
0
 public Operator after(Reach other)
 {
     if (Part == null)
     {
         Part = Base;
     }
     return(new Operator(Base, Part.after(other)));
 }
示例#18
0
// ******************* (Rch other)
        public Operator before(Reach other)
        {
            if (Part == null)
            {
                Part = Base;
            }
            return(new Operator(Base, Part.before(other)));
        }
示例#19
0
        public Pile <Reach> split(string delim)
        {
            Reach res = this; Pile <Reach> ret = new Pile <Reach>(); while (res.len > 0)

            {
                Reach part = res.before(1, utl.dmyBool("al(occur, token) is planned"), delim); res = res.after(1, utl.dmyBool("al(occur, token) is planned"), delim); ret.Add(part);
            }
            return(ret);
        }
示例#20
0
        private Reach detailled(Reach term)
        {
            string ret = "";

            term = term.Trim();
            while (term.len > 0)
            {
                Reach sign = term.upto(1); sign = sign.upto(true, -1, signCharacters); if (sign.len > 0)
                {
                    sign = term.before(false, 1, signCharacters);
                }
                term = term.after(sign).Trim();
                Reach num = term.upto(true, 1, namesCharacters).Trim();
                if (num.startsWith("«"))
                {
                    num = term.upto(1, utl.dmyBool("al(occur, token) is planned"), "»");
                }
                else
                {
                    if (num.upto(true, -1, numCharacters).len == 0)
                    {
                        num = term.before(false, 1, namesCharacters);
                    }
                    else
                    {
                        num = term.before(false, 1, numCharacters);
                        if (term.after(num).StartsWith("e"))
                        {
                            num = num + term.after(num).upto(1);
                            while (term.after(num).startsWith(true, "+-"))
                            {
                                num = num + term.after(num).upto(1);
                            }
                            num = num + term.after(num).before(false, 1, numCharacters);
                        }
                    }
                    if (num.before(-1, utl.dmyBool("al(occur, token) is planned"), "«").len > 0)
                    {
                        sign = sign + num.before(-1, utl.dmyBool("al(occur, token) is planned"), "«"); term = term.after(sign).Trim(); num = term.upto(1, utl.dmyBool("al(occur, token) is planned"), "»").Trim();
                    }
                }
                term = term.after(num).Trim();
                Reach optor = term.upto(1).upto(true, -1, operatorCharacters);
                term = term.after(optor).Trim();
                ret += "\r\n" + (sign + num).text;
                if (term.len > 0)
                {
                    ret += "\r\n" + optor.text;
                }
                else
                {
                    optor = "";
                }
            }
            return(ret.Substring(2));
        }
示例#21
0
        private void init(Reach expression)
        {
            try { Double.Parse(".1"); } catch (Exception ex) { useComma = true; }
            if (!selfTested)
            {
                selfTest();
            }

            splitFormula(expression);
        }
示例#22
0
 private double parseDouble(Reach term)
 {
     if (term.StartsWith(".e"))
     {
         return(0);
     }
     if (term.endsWith(true, ".,"))
     {
         term = term + new Reach("0");
     }
     return(useComma ? Double.Parse(term.text.Replace(".", ",")) : Double.Parse(term.text.Replace(",", ".")));
 }
示例#23
0
        private static void selfTest()
        {
            selfTested = true;
            Reach r1 = new Reach("ab");
            Reach r2 = new Reach("..X--XX___XX,,XX");
            Reach r3 = new Reach("aa bb  cc ");

            ass(r3.firstWord(" ").equals(""));
            ass(r3.firstWord(" a").equals("aa "));
            ass(r3.lastWord(" ").equals(" "));

            ass(r2.upto(1, false, "X,", "X_", "X-").equals("..X-"));
            ass(r2.upto(2, false, "X,", "X_", "X-").equals("..X--XX_"));
            ass(r2.upto(3, false, "X,", "X_", "X-").equals("..X--XX___XX,"));
            ass(r2.upto(-1, false, "X,", "X_", "X-").equals("..X--XX___XX,"));
            ass(r2.upto(-2, false, "X,", "X_", "X-").equals("..X--XX_"));
            ass(r2.upto(-3, false, "X,", "X_", "X-").equals("..X-"));

            ass(r2.upto(1, false, ",XX", "_XX", "X-", "..").equals(".."));
            ass(r2.upto(2, false, ",XX", "_XX", "X-", "..").equals("..X-"));
            ass(r2.upto(3, false, ",XX", "_XX", "X-", "..").equals("..X--XX___XX"));
            ass(r2.upto(-1, false, ",XX", "_XX", "X-", "..").equals("..X--XX___XX,,XX"));
            ass(r2.upto(-2, false, ",XX", "_XX", "X-", "..").equals("..X--XX___XX"));
            ass(r2.upto(-3, false, ",XX", "_XX", "X-", "..").equals("..X-"));

            ass(r2.from(1, false, "X,", "X_", "X-").equals("X--XX___XX,,XX"));
            ass(r2.from(2, false, "X,", "X_", "X-").equals("X___XX,,XX"));
            ass(r2.from(3, false, "X,", "X_", "X-").equals("X,,XX"));
            ass(r2.from(-1, false, "X,", "X_", "X-").equals("X,,XX"));
            ass(r2.from(-2, false, "X,", "X_", "X-").equals("X___XX,,XX"));
            ass(r2.from(-3, false, "X,", "X_", "X-").equals("X--XX___XX,,XX"));

            ass(r2.from(1, false, ",XX", "_XX", "X-", "..").equals("..X--XX___XX,,XX"));
            ass(r2.from(2, false, ",XX", "_XX", "X-", "..").equals("X--XX___XX,,XX"));
            ass(r2.from(3, false, ",XX", "_XX", "X-", "..").equals("_XX,,XX"));
            ass(r2.from(-1, false, ",XX", "_XX", "X-", "..").equals(",XX"));
            ass(r2.from(-2, false, ",XX", "_XX", "X-", "..").equals("_XX,,XX"));
            ass(r2.from(-3, false, ",XX", "_XX", "X-", "..").equals("X--XX___XX,,XX"));

            ass(r1.upto(1).equals("a")); ass(r1.before(1).equals("")); ass(r1.from(1).equals("ab")); ass(r1.after(1).equals("b")); ass(r1.upto(-1).equals("ab")); ass(r1.before(-1).equals("a")); ass(r1.from(-1).equals("b")); ass(r1.after(-1).equals(""));

            ass(r2.upto(2, true, "XX").equals("..X--XX___XX")); ass(r2.upto(2, true, "X").equals("..X--X")); ass(r2.upto(2, true, "XX", "X").equals("..X--X")); ass(r2.upto(2, true, "X", "XX").equals("..X--X")); ass(r2.upto(-2, true, "XX").equals("..X--XX___XX")); ass(r2.upto(-2, true, "X").equals("..X--XX___XX,,X")); ass(r2.upto(-2, true, "XX", "X").equals("..X--XX___XX,,X")); ass(r2.upto(-2, true, "X", "XX").equals("..X--XX___XX,,X"));
            ass(r2.from(2, true, "XX").equals("XX,,XX")); ass(r2.from(2, true, "X").equals("XX___XX,,XX")); ass(r2.from(2, true, "XX", "X").equals("XX___XX,,XX")); ass(r2.from(2, true, "X", "XX").equals("XX___XX,,XX")); ass(r2.from(-2, true, "XX").equals("XX,,XX")); ass(r2.from(-2, true, "X").equals("XX")); ass(r2.from(-2, true, "XX", "X").equals("XX")); ass(r2.from(-2, true, "X", "XX").equals("XX"));
            ass(r2.before(2, true, "XX").equals("..X--XX___")); ass(r2.before(2, true, "X").equals("..X--")); ass(r2.before(2, true, "XX", "X").equals("..X--")); ass(r2.before(2, true, "X", "XX").equals("..X--")); ass(r2.before(-2, true, "XX").equals("..X--XX___")); ass(r2.before(-2, true, "X").equals("..X--XX___XX,,")); ass(r2.before(-2, true, "XX", "X").equals("..X--XX___XX,,")); ass(r2.before(-2, true, "X", "XX").equals("..X--XX___XX,,"));
            ass(r2.after(2, true, "XX").equals(",,XX")); ass(r2.after(2, true, "X").equals("X___XX,,XX")); ass(r2.after(2, true, "XX", "X").equals("X___XX,,XX")); ass(r2.after(2, true, "X", "XX").equals("X___XX,,XX")); ass(r2.after(-2, true, "XX").equals(",,XX")); ass(r2.after(-2, true, "X").equals("X")); ass(r2.after(-2, true, "XX", "X").equals("X")); ass(r2.after(-2, true, "X", "XX").equals("X"));
            ass(r2.at(2, true, "XX").equals("XX")); ass(r2.at(2, true, "X").equals("X")); ass(r2.at(2, true, "XX", "X").equals("X")); ass(r2.at(2, true, "X", "XX").equals("X")); ass(r2.at(-2, true, "XX").equals("XX")); ass(r2.at(-2, true, "X").equals("X")); ass(r2.at(-2, true, "XX", "X").equals("X")); ass(r2.at(-2, true, "X", "XX").equals("X"));
        }
示例#24
0
        private static void selfTest()
        {
            if ((quotations == null) || (charrays == null) || (bracelets == null) || (brackets == null) || (curlybracks == null) || (quotation == null) || (charray == null) || (bracelet == null) || (bracket == null) || (curlybrack == null))
            {
                return;
            }
            selfTested = true;

            Reach r0 = new Reach("' ', sbj.id, 'ape:', 'birth', ' ', LEFT(CONVERT(VARCHAR(23), sbj.birth, 121), 4) + '-' + LEFT(RIGHT(CONVERT(VARCHAR(23), sbj.birth, 121), 18), 2) + '-' + LEFT(RIGHT(CONVERT(VARCHAR(23), sbj.birth, 121), 15), 2) + ' ' + LEFT(RIGHT(CONVERT(VARCHAR(23), sbj.birth, 121), 12), 2) + ':' + LEFT(RIGHT(CONVERT(VARCHAR(23), sbj.birth, 121), 9), 2) + ':' + LEFT(RIGHT(CONVERT(VARCHAR(23), sbj.birth, 121), 6), 2) + '.' + RIGHT(CONVERT(VARCHAR(23), sbj.birth, 121), 3)");
            Reach r1 = new Reach("a('b')c");
            Reach r2 = new Reach("a('b')c('d')e");
            Reach r3 = new Reach("('field') + ('2')");

            ass(charrays.upon(r1).equals("'b'"));
            ass(bracelets.upon(r1).equals("('b')"));
            ass(charrays.upon(r2).equals("'b''d'"));
            ass(bracelets.upon(r2).equals("('b')('d')"));
            ass(charrays.upon(r0).equals("' ''ape:''birth'' ''-''-'' '':'':''.'"));
            ass(bracelets.upon(r0).equals("(CONVERT(VARCHAR(23), sbj.birth, 121), 4)(RIGHT(CONVERT(VARCHAR(23), sbj.birth, 121), 18), 2)(RIGHT(CONVERT(VARCHAR(23), sbj.birth, 121), 15), 2)(RIGHT(CONVERT(VARCHAR(23), sbj.birth, 121), 12), 2)(RIGHT(CONVERT(VARCHAR(23), sbj.birth, 121), 9), 2)(RIGHT(CONVERT(VARCHAR(23), sbj.birth, 121), 6), 2)(CONVERT(VARCHAR(23), sbj.birth, 121), 3)"));
            ass(charray.upon(r3).equals("'field'"));
            ass(charray.on(r3).equals("field"));
            ass(bracelet.upon(r3).equals("('field')"));
            ass(bracelet.on(r3).equals("'field'"));
        }
示例#25
0
 internal Operator(Reach Base, Reach Part)
 {
     this.Base = Base; this.Part = Part;
 }
示例#26
0
 public Reach after(Reach other)
 {
     Base.upd(); other.upd(); return((pure) ? (bufop) ? (Reach)Base.delafter_(other)              : (Reach)Base.delafter(other)              : (bufop) ? (Reach)Base.delafter_(other, this)              : (Reach)Base.delafter(other, this));
 }
示例#27
0
 internal Operator(Reach Base)
 {
     this.Base = Base; this.Part = Base;
 }
示例#28
0
 public Reach SWAP(Reach txt)
 {
     return(null);
 }
示例#29
0
 public Reach Swap(Reach txt)
 {
     return(null);
 }
示例#30
0
 public Reach swap(Reach txt)
 {
     return(Base.before(Part) + txt + Base.after(Part));
 }