public override void Run()
		{
			var processed = new ArrayList();
			foreach(var input in Parameters.Input)
			{
				using(var reader = input.Open())
				{
					var code = reader.ReadToEnd();
					if (booViewEngine.ConditionalPreProcessingOnly(input.Name) == false ||
					    ShouldPreProcess(code))
					{
					    code = Booify(code);
					}
                    else
					{
					    code = EscapeNullPropagationsInOutputExpression(code);
					}
					var newInput = new StringInput(input.Name, code);
					inputToCode.Add(input, code);
					processed.Add(newInput);
				}
			}
			Parameters.Input.Clear();
			foreach(StringInput input in processed)
			{
				Parameters.Input.Add(input);
			}
		}
        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));
                }
            }
        }
Esempio n. 3
0
 private void setupSources(BooCompiler compiler, ViewCompilerInfo info) {
     compiler.Parameters.Input.Clear();
     foreach (var source in info.Sources) {
         var input = new StringInput(source.Key, source.GetContent());
         compiler.Parameters.Input.Add(input);
     }
 }
        public override void Run() {
#if LIB2
            var sources = this.Parameters.Input.ToArray();
            this.Parameters.Input.Clear();
            foreach (var compilerInput in sources) {
                var val = "";
                using (var r = compilerInput.Open()) {
                    val = r.ReadToEnd();
                }
                val = val.replace(@"\$(?=[^\{])", "_QUOTED_USD_");
                var src = new StringInput(compilerInput.Name, val);
                this.Parameters.Input.Add(src);
            }
#endif
        }
		public override void Run()
		{
			ArrayList processed = new ArrayList();
			foreach (ICompilerInput input in Parameters.Input)
			{
				//if input.Name.Contains("empty"):
				//	System.Diagnostics.Debugger.Break()
				using (TextReader reader = input.Open())
				{
					string code = reader.ReadToEnd();
					if (this.booViewEngine.ConditionalPreProcessingOnly(input.Name) == false ||
						ShouldPreProcess(code))
						code = Booify(code);
					StringInput newInput = new StringInput(input.Name, code);
					inputToCode.Add(input, code);
					processed.Add(newInput);
				}
			}
			Parameters.Input.Clear();
			foreach (StringInput input in processed)
			{
				Parameters.Input.Add(input);
			}
		}
Esempio n. 6
0
        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;
        }
        private void AddNamespaceImports(Import node)
        {
            RemoveCurrentNode();

            string url = GetFilePath(node);
            using(TextReader reader = urlResolver(url, baseDirectory))
            {
                BooParsingStep parser = new BooParsingStep();
                CompilerContext context = new CompilerContext();
                StringInput input = new StringInput(node.AssemblyReference.Name, reader.ReadToEnd());
                context.Parameters.Input.Add(input);
                parser.Initialize(context);
                parser.Run();
                Module current = (Module) node.GetAncestor(NodeType.Module);
                foreach (Module module in context.CompileUnit.Modules)
                {
                    foreach (Import import in module.Imports)
                    {
                        current.Imports.Add(import);
                    }
                }
            }
        }
 public static void AssertCSharpConversion(string expectedCSharpCode, string unityScriptCode)
 {
     var input = new StringInput("Script", unityScriptCode);
     CompileUnit[] array = Convert(input);
     AssertCSharpCode(expectedCSharpCode, array[0]);
 }
Esempio n. 9
0
		Module parse(StringInput input)
		{
			CompilerPipeline pipeline = new CompilerPipeline();
			pipeline.Add(new WSABooParsingStep());
			
			BooCompiler compiler = new BooCompiler();
			compiler.Parameters.Pipeline = pipeline;
			compiler.Parameters.Input.Add(input);
			CompilerContext result = compiler.Run();
			Assert.AreEqual(0, result.Errors.Count, result.Errors.ToString());
			Assert.AreEqual(1, result.CompileUnit.Modules.Count);
			return result.CompileUnit.Modules[0];
		}
Esempio n. 10
0
		Module parse(string code)
		{
			StringInput input = new StringInput("code", code);
			return parse(input);
		}