本文整理汇总了C#中CSharpOutputVisitor.VisitCompilationUnit方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpOutputVisitor.VisitCompilationUnit方法的具体用法?C# CSharpOutputVisitor.VisitCompilationUnit怎么用?C# CSharpOutputVisitor.VisitCompilationUnit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSharpOutputVisitor
的用法示例。
在下文中一共展示了CSharpOutputVisitor.VisitCompilationUnit方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestProgram
void TestProgram(string program)
{
IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(program));
parser.Parse();
Assert.AreEqual("", parser.Errors.ErrorOutput);
CSharpOutputVisitor outputVisitor = new CSharpOutputVisitor();
outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
Assert.AreEqual(StripWhitespace(program), StripWhitespace(outputVisitor.Text));
}
示例2: TestProgram
public void TestProgram(string input, string expectedOutput)
{
IParser parser = ParserFactory.CreateParser(SupportedLanguage.VBNet, new StringReader(input));
parser.Parse();
Assert.AreEqual("", parser.Errors.ErrorOutput);
parser.CompilationUnit.AcceptVisitor(new VBNetToCSharpConvertVisitor(), null);
CSharpOutputVisitor outputVisitor = new CSharpOutputVisitor();
outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
Assert.AreEqual(expectedOutput, outputVisitor.Text);
}
示例3: TestProgram
void TestProgram(string program)
{
IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(program));
parser.Parse();
Assert.AreEqual("", parser.Errors.ErrorOutput);
CSharpOutputVisitor outputVisitor = new CSharpOutputVisitor();
using (SpecialNodesInserter.Install(parser.Lexer.SpecialTracker.RetrieveSpecials(),
outputVisitor)) {
outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
}
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
Assert.AreEqual(program.Replace("\r", ""), outputVisitor.Text.TrimEnd().Replace("\r", ""));
parser.Dispose();
}
示例4: TestProgram
public void TestProgram(string input, string expectedOutput)
{
IParser parser = ParserFactory.CreateParser(SupportedLanguage.VBNet, new StringReader(input));
parser.Parse();
Assert.AreEqual("", parser.Errors.ErrorOutput);
parser.CompilationUnit.AcceptVisitor(new VBNetConstructsConvertVisitor(), null);
parser.CompilationUnit.AcceptVisitor(new ToCSharpConvertVisitor(), null);
CSharpOutputVisitor outputVisitor = new CSharpOutputVisitor();
outputVisitor.Options.IndentationChar = ' ';
outputVisitor.Options.IndentSize = 2;
outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
Assert.AreEqual(expectedOutput.Replace("\r", ""), outputVisitor.Text.Replace("\r", ""));
}
示例5: GenerateCode
public static string GenerateCode(CompilationUnit compilationUnit)
{
CSharpOutputVisitor outputVisitor = new CSharpOutputVisitor();
outputVisitor.VisitCompilationUnit(compilationUnit, null);
return outputVisitor.Text;
}
示例6: GenerateSourceCode
/// <summary>
/// Performs the reverse operation of parsing by serializing the specified <paramref name="compilationUnit"/>
/// to source code.
/// </summary>
///
/// <param name="compilationUnit">
/// A <see cref="CompilationUnit"/> which is to be turned into source code.
/// </param>
///
/// <returns>
/// A string representing the source code that would compile to the provided <paramref name="compilationUnit"/>.
/// </returns>
public static string GenerateSourceCode(this CompilationUnit compilationUnit)
{
var outputVisitor = new CSharpOutputVisitor
{
Options =
{
IndentationChar = ' ',
TabSize = 4,
IndentSize = 4,
}
};
using (CodeCommentDecorator.Install(outputVisitor))
{
outputVisitor.VisitCompilationUnit(compilationUnit, null);
}
return outputVisitor.Text;
}
示例7: GenerateCode
private void GenerateCode()
{
foreach (Source entry in Sources.Values)
{
if (entry.CodeFile)
{
CSharpOutputVisitor csharpOutputVisitor = new CSharpOutputVisitor();
SpecialNodesInserter.Install(entry.Parser.Lexer.SpecialTracker.RetrieveSpecials(), csharpOutputVisitor);
csharpOutputVisitor.VisitCompilationUnit(entry.CompilationUnit, null);
entry.Code = csharpOutputVisitor.Text;
}
}
}