public override bool Visit(UnifiedWhile element, VisitorArgument arg) { Writer.Write("while "); element.Condition.TryAccept(this, arg); Writer.WriteLine(":"); element.Body.TryAccept(this, arg.IncrementDepth()); if (!element.ElseBody.IsEmptyOrNull()) { Writer.WriteLine("else:"); element.ElseBody.TryAccept(this, arg.IncrementDepth()); } return(false); }
public override bool Visit(UnifiedIf ifStatement, VisitorArgument arg) { Writer.Write("if "); ifStatement.Condition.TryAccept(this, arg); Writer.WriteLine(":"); ifStatement.Body.TryAccept(this, arg.IncrementDepth()); if (ifStatement.ElseBody != null) { WriteIndent(arg.IndentDepth); Writer.WriteLine("else:"); ifStatement.ElseBody.TryAccept(this, arg.IncrementDepth()); } return(false); }
public override bool Visit(UnifiedForeach element, VisitorArgument arg) { Writer.Write("for "); element.Element.TryAccept(this, arg); Writer.Write(" in "); element.Set.TryAccept(this, arg); Writer.WriteLine(":"); element.Body.TryAccept(this, arg.IncrementDepth()); if (!element.ElseBody.IsEmptyOrNull()) { Writer.WriteLine("else:"); element.ElseBody.TryAccept(this, arg.IncrementDepth()); } return(false); }
public override bool Visit(UnifiedDoWhile element, VisitorArgument arg) { element.Body.TryAccept(this, arg); Writer.Write("while "); element.Condition.TryAccept(this, arg); Writer.WriteLine(":"); element.Body.TryAccept(this, arg.IncrementDepth()); return(false); }
public override bool Visit( UnifiedSet <UnifiedCase> element, VisitorArgument arg) { arg = arg.IncrementDepth(); foreach (var caseElement in element) { WriteIndent(arg.IndentDepth); caseElement.TryAccept(this, arg); } return(false); }
public override bool Visit(UnifiedFor element, VisitorArgument arg) { element.Initializer.TryAccept(this, arg.Set(CommaDelimiter)); Writer.Write("while "); element.Condition.TryAccept(this, arg); Writer.WriteLine(":"); arg = arg.IncrementDepth(); element.Body.TryAccept(this, arg); WriteIndent(arg.IndentDepth); element.Step.TryAccept(this, arg.Set(SemiColonDelimiter)); return(false); }
public override bool Visit( UnifiedFunctionDefinition element, VisitorArgument arg) { element.Annotations.TryAccept(this, arg); element.Modifiers.TryAccept(this, arg); Writer.Write("def "); element.Name.TryAccept(this, arg); element.Parameters.TryAccept(this, arg); Writer.WriteLine(":"); element.Body.TryAccept(this, arg.IncrementDepth()); 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); }
public override bool Visit(UnifiedSwitch element, VisitorArgument arg) { if (!element.Cases.IsEmptyOrNull()) { foreach (var c in element.Cases) { Writer.Write("if "); element.Value.TryAccept(this, arg); Writer.Write(" == "); c.Condition.TryAccept(this, arg); Writer.WriteLine(":"); c.Body.TryAccept(this, arg.IncrementDepth()); } } return(false); }
public override bool Visit( UnifiedClassDefinition element, VisitorArgument arg) { element.Annotations.TryAccept(this, arg); element.Modifiers.TryAccept(this, arg); Writer.Write("class"); Writer.Write(" "); element.Name.TryAccept(this, arg); Writer.Write(":"); Writer.Write(" # "); element.GenericParameters.TryAccept(this, arg); element.Constrains.TryAccept(this, arg); Writer.WriteLine(); element.Body.TryAccept(this, arg.IncrementDepth()); 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); }