예제 #1
0
        /// <summary>
        /// 执行指定脚本
        /// </summary>
        /// <param name="context">脚本执行上下文</param>
        /// <param name="script">需要执行的脚本</param>
        /// <returns></returns>
        public static object Execute(ScriptExecuteContext context, string script)
        {
            try
            {
                var tokens = Tokenizer(script);
                if (tokens.Count == 1)
                {
                    return(Execute(context, tokens[0]));
                }

                var sb = new StringBuilder();
                foreach (var token in tokens)
                {
                    var result = Execute(context, token);
                    sb.Append(ToString(result));
                }

                return(sb.ToString());
            }
            catch (Exception exception)
            {
                throw new ZeboneException(string.Format("在执行脚本 {0} 时发生错误:{1}", script, exception.Message), exception);
            }
        }
예제 #2
0
 internal TokenExecutor(ScriptExecuteContext context, Token token)
 {
     this.context = context;
     this.token   = token;
 }
예제 #3
0
 /// <summary>
 /// 处理脚本中的符号,返回处理后的脚本
 /// </summary>
 /// <param name="context">脚本执行上下文</param>
 /// <param name="script">需要进行处理的脚本</param>
 /// <returns></returns>
 public static string ReplaceTokens(ScriptExecuteContext context, string script)
 {
     return(ToString(Execute(context, script)));
 }
예제 #4
0
 /// <summary>
 /// 执行指定符号
 /// </summary>
 /// <param name="context">脚本执行上下文</param>
 /// <param name="token">需要执行的符号</param>
 /// <returns></returns>
 public static object Execute(ScriptExecuteContext context, Token token)
 {
     return(new TokenExecutor(context, token).Execute());
 }