Exemple #1
0
        public DekiScriptDom Visit(DekiScriptDomJson expr, DekiScriptOptimizerState state)
        {
            DekiScriptExpression value = expr.Value.VisitWith(DekiScriptExpressionOptimizer.Instance, state);

            if (value is DekiScriptLiteral)
            {
                return(new DekiScriptDomText(expr.Location, DekiScriptLibrary.JsonEmit(((DekiScriptLiteral)value).NativeValue)));
            }
            return(new DekiScriptDomJson(expr.Location, value));
        }
        public Empty Visit(DekiScriptDomJson expr, DekiScriptDomEvaluationState state)
        {
            var context = state.Context;
            var env     = state.Env;
            var parent  = state.Parent;

            try {
                DekiScriptLiteral value  = expr.Value.VisitWith(DekiScriptExpressionEvaluation.Instance, env);
                XmlText           result = context.CreateTextNode(DekiScriptLibrary.JsonEmit(value.NativeValue));
                parent.AppendChild(result);
            } catch (Exception e) {
                EmbedExceptionMessage(expr, env, context, e, parent);
            }
            return(Empty.Value);
        }
        private static bool TryParseDekiScriptExpression(string ctor, DekiScriptEnv env, DekiScriptRuntime runtime, ref int i, out string value)
        {
            string source = ParseExpression(ctor, null, ParseMode.EXPRESSION, false, env, runtime, null, ref i);

            if ((i >= ctor.Length) || (ctor[i] != '}'))
            {
                value = null;
                return(false);
            }

            // try to parse and execute the dekiscript fragment
            try {
                source = source.Substring(1, source.Length - 2);
                DekiScriptExpression dekiscript = DekiScriptParser.Parse(new Location("jem"), source);
                DekiScriptLiteral    result     = runtime.Evaluate(dekiscript, DekiScriptEvalMode.EvaluateSafeMode, env);
                value = DekiScriptLibrary.JsonEmit(result.NativeValue);
            } catch (Exception e) {
                // execution failed; convert exception into a javascript comment
                value = "alert(\"ERROR in DekiScript expression:\\n---------------------------\\n\\n\" + " + e.GetCoroutineStackTrace().QuoteString() + ")";
            }
            return(true);
        }