Esempio n. 1
0
        internal static DekiScriptExpression Parse(XDoc doc, bool scripted)
        {
            DekiScriptParser parser = new DekiScriptParser();
            var list = new List <DekiScriptExpression>();
            var root = (XmlElement)doc.AsXmlNode;

            parser.PushNode(root);
            parser.Parse(root, list);
            var result = parser.TryCatch(list[0], scripted);

            parser.PopNode();
            if (list.Count != 1)
            {
                throw new DekiScriptParserException("invalid state: more than one root node in document", Location.None);
            }
            return(result);
        }
        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);
        }
 internal static DekiScriptExpression Parse(XDoc doc, bool scripted) {
     DekiScriptParser parser = new DekiScriptParser();
     var list = new List<DekiScriptExpression>();
     var root = (XmlElement)doc.AsXmlNode;
     parser.PushNode(root);
     parser.Parse(root, list);
     var result = parser.TryCatch(list[0], scripted);
     parser.PopNode();
     if(list.Count != 1) {
         throw new DekiScriptParserException("invalid state: more than one root node in document", Location.None);
     }
     return result;
 }