Beispiel #1
0
 /// <summary>
 /// Registers a new SpecialNodesInserter with the output visitor.
 /// Make sure to call Finish() (or Dispose()) on the returned SpecialNodesInserter
 /// when the output is finished.
 /// </summary>
 public static SpecialNodesInserter Install(IEnumerable<ISpecial> specials, IOutputAstVisitor outputVisitor)
 {
     SpecialNodesInserter sni = new SpecialNodesInserter(specials, new SpecialOutputVisitor(outputVisitor.OutputFormatter));
     outputVisitor.BeforeNodeVisit += sni.AcceptNodeStart;
     outputVisitor.AfterNodeVisit  += sni.AcceptNodeEnd;
     return sni;
 }
        /// <summary>
        /// Registers a new SpecialNodesInserter with the output visitor.
        /// Make sure to call Finish() (or Dispose()) on the returned SpecialNodesInserter
        /// when the output is finished.
        /// </summary>
        public static SpecialNodesInserter Install(IEnumerable <ISpecial> specials, IOutputAstVisitor outputVisitor)
        {
            SpecialNodesInserter sni = new SpecialNodesInserter(specials, new SpecialOutputVisitor(outputVisitor.OutputFormatter));

            outputVisitor.BeforeNodeVisit += sni.AcceptNodeStart;
            outputVisitor.AfterNodeVisit  += sni.AcceptNodeEnd;
            return(sni);
        }
 public string Convert(string source, SupportedLanguage language)
 {
     CompilationUnit compilationUnit = this.GenerateCompilationUnit(source, language);
     SpecialOutputVisitor specialOutputVisitor = new SpecialOutputVisitor(this);
     this.specialNodesInserter = new SpecialNodesInserter(compilationUnit.UserData as List<ISpecial>, specialOutputVisitor);
     this.entryPointMethods = new List<MethodDeclaration>();
     this.codeBuilder = new PythonCodeBuilder()
     {
         IndentString = this.indentString
     };
     compilationUnit.AcceptVisitor(this, null);
     return this.codeBuilder.ToString().Trim();
 }
Beispiel #4
0
		string Output(IParser parser)
		{
			IOutputASTVisitor visitor = CreateOutputVisitor();
			visitor.Options = CreatePrettyPrintOptions();
			
			List<ISpecial> specials = parser.Lexer.SpecialTracker.CurrentSpecials;
			
			SpecialNodesInserter sni = new SpecialNodesInserter(specials,
			                                                    new SpecialOutputVisitor(visitor.OutputFormatter));
			visitor.NodeTracker.NodeVisiting += sni.AcceptNodeStart;			
			visitor.NodeTracker.NodeVisited += sni.AcceptNodeEnd;
			visitor.NodeTracker.NodeChildrenVisited += sni.AcceptNodeEnd;
			visitor.NodeTracker.NodeVisited += delegate(INode node) {
				if (IsMemberDeclaration(node))
				{
					visitor.OutputFormatter.NewLine();
				}
			};
			parser.CompilationUnit.AcceptVisitor(visitor, null);
			sni.Finish();
			return visitor.Text;
		}
		/// <summary>
		/// Converts the source code to Python.
		/// </summary>
		public string Convert(string source, SupportedLanguage language)
		{
			// Convert to NRefactory code DOM.
			CompilationUnit unit = GenerateCompilationUnit(source, language);
			
			SpecialOutputVisitor specialOutputVisitor = new SpecialOutputVisitor(this);
			specialNodesInserter = new SpecialNodesInserter(unit.UserData as List<ISpecial>, specialOutputVisitor);
			
			// Convert to Python code.
			entryPointMethods = new List<MethodDeclaration>();
			codeBuilder = new PythonCodeBuilder();
			codeBuilder.IndentString = indentString;
			unit.AcceptVisitor(this, null);
			
			return codeBuilder.ToString().Trim();
		}