2016-10-29 15:02:36 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Generator;
|
|
|
|
|
|
|
|
|
|
namespace Generator
|
|
|
|
|
{
|
|
|
|
|
public partial class CodeWriter
|
|
|
|
|
{
|
|
|
|
|
private StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
private int indent = 0;
|
2016-10-29 15:13:25 +03:00
|
|
|
|
private bool skipIndent = false;
|
|
|
|
|
public string Indent { get { if ( skipIndent ) { return ""; } return new string( '\t', indent ); } }
|
2016-10-29 15:02:36 +03:00
|
|
|
|
|
|
|
|
|
private void EndBlock( string end = "" )
|
|
|
|
|
{
|
|
|
|
|
indent--;
|
2016-10-29 15:13:25 +03:00
|
|
|
|
WriteLine( "}" + end );
|
2016-10-29 15:02:36 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void WriteLine( string v = "" )
|
|
|
|
|
{
|
|
|
|
|
sb.AppendLine( $"{Indent}{v}" );
|
2016-10-29 15:13:25 +03:00
|
|
|
|
skipIndent = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Write( string v = "" )
|
|
|
|
|
{
|
|
|
|
|
sb.Append( $"{Indent}{v}" );
|
|
|
|
|
skipIndent = true;
|
2016-10-29 15:02:36 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void StartBlock( string v )
|
|
|
|
|
{
|
2016-10-29 15:13:25 +03:00
|
|
|
|
WriteLine( v );
|
|
|
|
|
WriteLine( "{" );
|
2016-10-29 15:02:36 +03:00
|
|
|
|
|
|
|
|
|
indent++;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-01 14:05:26 +03:00
|
|
|
|
private void Else( string v = "" )
|
|
|
|
|
{
|
|
|
|
|
indent--;
|
|
|
|
|
|
|
|
|
|
WriteLine( "}" );
|
|
|
|
|
WriteLine( "else"+ v );
|
|
|
|
|
WriteLine( "{" );
|
|
|
|
|
|
|
|
|
|
indent++;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-29 15:02:36 +03:00
|
|
|
|
private void WriteLines( List<string> beforeLines )
|
|
|
|
|
{
|
|
|
|
|
foreach ( var line in beforeLines )
|
|
|
|
|
{
|
|
|
|
|
if ( line == "}" )
|
|
|
|
|
indent--;
|
|
|
|
|
|
|
|
|
|
WriteLine( line );
|
|
|
|
|
|
|
|
|
|
if ( line == "{" )
|
|
|
|
|
indent++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|