public void Run(KScriptContainer container, string args, KScriptObject Pobj) { if (!Ignore && container.AllowExecution) { try { try { if (GetValue().GetValidationType() != KScriptObject.ValidationTypes.BEFORE_PARSING) { GetValue().Validate(); } if (GetValue().GetType().IsAssignableFrom(typeof(KScriptIDObject))) { KScriptIDObject val = (KScriptIDObject)GetValue(); Value = container.GetObjectStorageContainer().GetObjectFromUID <KScriptIDObject>(val.id); } else { GetValue().SetBaseScriptObject(Pobj); GetValue().Run(); } } catch (KScriptExceptions.KScriptSkipScriptObject) { } } catch (System.Exception ex) { container.HandleException(GetValue(), ex); } } }
/* Supported formats: * Is Initialised by ~myArrayName[0] etc. * Accepted key selectors: * - [number] - Index of item. * - ['string'] - Key of item * - [~'string'] (to-be-impl.) - Key of item (bubbles down the array from index). * * E.g. * MyArray => [a => 'puppy', b => 'dog', c => [d => 'cat', e => 'kitten', a => [a => 'cub']]] * * Example: * - MyArray[2][~'d'] returns 'cat'. * - MyArray[~'e'] returns 'kitten'. * Or MyArray['c'][~'a'] would return cub only bubbling down from index 'c' and not return 'puppy' */ public static string HandleString(string str, KScriptContainer container) { try { MatchCollection matches = Regex.Matches(str, ArrayMatch); Dictionary <string, Match> Matched_Items = new Dictionary <string, Match>(); string tmp = str; if (matches.Count < 1) { return(str); } foreach (Match match in matches) { string uID = Guid.NewGuid().ToString(); tmp = tmp.Replace(match.Groups[0].Value, $"[{{{uID}}}]"); Matched_Items.Add(uID, match); } foreach (KeyValuePair <string, Match> item in Matched_Items) { MatchCollection m = Regex.Matches(item.Value.Groups[0].Value, RetrieveItems); if (m.Count < 1) { return(str); } string id = Regex.Match(item.Value.Groups[0].Value, ArrayMatch).Groups[1].Value; ArrayBase current = container.GetMultidimensionalArrays()[id]; IArray needle = current.Find(m.Cast <Match>().ToArray()); var result = needle.GetValue() is null ? item.Value.Groups[0].Value : needle.GetValue(); tmp = tmp.Replace($"[{{{item.Key}}}]", result); } return(tmp); } catch (System.Exception ex) { if (container.Properties.ThrowAllExceptions) { container.HandleException(ex); } return(str); } }
public void Validate(KScriptBaseObject caller) { foreach (KScriptValidationObject kScriptValidationObject in validationObjects) { try { kScriptValidationObject.Validate(Container, caller); } catch (System.Exception ex) { Container.HandleException(caller, ex); throw new KScriptInvalidScriptType(caller); } } }
public static IArray GetArrayItem(string str, KScriptContainer container) { try { Match item = Regex.Match(str, ArrayMatch); MatchCollection m = Regex.Matches(item.Groups[0].Value, RetrieveItems); var find = Regex.Match(item.Groups[0].Value, ArrayMatch).Groups[1].Value; string id = string.IsNullOrWhiteSpace(find) ? MultiArray.MultiArrayParser.StripKey(str) : find; ArrayBase current = container.GetMultidimensionalArrays()[id]; IArray needle = current.Find(m.Cast <Match>().ToArray()); return(needle); } catch (System.Exception ex) { container.HandleException(ex); return(null); } }