private void DrawOutputArea(Rect areaRect, float outputWidth) { GUILayout.BeginHorizontal(); { GUILayout.Label(_texts["output_header"]); _outputFilterText = EditorGUILayout.TextField(_outputFilterText); if (RexHelper.Output.Any() && GUILayout.Button(_texts["output_clear"], GUILayout.Width(43f))) { RexHelper.ClearOutput(); } } GUILayout.EndHorizontal(); EditorGUILayout.BeginVertical(slimBox); scroll3 = EditorGUILayout.BeginScrollView(scroll3); { foreach (var o in RexHelper.Output) { if (o.Filter(_outputFilterText)) { EditorGUILayout.BeginVertical(GUILayout.ExpandWidth(true)); o.DrawOutputUI(); DisplayLine(); EditorGUILayout.EndVertical(); } } } EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); }
public void ClassSetup() { if (Parser == null) Parser = new RexParser(); RexHelper.Variables.Clear(); var expression = "1+1"; var pResult = Parser.ParseAssignment(expression); var cResult = RexCompileEngine.Compile(pResult); var output = Execute(cResult); Assert.AreEqual(2, output.Value); RexHelper.Variables.Clear(); RexHelper.ClearOutput(); }
/// <summary> /// Executes the expression once. /// </summary> /// <param name="code">Code to execute</param> private void Execute(string code) { lastRunSuccesfull = true; code = code.Trim().Trim(';'); if (string.IsNullOrEmpty(code)) { return; } RexISM.Code = code; var compile = _compileEngine.GetCompileAsync(code, out Messages); if (compile != null) { if (_expressionHistory.Count == 0 || _expressionHistory[0].Code != code) { _expressionHistory.Insert(0, new RexHitoryItem { Code = code }); } var output = RexHelper.Execute <OutputEntry>(compile, out Messages); if (output != null) { RexHelper.AddOutput(output); } if (output == null || output.Exception != null) { lastRunSuccesfull = false; } } else { lastRunSuccesfull = false; } lastExecute = DateTime.Now; }
/// <summary> /// Displays a single variable, returns true if the varible was deleted else false. /// </summary> /// <param name="VarName">Name of the var. (key of the <see cref="RexHelper.Variables"/>)</param> /// <param name="var">The varible to display. (Value of the <see cref="RexHelper.Variables"/>)</param> private bool DisplayVariable(string VarName, RexHelper.Variable var) { string highlightedString; var type = RexUtils.GetCSharpRepresentation(var.VarType); // Format the code for syntax highlighting using richtext. highlightedString = RexUIUtils.SyntaxHighlingting(type.Concat(new[] { Syntax.Space, Syntax.Name(VarName), Syntax.Space, Syntax.EqualsOp, Syntax.Space }).Concat(RexReflectionUtils.GetSyntaxForValue(var.VarValue))); var shouldDelete = GUILayout.Button(_texts.GetText("remove_variable", tooltipFormat: VarName), GUILayout.Width(20)); // Draw the button as a label. if (GUILayout.Button(_texts.GetText("inspect_variable", highlightedString, VarName), varLabelStyle, GUILayout.ExpandWidth(true))) { var ouput = new OutputEntry(); ouput.LoadObject(var.VarValue); RexHelper.AddOutput(ouput); } return(shouldDelete); }
public static DummyOutput Execute(CompiledExpression compiledExpression) { Dictionary<MessageType, List<string>> tmp; return RexHelper.Execute<DummyOutput>(compiledExpression, out tmp); }
public static DummyOutput CompileAndRun(string code, out Dictionary<MessageType, List<string>> messages) { var pResult = new RexParser().ParseAssignment(code); var cResult = RexCompileEngine.Compile(pResult); return RexHelper.Execute<DummyOutput>(cResult, out messages); }
public static CompiledExpression Compile(ParseResult parseResult) { var errors = Enumerable.Empty <string>(); var returnTypes = new[] { FuncType._object, FuncType._void }; foreach (var returnType in returnTypes) { var wrapper = MakeWrapper(Instance.NamespaceInfos.Where(ns => ns.Selected), parseResult, returnType); var result = CompileCode(wrapper); //Path. if (result.Errors.Count == 1) { var error = result.Errors[0]; if (error.ErrorNumber == "CS0103") { var errorRegex = Regex.Match(error.ErrorText, "The name (?<type>.*) does not exist in the current context"); var typeNotFound = errorRegex.Groups["type"].Value.Substring(1).Trim('\''); var canditateTypes = (from t in RexUtils.AllVisibleTypes where t.Name == typeNotFound select t).ToArray(); if (canditateTypes.Length == 0) { return(new CompiledExpression { Parse = parseResult, Errors = new List <string> { result.Errors.Cast <CompilerError>().First().ErrorText } }); } if (canditateTypes.Length > 1) { var types = from n in canditateTypes select RexUtils.GetCSharpRepresentation(n, true).ToString(); var allTypeNames = string.Join(Environment.NewLine, types.ToArray()); return(new CompiledExpression { Parse = parseResult, Errors = new List <string> { string.Format("Ambiguous type name '{1}': {0} {2} {0} {3}", Environment.NewLine, typeNotFound, allTypeNames, "Use the Scope settings to select which namespace to use.") } }); } var name = canditateTypes.First().Namespace; var info = Instance.NamespaceInfos.First(i => i.Name == name); if (!info.Selected) { var usings = Instance.NamespaceInfos.Where(ns => ns.Selected || ns.Name == name); wrapper = MakeWrapper(usings, parseResult, returnType); result = CompileCode(wrapper); } } } errors = RexHelper.DealWithErrors(result); if (!errors.Any()) { return(new CompiledExpression { Assembly = result.CompiledAssembly, Parse = parseResult, FuncType = returnType, Errors = errors }); } } return(new CompiledExpression { Parse = parseResult, Errors = errors }); }