Ejemplo n.º 1
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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
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"));
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
// ******************* (Rch other)
        public Operator before(Reach other)
        {
            if (Part == null)
            {
                Part = Base;
            }
            return(new Operator(Base, Part.before(other)));
        }
Ejemplo n.º 6
0
//

        // a.take(a.before("xx").after(".")).swap("uuuu").Value;
        // a.take(a.before("xx").after(".")).swap("uuuu").Part;

        public Reach swap(string txt)
        {
            return(Base.before(Part) + new Reach(txt) + Base.after(Part));
        }
Ejemplo n.º 7
0
        public static Reach Load(string uri)
        {
            Reach Uri = new Reach(uri);

            uri = Uri.before(1, "///?");
            byte[] post     = new ASCIIEncoding().GetBytes(Uri.after(1, "///?"));
            Uri    location = new Uri(uri);

            if (location.IsFile)
            {
                Reach ret = new Reach(utl.f2s(location.ToString()));
                ret.location = location;
                return(ret);
            }
            else
            {
                HttpWebRequest  req;
                HttpWebResponse resp;
                Encoding        enc;
                req = (HttpWebRequest)WebRequest.Create(location.ToString());
                req.CookieContainer = new CookieContainer();
                req.CookieContainer.Add(Cookies);
                req.Timeout   = 30000; // 30 secs
                req.UserAgent = "Internet Explorer";
                if (post.Length > 0)
                {
                    req.Method        = "POST";
                    req.ContentType   = "application/x-www-form-urlencoded";
                    req.ContentLength = post.Length;
                    req.GetRequestStream().Write(post, 0, post.Length);
                }
                try
                {
                    resp = (HttpWebResponse)req.GetResponse();
                    Cookies.Add(resp.Cookies);

                    Reach ret = null;
                    try
                    {
                        Stream       responseStream = resp.GetResponseStream();
                        Encoding     e      = Encoding.GetEncoding(resp.CharacterSet);
                        StreamReader reader = new StreamReader(responseStream, e);
                        string       s      = reader.ReadToEnd();
                        ret = new Reach(s);
                    }
                    catch
                    {
                        //enc = Encoding.GetEncoding(1252);  // Windows-1252 or iso
                        //enc = Encoding.GetEncoding("unicodeFFFE");  // 1201 = "UTF-16BE" or "unicodeFFFE"
                        enc = Encoding.GetEncoding("unicode"); // 1200 = "UTF-16LE", "utf-16", "ucs-2", "unicode", or "ISO-10646-UCS-2"
                        try { if (resp.ContentEncoding.Length > 0)
                              {
                                  enc = Encoding.GetEncoding(resp.ContentEncoding);
                              }
                        } catch (Exception e) { e.ToString(); }
                        ret = new Reach((new StreamReader(resp.GetResponseStream())).ReadToEnd());
                    }
                    ret.location = location;
                    return(ret);
                }
                catch (Exception e)
                {
                    utl.msg(" ******* CANNOT LOAD DOCUMENT FROM WEB ********" + e.ToString());
                    return(null);
                    //SleepEx(20000, 1); //debug
                }
            }
        }
Ejemplo n.º 8
0
        private string splitAtOperators(string operators, Reach term)
        {
            Reach  newTerm = term.upto(0);
            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();
                if (term.len == 0)
                {
                    optor = optor.upto(0);
                }

                if (optor.upto(true, -1, operators).len > 0)
                {
                    newTerm = newTerm + sign + num + optor;
                }
                else
                {
                    if (newTerm.len > 0)
                    {
                        terms.Add(newTerm + sign + num); newTerm = term.upto(0); ret += "«" + (terms.Len) + "»";
                    }
                    else
                    {
                        ret += (sign + num).text;
                    } if (optor.len > 0)
                    {
                        ret += optor.text;
                    }
                    else
                    {
                        optor = "";
                    }
                }
            }
            return(ret);
        }
Ejemplo n.º 9
0
        private Pile <Reach> splitFormula(Reach formula)
        {
            terms = splitBraces(formula);

            Pile <Reach> Terms        = new Pile <Reach>();
            long         closePending = 0;
            bool         addClose     = false;
            int          termsCount   = terms.Len;

            for (int i = 1; i <= termsCount; i++)
            {
                Reach term = terms[i].Trim();
                Terms.Add(term.upto(0));
                while (term.len > 0)
                {
                    Reach sign = term.upto(1);
                    Reach num  = "";
                    if (sign.equals("'"))
                    {
                        num  = term.from(sign).upto(2, utl.dmyBool("al(occur, token) is planned"), "'");
                        term = term.Trim();
                        sign = sign.upto(0);
                    }
                    else
                    if (sign.equals("["))
                    {
                        num  = term.from(sign).upto(1, utl.dmyBool("al(occur, token) is planned"), "]");
                        term = term.Trim();
                        sign = sign.upto(0);
                    }
                    else
                    {
                        sign = sign.upto(true, -1, signCharacters);
                        if (sign.len > 0)
                        {
                            sign = term.before(false, 1, signCharacters);
                        }
                        term = term.after(sign).Trim();
                        num  = term.upto(true, 1, namesCharacters).Trim();
                    }
                    addClose = false;
                    if (num.startsWith("«"))
                    {
                        num = term.upto(1, utl.dmyBool("al(occur, token) is planned"), "»").Trim();
                    }
                    else if (num.startsWith("["))
                    {
                    }
                    else if (num.startsWith("'"))
                    {
                    }
                    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();
                        }
                        if (closePending > 0)
                        {
                            closePending--; if (closePending == 0)
                            {
                                addClose = true;
                            }
                        }
                    }
                    term = term.after(num).Trim();
                    Reach optor = term.upto(1).upto(true, -1, operatorCharacters);
                    term = term.after(optor).Trim();
                    if (optor.len == 0)
                    {
                        if (term.startsWith(true, numCharacters))
                        {
                            optor = sign;
                            if (optor.len == 0)
                            {
                                optor = optor + "*";
                            }
                            else
                            {
                                optor = "*";                      //if (optor.len == 0) optor = optor + "+"; else optor = "*";
                            }
                            sign         = "(" + sign;
                            closePending = 2;
                        }
                        else
                        {
                            optor = optor + "*";
                        }
                    }
                    if (addClose)
                    {
                        num = num + ")";
                    }
                    Terms[-1] = Terms[-1] + (sign + num);
                    if (term.len > 0)
                    {
                        Terms[-1] = Terms[-1] + new Reach(optor.text); //AttGeTr: if using the same sign reach twice within Term[-1] some following Reach Subtractions will create unexpected results!
                    }
                }
                if (Terms[-1].at(1, utl.dmyBool("al(occur, token) is planned"), "(").len > 0)
                {
                    Terms[-1] = splitBraces(Terms[-1])[-1];
                }
            }
            for (int i = 1; i <= Terms.Len; i++)
            {
                terms[i] = Terms[i];
            }
            terms.Add(terms[termsCount]);

            termsCount = terms.Len;
            for (int i = 1; i <= termsCount; i++)
            {
                terms[i] = splitAtOperators("&", terms[i]);
            }
            terms.Add(terms[termsCount]);

            termsCount = terms.Len;
            for (int i = 1; i <= termsCount; i++)
            {
                terms[i] = splitAtOperators("|^", terms[i]);
            }
            terms.Add(terms[termsCount]);

            termsCount = terms.Len;
            for (int i = 1; i <= termsCount; i++)
            {
                terms[i] = splitAtOperators("><=", terms[i]);
            }
            terms.Add(terms[termsCount]);

            termsCount = terms.Len;
            for (int i = 1; i <= termsCount; i++)
            {
                terms[i] = splitAtOperators("°", terms[i]);
            }
            terms.Add(terms[termsCount]);

            termsCount = terms.Len;

            for (int i = 1; i <= termsCount; i++)
            {
                terms[i] = splitAtOperators("*/%\\", terms[i]);
            }
            terms.Add(terms[termsCount]);

            return(terms);
        }