/// <summary> /// 增加 脚本和 using 引用到构建器中 /// </summary> /// <param name="script">代码脚本</param> /// <param name="usings">using 引用</param> /// <returns></returns> public NatashaException Add(string script, HashSet <string> usings = default) { #if DEBUG Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); #endif var tree = Syntax.ConvertToTree(script); #if DEBUG Console.WriteLine(); stopwatch.StopAndShowCategoreInfo("[SyntaxTree]", "语法树转换耗时", 2); stopwatch.Restart(); #endif var exception = NatashaExceptionAnalyzer.GetSyntaxException(tree); #if DEBUG stopwatch.StopAndShowCategoreInfo("[SyntaxTree]", "语法树判错耗时", 2); stopwatch.Restart(); #endif if (!exception.HasError || SyntaxErrorBehavior == ExceptionBehavior.Ignore) { Syntax.AddTreeToCache(tree); Syntax.ReferenceCache[exception.Formatter] = usings; } else { HandlerErrors(exception); } #if DEBUG stopwatch.StopAndShowCategoreInfo("[SyntaxTree]", "语法树错误处理耗时", 2); #endif return(exception); }
/// <summary> /// 增加 脚本和 using 引用到构建器中 /// </summary> /// <param name="script">代码脚本</param> /// <param name="usings">using 引用</param> /// <returns></returns> public NatashaException Add(string script, HashSet <string> usings = default) { var tree = Syntax.ConvertToTree(script); var exception = NatashaExceptionAnalyzer.GetSyntaxException(tree); if (!exception.HasError || SyntaxErrorBehavior == ExceptionBehavior.Ignore) { Syntax.AddTreeToCache(tree); Syntax.ReferenceCache[exception.Formatter] = usings; } else { HandlerErrors(exception); } return(exception); }
/// <summary> /// 添加语法树 /// </summary> /// <param name="tree"></param> public AssemblyCSharpBuilder Add(SyntaxTree tree) { tree = NatashaCSharpSyntax.FormartTree(tree, _options); var exception = NatashaExceptionAnalyzer.GetSyntaxException(tree); if (exception != null) { throw exception; } else { lock (SyntaxTrees) { SyntaxTrees.Add(tree); } } return(this); }
/// <summary> /// 添加脚本 /// </summary> /// <param name="script"></param> public AssemblyCSharpBuilder Add(string script) { var tree = NatashaCSharpSyntax.ParseTree(script, _options); var exception = NatashaExceptionAnalyzer.GetSyntaxException(tree); if (exception != null) { throw exception; } else { lock (SyntaxTrees) { SyntaxTrees.Add(tree); } } return(this); }