private static string RunThroughPreProcessor(string code) { var ppc = new BrailPreProcessor(new BooViewEngine()); var context = new CompilerContext(); context.Parameters.Input.Add(new StringInput("test", code)); ppc.Initialize(context); ppc.Run(); return context.Parameters.Input[0].Open().ReadToEnd(); }
private static string RunThroughPreProcessor(string code) { var ppc = new BrailPreProcessor(new BooViewEngine()); var context = new CompilerContext(); context.Parameters.Input.Add(new StringInput("test", code)); ppc.Initialize(context); ppc.Run(); return(context.Parameters.Input[0].Open().ReadToEnd()); }
public CompilationResult(CompilerContext context, BrailPreProcessor processor) { this.context = context; this.processor = processor; }
/// <summary> /// Perform the actual compilation of the scripts /// Things to note here: /// * The generated assembly reference the Castle.MonoRail.MonoRailBrail and Castle.MonoRail.Framework assemblies /// * If a common scripts assembly exist, it is also referenced /// * The AddBrailBaseClassStep compiler step is added - to create a class from the view's code /// * The ProcessMethodBodiesWithDuckTyping is replaced with ReplaceUknownWithParameters /// this allows to use naked parameters such as (output context.IsLocal) without using /// any special syntax /// * The FixTryGetParameterConditionalChecks is run afterward, to transform "if ?Error" to "if not ?Error isa IgnoreNull" /// * The ExpandDuckTypedExpressions is replace with a derived step that allows the use of Dynamic Proxy assemblies /// * The IntroduceGlobalNamespaces step is removed, to allow to use common variables such as /// date and list without accidently using the Boo.Lang.BuiltIn versions /// </summary> /// <param name="files"></param> /// <param name="name"></param> /// <returns></returns> private CompilationResult DoCompile(IEnumerable<ICompilerInput> files, string name) { ICompilerInput[] filesAsArray = new List<ICompilerInput>(files).ToArray(); BooCompiler compiler = SetupCompiler(filesAsArray); string filename = Path.Combine(baseSavePath, name); compiler.Parameters.OutputAssembly = filename; // this is here and not in SetupCompiler since CompileCommon is also // using SetupCompiler, and we don't want reference to the old common from the new one if (common != null) compiler.Parameters.References.Add(common); // pre procsssor needs to run before the parser var processor = new BrailPreProcessor(this); compiler.Parameters.Pipeline.Insert(0, processor); // inserting the add class step after the parser compiler.Parameters.Pipeline.Insert(2, new TransformToBrailStep(options)); compiler.Parameters.Pipeline.Replace(typeof(ProcessMethodBodiesWithDuckTyping), new ReplaceUknownWithParameters()); //compiler.Parameters.Pipeline.Replace(typeof(ExpandDuckTypedExpressions), // new ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods()); compiler.Parameters.Pipeline.Replace(typeof(InitializeTypeSystemServices), new InitializeCustomTypeSystem()); compiler.Parameters.Pipeline.InsertBefore(typeof(ReplaceUknownWithParameters), new FixTryGetParameterConditionalChecks()); compiler.Parameters.Pipeline.RemoveAt(compiler.Parameters.Pipeline.Find(typeof(IntroduceGlobalNamespaces))); return new CompilationResult(compiler.Run(), processor); }
private void setupPipeline(BooCompiler compiler, ViewCompilerInfo info) { if(info.InMemory) { if (info.ProcessingTest) { compiler.Parameters.Pipeline = new ResolveExpressions(); } else { compiler.Parameters.Pipeline = new CompileToMemory(); } }else { compiler.Parameters.Pipeline = new CompileToFile(); } compiler.Parameters.Pipeline.RemoveAt(0); compiler.Parameters.Pipeline.Insert(0,new WSAIgnoranceParsingStep()); var processor = new BrailPreProcessor(null, true); compiler.Parameters.Pipeline.Insert(0, processor); compiler.Parameters.Pipeline.InsertAfter(typeof(WSAIgnoranceParsingStep), new ExpandBmlStep()); compiler.Parameters.Pipeline.InsertAfter(typeof(WSAIgnoranceParsingStep), new IncludeAstMacroExpandStep()); compiler.Parameters.Pipeline.Insert(2, new TransformToBrailStep(info.Options)); compiler.Parameters.Pipeline.InsertAfter(typeof(TransformToBrailStep), new BrailRenamerAndTimeStamper()); compiler.Parameters.Pipeline.InsertAfter(typeof(ExpandBmlStep), new InterpolationUnescapeStep()); compiler.Parameters.Pipeline.InsertAfter(typeof (MacroAndAttributeExpansion), new OutputWriteUnification()); // if (!info.BrailProcessingTest) { compiler.Parameters.Pipeline.Replace(typeof (ProcessMethodBodiesWithDuckTyping), new ReplaceUknownWithParameters()); if (!info.ProcessingTest) { compiler.Parameters.Pipeline.Replace(typeof (ExpandDuckTypedExpressions), new ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods ()); } #if !LIB2 compiler.Parameters.Pipeline.Replace(typeof(InitializeTypeSystemServices), new InitializeCustomTypeSystem()); #endif compiler.Parameters.Pipeline.InsertBefore(typeof (MacroAndAttributeExpansion), new FixTryGetParameterConditionalChecks()); compiler.Parameters.Pipeline.RemoveAt( compiler.Parameters.Pipeline.Find(typeof (IntroduceGlobalNamespaces))); //} if(null!=PreparePipeline) { PreparePipeline(compiler.Parameters.Pipeline); } if(StopOnError)this.compiler.Parameters.Pipeline.BreakOnErrors = true; this.compiler.Parameters.Pipeline.BeforeStep += Pipeline_BeforeStep; this.compiler.Parameters.Pipeline.AfterStep += Pipeline_AfterStep; }