public void Run() { foreach (var input in _context.Parameters.Input) { try { bool wsa = false; bool isduck = true; string code = ""; using (var reader = input.Open()) { code = reader.ReadToEnd(); wsa = WSAHelper.IsWSA(code); isduck = WSAHelper.IsDuck(code); } var _input = new StringInput(input.Name, code); using (var reader = _input.Open()) { var module = ParseModule(wsa, input.Name, reader, OnParserError); module["isduck"] = isduck; module["iswsa"] = wsa; } } catch (CompilerError error) { _context.Errors.Add(error); } catch (antlr.TokenStreamRecognitionException x) { OnParserError(x.recog); } catch (Exception x) { _context.Errors.Add(CompilerErrorFactory.InputError(input.Name, x)); } } }
public override System.Reflection.Assembly CompileMultiple(Hashtable scriptNamesAndCode) { bool bUseTemporaryFiles = true; ArrayList files = new ArrayList(); //for easier deletion after compile this._compiler.Parameters.Input.Clear(); foreach (DictionaryEntry de in scriptNamesAndCode) { string nameID = (string)de.Key; string code = (string)de.Value; if (bUseTemporaryFiles) { string tempName = "__boo_"+nameID+".boo"; Endogine.Files.FileReadWrite.Write(tempName, code); System.IO.FileInfo file = new System.IO.FileInfo(tempName); files.Add(file); this._compiler.Parameters.Input.Add(new FileInput(tempName)); } else { //TODO: why is this StreamReader closed??? StringInput inp = new StringInput(nameID, code); inp.Open(); this._compiler.Parameters.Input.Add(inp); } } Boo.Lang.Compiler.CompilerContext context = this._compiler.Run(); if (bUseTemporaryFiles) { //foreach (System.IO.FileInfo file in files) // file.Delete(); } //The main module name is always filename+Module in pascal case; //this file is actually RunBooModule! //Using duck-typing, we can directly invoke static methods //Without having to do the typical System.Reflection voodoo. string[] errors; if (context.GeneratedAssembly == null) { errors = new string[context.Errors.Count]; string sErrors = "Boo compiler errors\r\n"; // for "+nameID+":\r\n"; for (int i=0; i<context.Errors.Count;i++) { Boo.Lang.Compiler.CompilerError err = context.Errors[i]; string sError = err.LexicalInfo.FileName + "("+err.LexicalInfo.Line+","+err.LexicalInfo.Column+")"+ "\r\n" + err.Message; if (System.IO.File.Exists(err.LexicalInfo.FileName)) { sError+="Source:\r\n"; System.IO.StreamReader rd = new System.IO.StreamReader(err.LexicalInfo.FileName); string sFileContents = rd.ReadToEnd(); string[] sLines = sFileContents.Split("\r\n".ToCharArray()); if (err.LexicalInfo.Line>0) sError+=sLines[(err.LexicalInfo.Line-1)*2]+"\r\n"; sError+=sLines[err.LexicalInfo.Line*2]; } errors[i] = sError; sErrors+=sError+"\r\n"; } throw new Exception(sErrors); } else { foreach (DictionaryEntry de in scriptNamesAndCode) { string nameID = (string)de.Key; this._classToAssembly[nameID] = context.GeneratedAssembly; } } return context.GeneratedAssembly; }