Пример #1
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());
 }
Пример #2
0
        public virtual string Format(RCFormat args, RCColmap colmap)
        {
            StringBuilder builder = new StringBuilder();

            Format(builder, args, colmap, 0);
            return(builder.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 static void DoFormat(RCReference reference,
                             StringBuilder builder,
                             RCFormat args,
                             RCColmap colmap,
                             int level)
 {
     builder.Append("$");
     builder.Append(reference.Name);
 }
Пример #7
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();
     }
 }
Пример #8
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());
        }
Пример #9
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);
        }
Пример #10
0
 public virtual void BodyToString(StringBuilder builder, RCFormat args, int level)
 {
     builder.Append(Name);
 }
Пример #11
0
 public override void BodyToString(StringBuilder builder, RCFormat args, int level)
 {
     _code.Format(builder, args, level);
 }
Пример #12
0
 public abstract void Format(StringBuilder builder, RCFormat args, RCColmap colmap, int level);
Пример #13
0
        static RCFormat()
        {
            // Single line format.
            Default = new RCFormat("RCL",
                                   "",
                                   "",
                                   " ",
                                   " ",
                                   align: false,
                                   showt: true,
                                   parsableScalars: true,
                                   canonicalCubes: true,
                                   fragment: false,
                                   useDisplayCols: false);

            // Multiline format.
            Pretty = new RCFormat("RCL",
                                  "  ",
                                  "\n",
                                  " ",
                                  "\n",
                                  align: true,
                                  showt: true,
                                  parsableScalars: true,
                                  canonicalCubes: true,
                                  fragment: false,
                                  useDisplayCols: true);

            // RCL fragment sourced from an editor.
            // Uses canonical cubes for accurate editing.
            EditorFragment = new RCFormat("RCL",
                                          "  ",
                                          "\n",
                                          " ",
                                          "\n",
                                          align: true,
                                          showt: true,
                                          parsableScalars: true,
                                          canonicalCubes: true,
                                          fragment: true,
                                          useDisplayCols: false);

            // Purist multiline format. Similar to pretty format but doesn't incorporate display
            // cols.
            Canonical = new RCFormat("RCL",
                                     "  ",
                                     "\n",
                                     " ",
                                     "\n",
                                     align: true,
                                     showt: true,
                                     parsableScalars: true,
                                     canonicalCubes: true,
                                     fragment: false,
                                     useDisplayCols: false);

            // Use for tests that do not want to specify G, E and T cols.
            DefaultNoT = new RCFormat("RCL",
                                      "",
                                      "",
                                      " ",
                                      " ",
                                      align: false,
                                      showt: false,
                                      parsableScalars: true,
                                      canonicalCubes: true,
                                      fragment: false,
                                      useDisplayCols: false);

            // Use for test cases involving canonical cubes.
            TestCanonical = new RCFormat("RCL",
                                         "",
                                         "",
                                         " ",
                                         " ",
                                         align: false,
                                         showt: true,
                                         parsableScalars: true,
                                         canonicalCubes: true,
                                         fragment: false,
                                         useDisplayCols: false);

            // Translate rcl values to JSON.
            Json = new RCFormat("JSON",
                                "  ",
                                "\n",
                                " ",
                                ",\n",
                                align: true,
                                showt: true,
                                parsableScalars: false,
                                canonicalCubes: true,
                                fragment: false,
                                useDisplayCols: false);

            // Translate rcl cubes to html tables.
            Html = new RCFormat("HTML",
                                "  ",
                                "\n",
                                " ",
                                "\n",
                                align: true,
                                showt: true,
                                parsableScalars: true,
                                canonicalCubes: true,
                                fragment: false,
                                useDisplayCols: false);

            // Translate rcl cubes to csv format.
            Csv = new RCFormat("CSV",
                               "  ",
                               "\n",
                               ",",
                               "\n",
                               align: false,
                               showt: true,
                               parsableScalars: false,
                               canonicalCubes: true,
                               fragment: false,
                               useDisplayCols: false);

            // Translate an appropriate cube to rcl log format.
            Log = new RCFormat("LOG",
                               "  ",
                               "\n",
                               " ",
                               "\n",
                               align: false,
                               showt: true,
                               parsableScalars: false,
                               canonicalCubes: true,
                               fragment: false,
                               useDisplayCols: false);
        }
Пример #14
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("]");
        }
Пример #15
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("}");
     }
 }