Exemplo n.º 1
0
        public virtual void Print(EnumNode node, StringBuilder sb, PrintOption opt, params object[] values)
        {
            sb.Append(opt.MakeIndentSpace());

            sb.AppendFormat("enum {0}\n", node.Name);
            sb.Append(opt.MakeIndentSpace());
            sb.Append("{\n");

            int maxNameLength = 0;

            if (node.Value.Count > 0)
            {
                maxNameLength = node.Value.Select(x => x.Name.Length).Max();
            }


            var subopt = new PrintOption(opt);

            foreach (var n in node.Child)
            {
                n.PrintVisit(this, sb, subopt, maxNameLength);
            }

            sb.Append(opt.MakeIndentSpace());
            sb.Append("}\n");
        }
Exemplo n.º 2
0
        public virtual void Print(FieldNode node, StringBuilder sb, PrintOption opt, params object[] values)
        {
            var maxNameLength = (int)values[0];
            var maxTypeLength = (int)values[1];

            sb.Append(opt.MakeIndentSpace());

            // 类型
            {
                sb.Append(node.CompleteTypeName.PadRight(maxTypeLength + 1));
            }

            // 字段名
            {
                sb.Append(node.Name.PadRight(maxNameLength + 1));
            }


            // 序号
            {
                if (node.Number > 0 && (!node.NumberIsAutoGen || opt.ShowAllFieldNumber))
                {
                    sb.AppendFormat(" = {0} ", node.Number);
                }
            }


            // Option
            if (node.HasOption)
            {
                sb.Append("[");

                if (node.DefaultValue != "")
                {
                    sb.AppendFormat("default:{0}", node.DefaultValue);
                }

                sb.Append("] ");
            }



            // 注释
            if (!string.IsNullOrEmpty(node.TrailingComment))
            {
                sb.AppendFormat("//{0}", node.TrailingComment);
            }

            sb.Append("\n");
        }
Exemplo n.º 3
0
        public virtual void Print(EnumValueNode node, StringBuilder sb, PrintOption opt, params object[] values)
        {
            var maxNameLength = (int)values[0];

            sb.Append(opt.MakeIndentSpace());

            sb.Append(node.Name.PadRight(maxNameLength));

            if ((!node.NumberIsAutoGen || opt.ShowAllEnumNumber))
            {
                sb.AppendFormat(" = {0}", node.Number);
            }

            var commentSpace = " ".PadLeft(Math.Max(3 - node.Number.ToString().Length, 1));

            sb.Append(commentSpace);

            if (!string.IsNullOrEmpty(node.TrailingComment))
            {
                sb.AppendFormat("//{0}", node.TrailingComment);
            }

            sb.Append("\n");
        }
Exemplo n.º 4
0
 public virtual void Print(CommentNode node, StringBuilder sb, PrintOption opt, params object[] values)
 {
     sb.AppendFormat("{0}//{1}\n", opt.MakeIndentSpace(), node.Comment);
 }