public static string JoinToString( JoinStatement joinStatement, string spaces, string itemSpaces )
        {
            var builder = new StringBuilder();

            builder.Append( "<%join \"" );
            builder.Append( joinStatement.String );
            builder.Append( "\"%>" );

            foreach (var statement in joinStatement.Statements)
            {
                if (statement is ValueStatement)
                    builder.Append( ValueUnitTest.ValueToString( (ValueStatement)statement, spaces ) );
                else if (statement is ApplyStatement)
                    builder.Append( ApplyUnitTest.ApplyToString( (ApplyStatement)statement, spaces, true ) );
                else
                    Assert.Fail( "Join can contain only statements of type: {0}, {1}", typeof(ValueStatement), typeof(ApplyStatement) );

                builder.Append( itemSpaces );
            }

            builder.Append( "<%end%>" );

            return builder.ToString();
        }
Beispiel #2
0
        void Join(out JoinStatement joinStatement)
        {
            string @string;
            List<RuleStatement> statements = null;
            ValueStatement valueStatement;
            ApplyStatement applyStatement;
            CallStatement callStatement;
            //JoinStatement joinStatement;
            AppendType appendType = AppendType.EmptyLastLine;
            while (!(la.kind == 0 || la.kind == 4)) {SynErr(43); Get();}
            Expect(4);
            Token start = t;
            Expect(29);
            @string = t.val.Substring( 1, t.val.Length - 2 );
            if (la.kind == 17) {
            Get();
            if (la.kind == 18) {
                Get();
                appendType = AppendType.SpaceLastLine;
            } else if (la.kind == 19) {
                Get();
                appendType = AppendType.CloneLastLine;
            } else if (StartOf(7)) {
                while (StartOf(8)) {
                    Get();
                }

            } else SynErr(44);
            }
            while (!(la.kind == 0 || la.kind == 10)) {SynErr(45); Get();}
            Expect(10);
            while (la.kind == 5 || la.kind == 6 || la.kind == 12) {
            if (la.kind == 12) {
                Value(out valueStatement);
                if (statements == null) statements = new List<RuleStatement>();
                statements.Add( valueStatement );
            } else if (la.kind == 5) {
                Apply(out applyStatement);
                if (statements == null) statements = new List<RuleStatement>();
                statements.Add( applyStatement );
            } else {
                Call(out callStatement);
                if (statements == null) statements = new List<RuleStatement>();
                statements.Add( callStatement );
            }
            }
            while (!(la.kind == 0 || la.kind == 11)) {SynErr(46); Get();}
            Expect(11);
            joinStatement = new JoinStatement( new StatementPosition( start, t ), @string, appendType, statements );
        }
        public CodeWriter Statement( JoinStatement join, string writerName )
        {
            var writer = new CodeWriter();

            writer.Indent = 0;
            writer.AppendLine( "{" );
            writer.Indent = 1;
            writer.AppendLine( "var list = new List<CodeWriter>();" );
            writer.AppendLine( "CodeWriter temp;" );
            writer.Indent = 0;
            writer.AppendLine();
            writer.Indent = 1;
            {
                var list = new List<CodeWriter>();
                CodeWriter temp;

                foreach (var item in join.Statements)
                {
                    temp = this.Invoke( "JoinStatement", item, "temp", "list" );
                    list.Add( temp );
                }

                writer.AppendType = AppendType.EmptyLastLine;
                for (var listI = 0; listI < list.Count; listI++)
                {
                    var codeWriter = list[listI];
                    writer.Append( codeWriter );
                    if (listI < list.Count - 1)
                        writer.AppendText( "\r\n" );
                }
                writer.AppendType = AppendType.EmptyLastLine;
            }
            writer.Indent = 0;
            writer.AppendLine();
            writer.AppendLine();
            writer.Indent = 1;
            writer.Append( "writer.AppendType = AppendType." );
            writer.AppendText( join.AppendType.ToString() );
            writer.Indent = 0;
            writer.AppendLine( ";" );
            writer.Indent = 1;
            writer.AppendLine( "for (var listI = 0; listI < list.Count; listI++)" );
            writer.AppendLine( "{" );
            writer.Indent = 2;
            writer.AppendLine( "var codeWriter = list[listI];" );
            writer.AppendText( writerName );
            writer.Indent = 0;
            writer.AppendLine( ".Append( codeWriter );" );
            writer.Indent = 2;
            writer.AppendLine( "if (listI < list.Count - 1)" );
            writer.Indent = 3;
            writer.AppendText( writerName );
            writer.Indent = 0;
            writer.Append( ".AppendText( \"" );
            writer.AppendText( join.String );
            writer.Indent = 0;
            writer.AppendLine( "\" );" );
            writer.Indent = 1;
            writer.AppendLine( "}" );
            writer.AppendLine( "writer.AppendType = AppendType.EmptyLastLine;" );
            writer.Indent = 0;
            writer.Append( "}" );

            return writer;
        }