private DecrementDepth ( ) : |
||
Résultat |
// ブロック(UnifiedBlock) 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.Write(arg.Decoration.MostRight); } return false; }
public override bool Visit(UnifiedBlock element, VisitorArgument arg) { // Write '{' which can be abbreviated 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); } // Write '}' which can be abbreviated if (!string.IsNullOrEmpty(arg.Decoration.MostRight)) { arg = arg.DecrementDepth(); WriteIndent(arg); Writer.WriteLine(arg.Decoration.MostRight); } return false; }
//ブロック 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; }