Esempio n. 1
0
 public void testBadDefConstruction()
 {
     string[] badDefs = new string[]
     {
         "^@a",
         "^a b",
         "^a\n",
         "^@",
         "a",
         "bcd",
     };
     foreach (string strID in badDefs)
     {
         HDef.make(strID);
     }
 }
 public void testDef()
 {
     Assert.AreEqual(new HDictBuilder().add("def", HDef.make("^a")).toDict().getDef("def").ToString(), "^a");
     Assert.AreEqual(new HDictBuilder().add("def", HDef.make("^a")).toDict().toString(), "{def:^a}");
 }
Esempio n. 3
0
        //////////////////////////////////////////////////////////////////////////
        // Utils
        //////////////////////////////////////////////////////////////////////////

        private HVal parseVal()
        {
            // if it's an id
            if (m_tokCur == HaystackToken.id)
            {
                string id = (string)m_curVal;
                consume(HaystackToken.id);

                // check for coord or xstr
                if (m_tokCur == HaystackToken.lparen)
                {
                    if (m_tokPeek == HaystackToken.num)
                    {
                        return(parseCoord(id));
                    }
                    else
                    {
                        return(parseXStr(id));
                    }
                }

                // check for keyword
                if ("T".CompareTo(id) == 0)
                {
                    return(HBool.TRUE);
                }
                if ("F".CompareTo(id) == 0)
                {
                    return(HBool.FALSE);
                }
                if ("N".CompareTo(id) == 0)
                {
                    return(null);
                }
                if ("M".CompareTo(id) == 0)
                {
                    return(HMarker.VAL);
                }
                if ("NA".CompareTo(id) == 0)
                {
                    return(HNA.VAL);
                }
                if ("R".CompareTo(id) == 0)
                {
                    return(HRemove.VAL);
                }
                if ("NaN".CompareTo(id) == 0)
                {
                    return(HNum.NaN);
                }
                if ("INF".CompareTo(id) == 0)
                {
                    return(HNum.POS_INF);
                }
                if (id.StartsWith("^"))
                {
                    return(HDef.make(id));
                }

                err("Unexpected identifier: " + id);
                return(null); // This is not code that will be executable because of call to err
            }

            // literals
            if (m_tokCur.Literal)
            {
                return(parseLiteral());
            }
            bool bPeekIsINF = false;

            if (m_peekVal is string)
            {
                if (((string)m_peekVal).CompareTo("INF") == 0)
                {
                    bPeekIsINF = true;
                }
            }
            // -INF
            if (m_tokCur == HaystackToken.minus && bPeekIsINF)
            {
                consume(HaystackToken.minus);
                consume(HaystackToken.id);
                return(HNum.NEG_INF);
            }

            // nested collections
            if (m_tokCur == HaystackToken.lbracket)
            {
                return(parseList());
            }
            if (m_tokCur == HaystackToken.lbrace)
            {
                return(parseDict());
            }
            if (m_tokCur == HaystackToken.lt2)
            {
                return(parseGrid());
            }

            err("Unexpected token: " + curToStr());
            return(null); // This is not code that will be executable because of call to err
        }
Esempio n. 4
0
 public void testZinc()
 {
     verifyZinc(HDef.make("^testDef"), "^testDef");
 }
Esempio n. 5
0
 public void testEquality()
 {
     Assert.IsTrue(HDef.make("^foo").hequals(HDef.make("^foo")));
     Assert.IsFalse(HDef.make("^foo").hequals(HDef.make("^Foo")));
 }