Exemple #1
0
        public ReadSpec GetReadSpec(RCSymbol symbol, int limit, bool force, bool fill)
        {
            ReadSpec result = new ReadSpec(this, limit, force, fill);

            if (limit == 0)
            {
                limit = int.MaxValue;
            }
            for (int i = 0; i < symbol.Count; ++i)
            {
                CountRecord current = Get(symbol[i]);
                if (current != null)
                {
                    // Start searching from the first known record.
                    result.Add(symbol[i], current.start, limit);
                }
                else
                {
                    // In this case we know there is no data so any search should begin
                    // from the end of time.
                    result.Add(symbol[i], _dispatched.Count, limit);
                }
            }
            return(result);
        }
Exemple #2
0
 // This is for page.
 public ReadSpec(ReadCounter counter,
                 RCSymbol left,
                 int skipFirst,
                 int totalLimit,
                 bool
                 showDeleted)
 {
     // For paging.
     _counter = counter;
     _forward = totalLimit >= 0;
     _ignoreDispatchedRows = false;
     _start = 0;
     // each symbol is unlimited individually.  But the total is going to be limited by
     // stopAfter.
     _unlimited   = true;
     _symbolLimit = int.MaxValue;
     _skipFirst   = Math.Abs(skipFirst);
     _totalLimit  = Math.Abs(totalLimit);
     ShowDeleted  = showDeleted;
     left         = _counter.ConcreteSymbols(left, showDeleted);
     for (int i = 0; i < left.Count; ++i)
     {
         Add(left[i], 0, _symbolLimit);
     }
 }
Exemple #3
0
        public ReadSpec GetReadSpec(RCSymbol symbol, RCLong starts, bool force, bool fill)
        {
            ReadSpec result = new ReadSpec(this, 0, force, fill);

            for (int i = 0; i < symbol.Count; ++i)
            {
                result.Add(symbol[i], (int)starts[i], int.MaxValue);
            }
            return(result);
        }
Exemple #4
0
        public RCSymbolScalar GetSymbol(long i)
        {
            RCSymbol val = (RCSymbol)Get(i);

            if (val == null)
            {
                throw new Exception(string.Format("No value at index {0} within block (count:{1})",
                                                  i,
                                                  Count));
            }
            return(val[0]);
        }
Exemple #5
0
        public void EvalParse(RCRunner runner, RCClosure closure, RCSymbol left, RCString right)
        {
            RCParser parser    = null;
            bool     canonical = false;
            string   which     = left[0].Part(0).ToString();

            if (which.Equals("csv"))
            {
                parser = new CSVParser();
            }
            else if (which.Equals("xml"))
            {
                parser = new XMLParser();
            }
            else if (which.Equals("json"))
            {
                parser = new JSONParser();
            }
            else if (which.Equals("rcl"))
            {
                parser = new RCLParser(RCSystem.Activator);
            }
            else if (which.Equals("canonical"))
            {
                parser    = new RCLParser(RCSystem.Activator);
                canonical = true;
            }
            else if (which.Equals("log"))
            {
                parser = new LogParser();
            }
            else if (which.Equals("md"))
            {
                parser = new MarkdownParser();
            }
            else
            {
                throw new Exception("Unknown parser: " + which);
            }
            bool    fragment;
            RCValue result;

            try
            {
                result = DoParse(parser, right, canonical, out fragment);
                runner.Yield(closure, result);
            }
            catch (RCSyntaxException ex)
            {
                throw new RCException(closure, ex, RCErrors.Syntax, ex.Message);
            }
        }
Exemple #6
0
        public RCSymbolScalar GetSymbol(string name, RCSymbolScalar def)
        {
            RCSymbol val = (RCSymbol)Get(name);

            if (val == null)
            {
                return(def);
            }
            else
            {
                return(val[0]);
            }
        }
Exemple #7
0
        public RCSymbolScalar GetSymbol(string name)
        {
            RCSymbol val = (RCSymbol)Get(name);

            if (val == null)
            {
                throw new Exception("Required value " + name + " not found in block");
            }
            else
            {
                return(val[0]);
            }
        }
Exemple #8
0
 public ReadSpec(ReadCounter counter,
                 RCSymbol left,
                 RCLong right,
                 int defaultLimit,
                 bool
                 ignoreDispatchedRows,
                 bool force,
                 bool fill,
                 bool showDeleted)
 {
     _counter              = counter;
     ShowDeleted           = showDeleted;
     _ignoreDispatchedRows = ignoreDispatchedRows;
     _force = force;
     _fill  = fill;
     if (right.Count == 1)
     {
         // It's the start point.
         _forward     = defaultLimit >= 0;
         _unlimited   = defaultLimit == 0;
         _symbolLimit = Math.Abs(_unlimited ? int.MaxValue : defaultLimit);
         left         = _counter.ConcreteSymbols(left, showDeleted);
         for (int i = 0; i < left.Count; ++i)
         {
             Add(left[i], (int)right[0], _symbolLimit);
         }
     }
     else if (right.Count == 2)
     {
         // It's the start point and the limit.
         _forward     = right[1] >= 0;
         _unlimited   = right[1] == 0;
         _symbolLimit = Math.Abs(_unlimited ? int.MaxValue : (int)right[1]);
         left         = _counter.ConcreteSymbols(left, showDeleted);
         for (int i = 0; i < left.Count; ++i)
         {
             Add(left[i], (int)right[0], _symbolLimit);
         }
     }
     else
     {
         // Who knows what this should do.
         // Maybe let you give different counts for each symbol.
         throw new ArgumentException("Read takes a maximum of two right arguments.");
     }
 }
Exemple #9
0
        public static RCClosure Deserialize(RCBlock right)
        {
            long      botId       = right.GetLong("bot");
            long      fiber       = right.GetLong("fiber");
            RCSymbol  locks       = (RCSymbol)right.Get("locks", null);
            RCBlock   parentBlock = (RCBlock)right.GetBlock("parent", null);
            RCClosure parent      = null;

            if (parentBlock != null)
            {
                parent = Deserialize(parentBlock);
            }
            RCValue           code               = right.Get("code");
            RCValue           left               = right.Get("left", null);
            RCBlock           result             = right.GetBlock("result");
            int               index              = (int)right.GetLong("index");
            RCValue           userOp             = right.Get("userOp");
            RCBlock           userOpContextBlock = right.GetBlock("userOpContext", null);
            RCArray <RCBlock> userOpContext      = null;

            if (userOpContextBlock != null)
            {
                userOpContext = new RCArray <RCBlock> ();
                for (int i = 0; i < userOpContextBlock.Count; ++i)
                {
                    userOpContext.Write((RCBlock)userOpContextBlock.Get(i));
                }
            }
            bool noClimb   = right.GetBoolean("noClimb");
            bool noResolve = right.GetBoolean("noResolve");

            return(new RCClosure(botId,
                                 fiber,
                                 locks,
                                 parent,
                                 code,
                                 left,
                                 result,
                                 index,
                                 userOp,
                                 userOpContext,
                                 noClimb,
                                 noResolve));
        }
Exemple #10
0
 public RCClosure(long bot,
                  long fiber,
                  RCSymbol locks,
                  RCClosure parent,
                  RCValue code,
                  RCValue left,
                  RCBlock result,
                  int index,
                  RCValue userOp,
                  RCArray <RCBlock> userOpContext,
                  bool noClimb,
                  bool noResolve)
 {
     if (parent != null)
     {
         Depth = parent.Depth + 1;
     }
     if (code == null)
     {
         throw new Exception("code may not be null.");
     }
     Bot    = bot;
     Fiber  = fiber;
     Locks  = locks;
     Parent = parent;
     Code   = code;
     Left   = left;
     Result = result != null ? result : RCBlock.Empty;
     Index  = index;
     if (userOp != null)
     {
         UserOp = userOp;
     }
     if (userOpContext != null)
     {
         UserOpContext = userOpContext;
     }
     NoClimb = noClimb;
     if (NoClimb)
     {
         Depth = 0;
     }
     NoResolve = noResolve;
 }
Exemple #11
0
        public RCSymbol ConcreteSymbols(RCSymbol symbol, bool showDeleted)
        {
            RCArray <RCSymbolScalar> result = new RCArray <RCSymbolScalar> (8);

            foreach (CountRecord count in _records.Values)
            {
                if (count.deleted && !showDeleted)
                {
                    continue;
                }
                for (int i = 0; i < symbol.Count; ++i)
                {
                    RCSymbolScalar scalar = symbol[i];
                    if (scalar.Key.Equals("'*'") || symbol[i].Key.Equals("*"))
                    {
                        if (count.Concrete && !result.Contains(count.symbol))
                        {
                            if (count.symbol.IsConcreteOf(scalar))
                            {
                                result.Write(count.symbol);
                            }
                            else if (count.symbol.Equals(scalar))
                            {
                                result.Write(count.symbol);
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < symbol.Count; ++i)
            {
                if (!(symbol[i].Key.Equals("'*'") || symbol[i].Key.Equals("*")) &&
                    !result.Contains(symbol[i]))
                {
                    result.Write(symbol[i]);
                }
            }
            return(new RCSymbol(result));
        }
Exemple #12
0
 public RCClosure(RCClosure parent,
                  long bot,
                  RCValue code,
                  RCValue left,
                  RCBlock result,
                  int index,
                  RCValue userOp,
                  RCArray <RCBlock> userOpContext)
 {
     if (parent != null)
     {
         Fiber         = parent.Fiber;
         Locks         = parent.Locks;
         Depth         = parent.Depth + 1;
         UserOp        = parent.UserOp;
         UserOpContext = parent.UserOpContext;
     }
     if (code == null)
     {
         throw new Exception("code may not be null.");
     }
     Bot    = bot;
     Parent = parent;
     Code   = code;
     Left   = left;
     Result = result != null ? result : RCBlock.Empty;
     Index  = index;
     if (userOp != null)
     {
         UserOp = userOp;
     }
     if (userOpContext != null)
     {
         UserOpContext = userOpContext;
     }
 }
Exemple #13
0
        /*
         * protected Type InferType(string[] name, string original)
         * {
         * //Let's try to figure it out!
         * RCValue target = null;
         *
         * //Try the block under construction.
         * if (_block != null)
         * {
         * target = _block.Get(name);
         * }
         *
         * //Try to find it higher up the stack.
         * if (target == null)
         * {
         * RCBlock[] parents = _blocks.ToArray();
         * //When you ToArray the stack items come out in the same order
         * //you would have taken them off the stack.
         * for (int i = 0; i < parents.Length; ++i)
         * {
         * //There will be null blocks on the stack.
         * if (parents[i] != null)
         * {
         * target = parents[i].Get(name);
         * if (target != null) break;
         * }
         * }
         * }
         *
         * if (target == null)
         * {
         * throw new Exception("Unable to infer type for reference " + original + ".");
         * }
         * else return target.Yields;
         * }
         */

        protected RCVectorBase MakeVector(RCArray <RCToken> vector)
        {
            RCVectorBase result = null;

            if (vector[0].Text[0] == '~')
            {
                switch (vector[0].Text[1])
                {
                case 'x': return(RCByte.Empty);

                case 'b': return(RCBoolean.Empty);

                case 'l': return(RCLong.Empty);

                case 'd': return(RCDouble.Empty);

                case 'm': return(RCDecimal.Empty);

                case 's': return(RCString.Empty);

                case 'y': return(RCSymbol.Empty);

                case 't': return(RCTime.Empty);

                case 'n': return(RCIncr.Empty);

                default: throw new Exception("Unrecognized type code: " + vector[0].Text[1]);
                }
            }
            if (vector[0].Type == RCTokenType.Symbol)
            {
                RCArray <RCSymbolScalar> list = new RCArray <RCSymbolScalar> (vector.Count);
                for (int i = 0; i < vector.Count; ++i)
                {
                    list.Write(vector[i].ParseSymbol(_lexer));
                }
                result = new RCSymbol(list);
            }
            else if (vector[0].Type == RCTokenType.String)
            {
                RCArray <string> list = new RCArray <string> (vector.Count);
                for (int i = 0; i < vector.Count; ++i)
                {
                    list.Write(vector[i].ParseString(_lexer));
                }
                result = new RCString(list);
            }
            else if (vector[0].Type == RCTokenType.Boolean)
            {
                RCArray <bool> list = new RCArray <bool> (vector.Count);
                for (int i = 0; i < vector.Count; ++i)
                {
                    list.Write(vector[i].ParseBoolean(_lexer));
                }
                result = new RCBoolean(list);
            }
            else if (vector[0].Type == RCTokenType.Incr)
            {
                RCArray <RCIncrScalar> list = new RCArray <RCIncrScalar> (vector.Count);
                for (int i = 0; i < vector.Count; ++i)
                {
                    list.Write(vector[i].ParseIncr(_lexer));
                }
                result = new RCIncr(list);
            }
            else if (vector[0].Type == RCTokenType.Literal)
            {
                char type = vector[0].Text[1];
                switch (type)
                {
                case 'x':
                    RCArray <byte> list = new RCArray <byte> (vector.Count);
                    for (int i = 0; i < vector.Count; ++i)
                    {
                        list.Write(vector[i].ParseByte(_lexer));
                    }
                    result = new RCByte(list);
                    break;

                default: throw new Exception("Unknown type specifier:" + type);
                }
            }
            else if (vector[0].Type == RCTokenType.Time)
            {
                RCArray <RCTimeScalar> list = new RCArray <RCTimeScalar> (vector.Count);
                for (int i = 0; i < vector.Count; ++i)
                {
                    list.Write(vector[i].ParseTime(_lexer));
                }
                result = new RCTime(list);
            }
            else if (vector[0].Type == RCTokenType.Number)
            {
                // have a look at the last character in the last token
                // if there is a type specifier there we will use it to
                // create the appropriate type of vector.
                RCToken last = vector[vector.Count - 1];
                char    type = last.Text[last.Text.Length - 1];
                if (type == 'l')
                {
                    RCArray <long> list = new RCArray <long> (vector.Count);
                    for (int i = 0; i < vector.Count; ++i)
                    {
                        list.Write(vector[i].ParseLong(_lexer));
                    }
                    result = new RCLong(list);
                }
                if (type == 'd')
                {
                    RCArray <double> list = new RCArray <double> (vector.Count);
                    for (int i = 0; i < vector.Count; ++i)
                    {
                        list.Write(vector[i].ParseDouble(_lexer));
                    }
                    result = new RCDouble(list);
                }
                else if (type == 'm')
                {
                    RCArray <decimal> list = new RCArray <decimal> (vector.Count);
                    for (int i = 0; i < vector.Count; ++i)
                    {
                        list.Write(vector[i].ParseDecimal(_lexer));
                    }
                    result = new RCDecimal(list);
                }
                else // default to double
                {
                    if (vector[0].Text.IndexOf('.') > -1 || vector[0].Text == "NaN")
                    {
                        RCArray <double> list = new RCArray <double> (vector.Count);
                        for (int i = 0; i < vector.Count; ++i)
                        {
                            list.Write(vector[i].ParseDouble(_lexer));
                        }
                        result = new RCDouble(list);
                    }
                    else
                    {
                        RCArray <long> list = new RCArray <long> (vector.Count);
                        for (int i = 0; i < vector.Count; ++i)
                        {
                            list.Write(vector[i].ParseLong(_lexer));
                        }
                        result = new RCLong(list);
                    }
                }
            }
            return(result);
        }
Exemple #14
0
 public void EvalEval(RCRunner runner, RCClosure closure, RCBlock left, RCSymbol right)
 {
     runner.Yield(closure, right);
 }
Exemple #15
0
        public void EvalFormat(RCRunner runner, RCClosure closure, object left, object right)
        {
            // eventually should support xml and json, maybe csv?
            string   which   = "default";
            RCSymbol format  = (RCSymbol)left;
            RCValue  content = (RCValue)right;

            which = format[0].Part(0).ToString();
            string result = null;

            if (which.Equals("default"))
            {
                result = content.Format(RCFormat.Default);
            }
            else if (which.Equals("pretty"))
            {
                result = content.Format(RCFormat.Pretty);
            }
            else if (which.Equals("defaultnot"))
            {
                result = content.Format(RCFormat.DefaultNoT);
            }
            else if (which.Equals("canonical"))
            {
                result = content.Format(RCFormat.Canonical);
            }
            else if (which.Equals("testcanonical"))
            {
                result = content.Format(RCFormat.TestCanonical);
            }
            else if (which.Equals("fragment"))
            {
                result = content.Format(RCFormat.EditorFragment);
            }
            else if (which.Equals("html"))
            {
                // content must be a cube
                result = content.Format(RCFormat.Html);
            }
            else if (which.Equals("csv"))
            {
                // content must be a cube
                result = content.Format(RCFormat.Csv);
            }
            else if (which.Equals("log"))
            {
                // content must be a cube containing expected logging fields
                result = content.Format(RCFormat.Log);
            }
            else if (which.Equals("json"))
            {
                result = content.Format(RCFormat.Json);
            }
            else if (which.Equals("text"))
            {
                result = DoTextFormat(right, Environment.NewLine);
            }
            else if (which.Equals("textcrlf"))
            {
                result = DoTextFormat(right, "\r\n");
            }
            else if (which.Equals("textlf"))
            {
                result = DoTextFormat(right, "\n");
            }
            else
            {
                throw new Exception("Unknown format:" + which);
            }
            runner.Yield(closure, new RCString(result));
        }