Example #1
0
        public void CancelEscrowPreventsOutputOfPendingLine()
        {
            var writer = new StringWriter();
            var source = new SourceWriter(writer);

            source
                .WriteLine()
                .WriteLine("begin")
                .AddIndent()
                .WriteLine("if")
                .AddIndent()
                .WriteLine("do this")
                .RemoveIndent()
                .EscrowLine("endif")
                .ClearEscrowLine()
                .WriteLine("else")
                .AddIndent()
                .WriteLine("do that")
                .RemoveIndent()
                .EscrowLine("endif")
                .RemoveIndent()
                .WriteLine("done");
            Assert.That(source.ToString(), Is.EqualTo(@"
            begin
            if
            do this
            else
            do that
            endif
            done
            "));
        }
Example #2
0
 public void VisitChunk(IChunkVisitor visitor, OutputLocation location, IList<Chunk> body, StringBuilder output)
 {
     if (location == OutputLocation.ClassMembers)
     {
         foreach (var snippet in body.OfType<CodeStatementChunk>().SelectMany(chunk => chunk.Code))
         {
             snippet.Value = snippet.Value.Replace("@class", "class");
         }
         var source = new SourceWriter(new StringWriter(output));
         var generator = new GeneratedCodeVisitor(source, new Dictionary<string, object>(), NullBehaviour.Strict);
         generator.Accept(body);
     }
 }
Example #3
0
        public void IndentationShouldAddLeadingSpace()
        {
            var writer = new StringWriter();
            var source = new SourceWriter(writer);

            source
                .WriteLine()
                .WriteLine("one")
                .AddIndent()
                .WriteLine("two")
                .RemoveIndent()
                .WriteLine("three");
            Assert.That(source.ToString(), Is.EqualTo(@"
            one
            two
            three
            "));
        }
Example #4
0
        public void EscrowLineWritesFirstAtIndentationWhenItWasAdded()
        {
            var writer = new StringWriter();
            var source = new SourceWriter(writer);
            source.WriteLine().AddIndent();

            source
                .WriteLine("one")
                .AddIndent()
                .WriteLine("two")
                .EscrowLine("two-b")
                .RemoveIndent()
                .WriteLine("three")
                .RemoveIndent();
            Assert.That(source.ToString(), Is.EqualTo(@"
            one
            two
            two-b
            three
            "));
        }
 public GlobalFunctionsVisitor(SourceWriter source, IDictionary<string, object> globals)
 {
     _source = source;
     _globals = globals;
 }
Example #6
0
 public GeneratedCodeVisitor(SourceWriter source, IDictionary<string, object> globals)
 {
     _source = source;
     _variables = new VariableTracker(globals);
 }
Example #7
0
 public GlobalInitializeVisitor(SourceWriter sourceWriter)
 {
     _source = sourceWriter;
 }
 public GlobalMembersVisitor(SourceWriter sourceWriter, Dictionary<string, object> globals)
 {
     _source = sourceWriter;
     _globals = globals;
 }