예제 #1
0
        public virtual string Format(RCFormat args, RCColmap colmap)
        {
            StringBuilder builder = new StringBuilder();

            Format(builder, args, colmap, 0);
            return(builder.ToString());
        }
예제 #2
0
 public override void Format(StringBuilder builder, RCFormat args, RCColmap colmap, int level)
 {
     // There should be some clean way to identify a native value,
     // if just for the purpose of raising an error.
     // This will make it look like an operator to the parser.
     builder.Append(Value.ToString());
 }
예제 #3
0
 public static void DoFormat(RCOperator op,
                             StringBuilder builder,
                             RCFormat args,
                             RCColmap
                             colmap,
                             int level)
 {
     if (op.Left != null)
     {
         if (op.Left.IsOperator)
         {
             builder.Append("(");
             op.Left.Format(builder, args, colmap, level);
             builder.Append(")");
         }
         else
         {
             op.Left.Format(builder, args, colmap, level);
         }
         builder.Append(" ");
     }
     op.BodyToString(builder, args, level);
     builder.Append(" ");
     // Note Right is not allowed to be null.
     op.Right.Format(builder, args, colmap, level);
 }
예제 #4
0
 public static void DoFormat <T> (RCVector <T> vector,
                                  StringBuilder builder,
                                  RCFormat args,
                                  RCColmap colmap,
                                  int level)
 {
     if (vector.Count == 0)
     {
         builder.Append("~");
         builder.Append(vector.TypeCode);
     }
     else
     {
         for (int i = 0; i < vector.Count; ++i)
         {
             vector.ScalarToString(builder, vector[i]);
             if (i < vector.Count - 1)
             {
                 builder.Append(" ");
             }
             else
             {
                 builder.Append(vector.Suffix);
             }
         }
     }
 }
예제 #5
0
 public override void Format(StringBuilder builder,
                             RCFormat args,
                             RCColmap colmap,
                             int level)
 {
     RCL.Kernel.Format.DoFormat(this, builder, args, colmap, level);
 }
예제 #6
0
 public void UpdateColmap(RCArray <string> column, RCArray <string> format)
 {
     lock (_lock)
     {
         _colmap = _colmap.Update(column, format);
     }
 }
예제 #7
0
 public static void DoFormat(RCReference reference,
                             StringBuilder builder,
                             RCFormat args,
                             RCColmap colmap,
                             int level)
 {
     builder.Append("$");
     builder.Append(reference.Name);
 }
예제 #8
0
 public Formatter(StringBuilder builder, RCFormat args, RCColmap colmap, int level)
 {
     _builder = builder;
     _args    = args;
     _level   = level;
     _colmap  = colmap;
     if (_colmap == null)
     {
         _colmap = new RCColmap();
     }
 }
예제 #9
0
        public virtual string Format(RCFormat args)
        {
            StringBuilder builder = new StringBuilder();
            int           level   = 0;
            RCColmap      colmap  = null;

            if (args.UseDisplayCols)
            {
                colmap = RCSystem.Log.GetColmap();
            }
            Format(builder, args, colmap, level);
            return(builder.ToString());
        }
예제 #10
0
        public override void Format(StringBuilder builder, RCFormat args, RCColmap colmap, int level)
        {
            RCFormat format = new RCFormat(args.Syntax,
                                           "  ",
                                           args.Newline,
                                           args.Delimeter,
                                           args.RowDelimeter,
                                           args.Align,
                                           args.Showt,
                                           args.ParsableScalars,
                                           args.CanonicalCubes,
                                           args.Fragment,
                                           args.UseDisplayCols);

            RCL.Kernel.Format.DoFormat(this, builder, format, colmap, level);
        }
예제 #11
0
        public RCColmap Update(RCArray <string> column, RCArray <string> format)
        {
            RCColmap result = new RCColmap();

            result._displayCols = this._displayCols;
            string[] keys = new string[this._displayCols.Count];
            _displayCols.Keys.CopyTo(keys, 0);
            foreach (string key in keys)
            {
                result._displayCols[key] = _displayCols[key];
            }
            _displayCols = new Dictionary <string, DisplayCol> ();
            for (int i = 0; i < column.Count; i++)
            {
                result._displayCols[column[i]] = new DisplayCol(column[i], format[i]);
            }
            return(result);
        }
예제 #12
0
 public abstract void Format(StringBuilder builder, RCFormat args, RCColmap colmap, int level);
예제 #13
0
        public static void DoFormat(RCTemplate template,
                                    StringBuilder builder,
                                    RCFormat args,
                                    RCColmap
                                    colmap,
                                    int level)
        {
            // templates need to follow the same indenting rules as everyone else please.
            builder.Append("[");
            builder.Append('?', template.EscapeCount);
            // Use AppendLine not args.Newline, because the newline is signficant
            //  and needs to be there no matter what.  Otherwise when we parse it again
            ++level;
            if (template.Multiline)
            {
                builder.Append("\n");
                for (int tab = args.Fragment ? 1 : 0; tab < level; ++tab)
                {
                    builder.Append(args.Indent);
                }
            }
            for (int i = 0; i < template.Count - 1; ++i)
            {
                RCValue  child = template.Get(i);
                RCString str   = child as RCString;
                if (str != null && i % 2 == 0)
                {
                    for (int j = 0; j < str.Count; ++j)
                    {
                        // Now go through str one char at a time to find the newlines.
                        int start = 0, end = 0;
                        for (; end < str[j].Length; ++end)
                        {
                            if (str[j][end] == '\n')
                            {
                                string line = str[j].Substring(start, end - start);
                                builder.Append(line);
                                builder.Append("\n");
                                if (i < template.Count - 2 || end < str[j].Length - 1)
                                {
                                    for (int tab = args.Fragment ? 1 : 0; tab < level; ++tab)
                                    {
                                        builder.Append(args.Indent);
                                    }
                                }
                                start = end + 1;
                            }
                            else if (end == str[j].Length - 1)
                            {
                                builder.Append(str[j].Substring(start, 1 + end - start));
                            }
                        }
                    }
                }
                else
                {
                    if (template.Multiline)
                    {
                        // for (int tab = 0; tab < level; ++tab)
                        // {
                        //  builder.Append (args.Indent);
                        // }

                        /*
                         * int k = builder.Length - 1;
                         * while (k >= 0)
                         * {
                         * if (builder[k] == '\n')
                         * {
                         *  for (int tab = 0; tab < level; ++tab)
                         *  {
                         *    builder.Append (args.Indent);
                         *  }
                         *  break;
                         * }
                         * else if (builder[k] != ' ')
                         * {
                         *  break;
                         * }
                         * --k;
                         * }
                         */
                    }
                    builder.Append("[");
                    builder.Append('!', template.EscapeCount);
                    builder.Append(' ');
                    child.Format(builder, RCFormat.Default, colmap, level);
                    builder.Append(' ');
                    builder.Append('!', template.EscapeCount);
                    builder.Append("]");
                }
            }
            --level;
            if (template.Multiline)
            {
                for (int tab = args.Fragment ? 1 : 0; tab < level; ++tab)
                {
                    builder.Append(args.Indent);
                }
            }
            builder.Append('?', template.EscapeCount);
            builder.Append("]");
        }
예제 #14
0
 public static void DoFormat(RCBlock block,
                             StringBuilder builder,
                             RCFormat args,
                             RCColmap
                             colmap,
                             int level)
 {
     if (block.Count == 0)
     {
         if (!args.Fragment)
         {
             builder.Append("{}");
         }
         return;
     }
     if (level > 0 || !args.Fragment)
     {
         builder.Append("{");
         builder.Append(args.Newline);
     }
     ++level;
     // Note the indexer requires a linear search backwards.
     // Maybe a custom iterator is in order?
     // It would also be useful for evaluation and other algorithms.
     for (int i = 0; i < block.Count; ++i)
     {
         RCBlock child = block.GetName(i);
         if (level > 1 || !args.Fragment)
         {
             for (int tab = args.Fragment ? 1 : 0; tab < level; ++tab)
             {
                 builder.Append(args.Indent);
             }
         }
         if (args.Syntax == "JSON")
         {
             builder.AppendFormat("\"{0}\"", child.RawName);
         }
         else if (child.EscapeName)
         {
             builder.Append(child.Name);
         }
         else
         {
             builder.Append(child.Name);
         }
         builder.Append(child.Evaluator.Symbol);
         if (child.Value != null)
         {
             child.Value.Format(builder, args, colmap, level);
         }
         else // Only the empty block has no value.
         {
             builder.Append("{}");
         }
         if (i < block.Count - 1)
         {
             builder.Append(args.RowDelimeter);
         }
     }
     builder.Append(args.Newline);
     --level;
     if (level > 0 || !args.Fragment)
     {
         for (int tab = args.Fragment ? 1 : 0; tab < level; ++tab)
         {
             builder.Append(args.Indent);
         }
         builder.Append("}");
     }
 }