Esempio n. 1
0
 private bool ReadStringValue(StringReader p, out ExprPiece value)
 {
     string s;
     if (p.AnyQuoted(out s))
     {
         value = new LiteralConst
         {
             Literal = s
         };
         return true;
     }
     value = null;
     return false;
 }
Esempio n. 2
0
 private bool ReadSymbolValue(StringReader p, out ExprPiece value)
 {
     int wordRead;
     if (p.ThisWord(new[] { "null", "true", "false" }, out wordRead))
         switch (wordRead)
         {
             case 0:
                 value = new LiteralConst { Literal = null };
                 return true;
             case 1:
                 value = new LiteralConst { Literal = true };
                 return true;
             case 2:
                 value = new LiteralConst { Literal = false };
                 return true;
         }
     value = null;
     return false;
 }
Esempio n. 3
0
        private bool ReadFloatValue(StringReader p, out ExprPiece value)
        {
            var saved = p.Position;
            p.Skip();
            string f;
            // sinal
            char sig;
            if (p.ThisCharNoSkip("+-", out sig))
                f = sig.ToString();
            else
                f = "";
            bool hasint = false, hasfrac = false, hasexp = false;
            // int part
            string intpart;
            if (p.ThisSetNoSkip("0123456789", out intpart))
            {
                f += intpart;
                hasint = true;
            }
            else
                f += "0";
            var befpt = p.Position;
            // frac part
            if (p.ThisCharNoSkip('.'))
            {
                string fracpart;
                if (p.ThisSetNoSkip("0123456789", out fracpart))
                {
                    f += "." + fracpart;
                    hasfrac = true;
                }
                if (!hasfrac)
                    p.Position = befpt;
            }
            // exp part
            if (hasint || hasfrac)
            {
                var befexp = p.Position;
                if (p.ThisCharNoSkip("eE"))
                {
                    char expsig;
                    if (p.ThisCharNoSkip("+-", out expsig))
                    {
                        string exppart;
                        if (p.ThisSetNoSkip("0123456789", out exppart))
                        {
                            f += "e" + expsig.ToString() + exppart;
                            hasexp = true;
                        }
                    }
                    if (!hasexp)
                        p.Position = befexp;
                }

                var lit = new LiteralConst();
                int ival;
                if (hasfrac)
                {
                    var comma = 1.1.ToString()[1];
                    f = f.Replace('.', comma);
                    lit.Literal = double.Parse(f);
                }
                else if (int.TryParse(f, out ival))
                    lit.Literal = ival;
                else
                    lit.Literal = long.Parse(f);
                value = lit;
                return true;
            }
            p.Position = saved;
            value = null;
            return false;
        }