Exemplo n.º 1
0
        //ブロック
        public override bool Visit(UnifiedBlock element, VisitorArgument arg)
        {
            //「いわゆるブロック」と「式のリストの入れ物としてのブロック」があるため、decorationでどちらかを判断する
            var decoration = arg.Decoration;

            //いわゆるブロックの場合 : e.g. while(true){ }の{ }の部分
            if (decoration.MostLeft == "{")
            {
                Writer.WriteLine(decoration.MostLeft);
                arg = arg.IncrementDepth(); //ブロック内部ではインデントを1つ下げる

                //ブロック内部の式を出力
                foreach (var stmt in element)
                {
                    WriteIndent(arg.IndentDepth);
                    if (stmt.TryAccept(this, arg))
                    {
                        Writer.Write(";");
                    }
                    Writer.Write(decoration.EachRight);
                }

                arg = arg.DecrementDepth(); //インデントを元に戻す
                WriteIndent(arg.IndentDepth);
                Writer.Write(decoration.MostRight);
                return(false);
            }

            //式のリストの入れ物としてのブロックの場合 : e.g. return 1,2,3;の1,2,3の部分
            //式の数が0個の場合は何も出力せずに終了
            if (element.Count == 0)
            {
                return(false);
            }

            //式が1つ以上ある場合
            //TODO なぜ括弧を出力するのか確認
            Writer.Write("(");
            var comma = "";

            foreach (var e in element)
            {
                Writer.Write(comma);
                e.TryAccept(this, arg);
                comma = decoration.Delimiter;
            }
            Writer.Write(")");
            return(false);
        }
 public override bool Visit(UnifiedBlock element, VisitorArgument arg)
 {
     if (!string.IsNullOrEmpty(arg.Decoration.MostLeft))
     {
         Writer.WriteLine(arg.Decoration.MostLeft);
         arg = arg.IncrementDepth();
     }
     foreach (var stmt in element)
     {
         WriteIndent(arg);
         if (stmt.TryAccept(this, arg))
         {
             Writer.Write(";");
         }
         Writer.Write(arg.Decoration.EachRight);
     }
     if (!string.IsNullOrEmpty(arg.Decoration.MostRight))
     {
         arg = arg.DecrementDepth();
         WriteIndent(arg);
         Writer.WriteLine(arg.Decoration.MostRight);
     }
     return(false);
 }