Пример #1
0
        public ContractEnforcer(Object obj, string message)
        {
            this.obj = obj;
            if (Runtime.IsPrefixed(message, out type, out name))
            {
                isSetter = type == "set";
            }
            else
            {
                type     = "";
                name     = message;
                isSetter = false;
            }
            OldValue = new Nil();
            switch (type)
            {
            case "get":
            case "set":
                disabled = false;
                break;

            default:
                disabled = true;
                break;
            }
        }
Пример #2
0
        public override Element BuildElement(Element element)
        {
            if (!(element is BlockContainer))
            {
                return(element);
            }

            var newSubs = Nil.L <Element>();

            foreach (Element el in element.Subs)
            {
                if (el is Paragraph p && p.Subs.Any(_ => _ is LineBreak))
                {
                    var lineSubs = Nil.L <Element>();
                    p.Subs.GroupAdjacent(_ => _ is LineBreak).Where(_ => !_.Key).ForEach(_ => {
                        lineSubs.Add(new Paragraph {
                            Subs = _.ToList()
                        });
                    });
                    if (lineSubs.Any())
                    {
                        p.MoveAttributesTo(lineSubs.First());
                    }
                    newSubs = newSubs.Concat(lineSubs).ToList();
                }
Пример #3
0
 public Parser(Scanner s)
 {
     scanner = s;
     nil     = new Nil();
     tr      = new BoolLit(true);
     fa      = new BoolLit(false);
 }
        public string Get(string key)
        {
            lock (SyncLock(key))
            {
                string result;

                var exists = _databaseImpl.Exists(key);
                if (!exists)
                {
                    result = new Nil();
                }
                else
                {
                    var valueInternal = _databaseImpl.Get <object>(key);
                    if (!(valueInternal is string value))
                    {
                        throw new InMemoryDatabaseOperationException(key, $"WRONGTYPE Operation against a key holding the wrong kind of value");
                    }

                    result = value;
                }

                return(result);
            }
        }
Пример #5
0
        //-------------------------------------------------
        #region Overrided Methods Region
        /// <summary>
        /// Warning: Don't use this function for saving this object to the server,
        /// this is just for showing this object in the Design of the Game.
        /// If you want to save this to the server, use this: <see cref="GetForServer()"/>!
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            if (IsNegative)
            {
                return("-" + (-this));
            }

            if (Bil == 0)
            {
                if (Mil == 0)
                {
                    if (Kil == 0)
                    {
                        return(Nil.ToString());
                    }
                    else
                    {
                        return(Kil.ToString() + " K");
                    }
                }
                else
                {
                    return(Mil.ToString() + " M");
                }
            }
            else
            {
                return(Bil.ToString() + " B");
            }
        }
Пример #6
0
        public override void SetVariable(string name, Value value)
        {
            var invariant = invariants[name];

            if (invariant == null)
            {
                base.SetVariable(name, value);
                return;
            }

            Value oldValue = new Nil();

            if (variables.ContainsKey(name))
            {
                oldValue = variables[name];
            }

            base.SetVariable(name, value);
            var arguments = new Arguments();

            arguments.AddArgument(oldValue);
            arguments.AddArgument(value);
            var result = obj.Invoke(invariant, arguments);

            result.IsTrue.Must().BeTrue().OrThrow(LOCATION, () => $"Invariant failed for {name}");
        }
Пример #7
0
 public StrongString GetForServer()
 {
     return(Bil.ToString() + CharSeparater +
            Mil.ToString() + CharSeparater +
            Kil.ToString() + CharSeparater +
            Nil.ToString() + CharSeparater);
 }
        public string Zrank(string key, string member)
        {
            lock (SyncLock(key))
            {
                string result;

                var exists = _databaseImpl.Exists(key);
                if (!exists)
                {
                    result = new Nil();
                }
                else
                {
                    var valueInternal = _databaseImpl.Get <object>(key);
                    if (!(valueInternal is SortedSet sortedSet))
                    {
                        throw new InMemoryDatabaseOperationException(key, $"WRONGTYPE Operation against a key holding the wrong kind of value");
                    }

                    var rank = sortedSet.Rank(member);
                    if (!rank.HasValue)
                    {
                        result = new Nil();
                    }
                    else
                    {
                        result = rank.Value.ToString();
                    }
                }

                return(result);
            }
        }
Пример #9
0
        public void Print_Nil()
        {
            const string expected = "nil";
            var          input    = new Nil();
            var          actual   = Printer.Print(input);

            Assert.Equal(expected, actual);
        }
Пример #10
0
        public Nil ReadNil()
        {
            Nil value = MessagePackBinary.ReadNil(Buffer, Position, out int readSize);

            Position += readSize;

            return(value);
        }
Пример #11
0
    public static void Main()
    {
        var vec1 = new Cons <Z, int>(4, new Nil <int>());

        Console.WriteLine(vec1.First());      // 4
        var vec0 = new Nil <int>();

        Console.WriteLine(vec0.First());      // type error!
    }
        public bool Visit(Nil node)
        {
            if (node.SymType != null)
            {
                return(true);
            }

            node.IsLValue = false;
            node.SymType  = SymbolStack.SymNil;
            return(true);
        }
Пример #13
0
        public StrongString GetForServer()
        {
            var _s = CharSeparater;

            _s +=
                (IsNegative ? NegetiveSerialized :
                 PossitiveSerialized) +
                Bil.ToString() + CharSeparater +
                Mil.ToString() + CharSeparater +
                Kil.ToString() + CharSeparater +
                Nil.ToString() + CharSeparater;;
            return(_s);
        }
Пример #14
0
 public override Element BuildElement(Element element)
 {
     if (element is BlockContainer &&
         element.Subs.Any(_ => _ is Listing l && l.Kind.IsOneOf(ListingKind.Items, ListingKind.CheckItems)))
     {
         var newSubs = Nil.L <Element>();
         element.Subs.ForEach(_ => {
             if (_ is Listing list && list.Kind.IsOneOf(ListingKind.Items, ListingKind.CheckItems))
             {
                 list.Subs.ForEach(item => {
                     newSubs.Add(new Item(item, list.Kind));
                 });
             }
        //parses grammar for exp ->
        public Node parseExp()
        {
            Token tok;

            tok = scanner.getNextToken();
            //checks for end of file
            if (tok == null)
            {
                Nil retNil = nilPoint;
                return(retNil);
            }
            //checks for case of left parenthesis
            if (tok.getType() == TokenType.LPAREN)
            {
                return(parseRest(true));
            }
            //checks for case of false constant
            else if (tok.getType() == TokenType.FALSE)
            {
                BoolLit ret = fBool;
                return(ret);
            }
            //checks for case of true constant
            else if (tok.getType() == TokenType.TRUE)
            {
                BoolLit ret = tBool;
                return(ret);
            }
            //checks for case of QUOTE symbol
            else if (tok.getType() == TokenType.QUOTE)
            {
                return(new Cons(new Ident("quote"), new Cons(parseExp(), new Nil()), true));
            }
            //checks for case int constant
            else if (tok.getType() == TokenType.INT)
            {
                return(new IntLit(tok.getIntVal()));
            }
            //checks for case of string constant
            else if (tok.getType() == TokenType.STRING)
            {
                return(new StringLit(tok.getStringVal()));
            }
            //checks for case of identifier
            else if (tok.getType() == TokenType.IDENT)
            {
                return(new Ident(tok.getName()));
            }

            return(null);
        }
Пример #16
0
 private static object Mplus(object d1, object d2)
 {
     if (Nil.Equals(d1))
     {
         return(d2);
     }
     else if (IsProcedure(d1))
     {
         return(new Func <object>(() => Mplus(d2, Call(d1))));
     }
     else
     {
         return(Cons(Car(d1), Mplus(Cdr(d1), d2)));
     }
 }
Пример #17
0
 public static object Bind(object d, Func <object, object> g)
 {
     if (Nil.Equals(d))
     {
         return(Mzero);
     }
     else if (IsProcedure(d))
     {
         return(new Func <object>(() => Bind(Call(d), g)));
     }
     else
     {
         return(Mplus(g.Call(Car(d)), Bind(Cdr(d), g)));
     }
 }
        //method for parsing rest-> grammar
        protected Node parseRest(bool startsList)
        {
            Token tok;

            tok = scanner.getNextToken();
            if (tok.getType() == TokenType.RPAREN)
            {
                Nil retNil = nilPoint;
                return(retNil);
            }
            else
            {
                return(new Cons(parseExp(tok), parseRest(false), startsList));
            }
            return(null);
        }
Пример #19
0
 public static string Print(IValue expression)
 {
     return(expression switch
     {
         Boolean boolean => boolean.Value ? "#t" : "#f",
         Integer integer => integer.Value.ToString(),
         Float floating => AddDotZeroIfInteger(floating.Value.ToString("G7",
                                                                       CultureInfo.InvariantCulture.NumberFormat)),
         Nil _ => "nil",
         String @string => $"\"{@string.Value}\"",
         Symbol symbol => symbol.Value,
         Function _ => "#<function>",
         Keyword keyword => keyword.Value,
         List list => PrintCollection("(", ")", list),
         Vector vector => PrintCollection("[", "]", vector),
         _ => throw new YungException(
             $"Tried to print a node of type {expression.GetType().Name}, but this action is not implemented.")
     });
Пример #20
0
        public override Verb CreateVerb(string[] tokens)
        {
            Color(position, length, KeyWords);
            var   word = tokens[1].ToLower();
            Value value;

            switch (word)
            {
            case "false":
                value = false;
                break;

            case "true":
                value = true;
                break;

            case "nil":
                value = new Nil();
                break;

            case "any":
                value = new Any();
                break;

            case "null":
                value = new Null();
                break;

            case "none":
                value = new None();
                break;

            case "ignore":
                value = new Ignore();
                break;

            default:
                return(null);
            }
            result.Value = value;
            return(new Push(value));
        }
Пример #21
0
        public static (Lst <ODE> odes, Lst <Equation> eqs) FromCRN(CRN crn)
        {
            (SpeciesValue[] vars, Flow[] flows) = crn.MeanFlow();
            Lst <ODE> odes = new Nil <ODE>();

            for (int i = vars.Length - 1; i >= 0; i--)
            {
                odes = new Cons <ODE>(new ODE(new SpeciesFlow(vars[i].symbol), flows[i]), odes);
            }
            List <SpeciesValue> species = crn.sample.stateMap.species;
            Lst <Equation>      eqs     = new Nil <Equation>();

            for (int i = species.Count - 1; i >= 0; i--)
            {
                eqs = new Cons <Equation>(new Equation(new SpeciesFlow(species[i].symbol), "id", new Lst <Monomial>[1] {
                    Monomial.Singleton(new Monomial(crn.sample.stateMap.state.Mean(i)))
                }), eqs);
            }
            return(odes, eqs);
        }
Пример #22
0
 /// <summary>
 /// Get the string of this Unit, by indecating whether you want it full or not.
 /// <!--This is not an overrided method,
 /// but this is a overloaded method for ToString() method,
 /// so I thought it it'd be better to right it here.-->
 /// </summary>
 /// <param name="fullUnit">
 /// if true, it returns a full mode unit string.
 /// </param>
 /// <returns></returns>
 public string ToString(bool fullUnit)
 {
     if (fullUnit)
     {
         string myString = string.Empty;
         if (Bil != 0)
         {
             myString += Bil.ToString() + FullTosStringSeparater;
             myString += Mil.ToString(FullUnitFormatConvertor) + FullTosStringSeparater;
             myString += Kil.ToString(FullUnitFormatConvertor) + FullTosStringSeparater;
             myString += Nil.ToString(FullUnitFormatConvertor);
         }
         else
         {
             if (Mil != 0)
             {
                 myString += Mil.ToString() + FullTosStringSeparater;
                 myString += Kil.ToString(FullUnitFormatConvertor) + FullTosStringSeparater;
                 myString += Nil.ToString(FullUnitFormatConvertor);
             }
             else
             {
                 if (Kil != 0)
                 {
                     myString += Kil.ToString() + FullTosStringSeparater;
                     myString += Nil.ToString(FullUnitFormatConvertor);
                 }
                 else
                 {
                     myString += Nil.ToString();
                 }
             }
         }
         return(myString);
     }
     else
     {
         return(ToString());
     }
 }
Пример #23
0
 public void Visit(Nil nil)
 {
     _sb.Append("nil");
 }
Пример #24
0
 static Nil()
 {
     Instance = new Nil();
     RegisterSymbol(Instance);
 }
Пример #25
0
 static _()
 {
     nil = new Nil();
 }
Пример #26
0
        public SExp[] CreateExpressions(IEnumerable<LexerToken> tokens)
        {
            IEnumerator<LexerToken> itor = tokens.GetEnumerator();

              // confirm
              if (!itor.MoveNext())
              {
            const string MSG = "Empty S-Expression.";
            throw new ParserException(MSG);
              }

              itor = tokens.GetEnumerator();
              Stack<SExp> stkExp = new Stack<SExp>();
              SExp list = new Nil();
              bool consing = false;

              while (true)
              {
            if (consing)
            {
              SExp exp = null;
              try { exp = stkExp.Pop(); }
              catch
              {
            const string MSG = "Extra close parenthesis.";
            throw new ParserException(MSG);
              }

              if (exp is __LeftParen)
              {
            stkExp.Push(list);
            list = new Nil();
            consing = false;
              }
              else
              {
            list = new Cell(exp, list);
              }
            }
            else
            {
              if (!itor.MoveNext())
              {
            break;
              }
              else if (itor.Current is TokenRightParen)
              {
            consing = true;
              }
              else
              {
            SExp exp = CreateAtom(itor.Current);
            stkExp.Push(exp);
              }
            }

              }

              List<SExp> l = new List<SExp>(stkExp);
              l.Reverse();
              if (l.Exists(exp=>exp is __LeftParen))
              {
            string msg = "Unclosed list detected.";
            throw new ParserException(msg);
              }
              return l.ToArray();
        }
Пример #27
0
 /// <summary>
 ///     Encodes the specified output.
 /// </summary>
 /// <param name="output">The output.</param>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public override int Encode(Stream output, Nil value)
 {
     return(0);
 }
Пример #28
0
        public AstPrinterNode Visit(Nil node)
        {
            var printer = new AstPrinterNode(node.ToString());

            return(printer);
        }
 static Nil()
 {
     single = new Nil <a> ();
 }
Пример #30
0
 public override void Because()
 {
     nilString = Nil<string>.Instance;
     nilElse = Nil<UnitTestBase>.Instance;
 }
Пример #31
0
 public override void CreateVariable(string variableName, bool global = false,
                                     VisibilityType visibility        = VisibilityType.Public, bool _override = false)
 {
     variables[variableName]       = new Nil();
     visibilityTypes[variableName] = visibility;
 }
Пример #32
0
        public override Element BuildElement(Element element)
        {
            { // Headings can't contain other headings & list item headings don't become items.
                if (element is Heading || element is ListItem)
                {
                    return(element);
                }
            }

            Item?   item        = null;
            Heading?lastHeading = null;
            var     subs        = element switch {
                Item i => i.Content,
                    _ => element.Subs
            };
            var newSubs = Nil.L <Element>();

            if (element is Item ii)
            {
                newSubs.Add(ii.Title);
            }

            subs.ForEach(el => {
                var newItem = el is Heading h && h.Level <= (lastHeading?.Level ?? 7);
                if (item == null)
                {
                    if (newItem)
                    {
                        item = Item.FromTitleElement(el);
                    }
                    else
                    {
                        newSubs.Add(el);
                    }
                }
                else
                {
                    if (newItem)
                    {
                        newSubs.Add(item);
                        item = Item.FromTitleElement(el);
                    }
                    else
                    {
                        item.Subs.Add(el);
                    }
                }

                if (newItem)
                {
                    lastHeading = el as Heading;
                }
            });
            if (item != null)
            {
                newSubs.Add(item);
            }

            element.Subs = newSubs;

            return(element);
        }
    }
Пример #33
0
 public override void Encode(JsonWriter output, Nil value)
 {
 }