Exemple #1
0
        static void p5_hyperlisp_get_object_value_regex(ApplicationContext context, ActiveEventArgs e)
        {
            if (e.Args.Value is Regex)
            {
                return;
            }
            var strValue = XUtil.FormatNode(context, e.Args).ToString();

            // Sanity check
            if (!strValue.StartsWithEx("/"))
            {
                throw new LambdaException("Syntax error in regular expression, missing initial /", e.Args, context);
            }

            // Converting string to regular expression
            var regexString = strValue.Substring(1);  // Removing initial "/"

            // More sanity check
            if (!regexString.Contains("/"))
            {
                throw new LambdaException("Syntax error in regular expression, missing trailing /", e.Args, context);
            }

            // Retrieving options
            var options = regexString.Substring(regexString.LastIndexOfEx("/") + 1);

            // Removing options from actual regex string
            regexString = regexString.Substring(0, regexString.LastIndexOfEx("/"));

            e.Args.Value = new Regex(regexString, GetOptions(context, e.Args, options));
        }
        public static void lambda_return(ApplicationContext context, ActiveEventArgs e)
        {
            // Retrieving root for efficiency reasons, since everything we do from here, we do to root.
            var root = e.Args.Root;

            // Inserting "return signaling node", such that [eval] and similar constructs will break out of their current execution.
            root.Insert(0, new Node("_return"));

            // Checking value of return, and acting accordingly, making sure we return simple values as such, and node expression results as nodes.
            var x = e.Args.Value as Expression;

            if (x != null)
            {
                // Making sure we clean up after ourselves.
                using (new ArgsRemover(e.Args)) {
                    // Source is an expression, evaluating it, and returning results back to caller.
                    var match = x.Evaluate(context, e.Args, e.Args);
                    if (match.TypeOfMatch == Match.MatchType.count)
                    {
                        // Simple count expression.
                        root.Value = match.Count;
                    }
                    else if (match.TypeOfMatch == Match.MatchType.node)
                    {
                        // Node values, single or multiple is irrelevant, still need to clone them, and insert them into root.
                        root.AddRange(match.Select(ix => ix.Node.Clone()));
                    }
                    else if (match.Count == 1)
                    {
                        // Single value, name or value type of value is irrelevant, adding to value anyways.
                        root.Value = match [0].Value;
                    }
                    else if (match.TypeOfMatch == Match.MatchType.name)
                    {
                        // Multiple name values.
                        root.AddRange(match.Select(ix => new Node(ix.Node.Name)));
                    }
                    else
                    {
                        // Multiple value values.
                        root.AddRange(match.Select(ix => new Node("", ix.Value)));
                    }
                }
            }
            else if (e.Args.Value != null)
            {
                // Returning formatted value.
                root.Value = XUtil.FormatNode(context, e.Args);
            }

            // Adding all children of [return] as result to evaluated root node, no need to clone.
            root.InsertRange(1, e.Args.Children);
        }
Exemple #3
0
        public static void lambda_src_dest(ApplicationContext context, ActiveEventArgs e)
        {
            // Figuring out type of source.
            var x = e.Args.Value as Expression;

            if (x != null)
            {
                // Source is an expression, evaluating it, and returning results back to caller.
                var match = x.Evaluate(context, e.Args, e.Args);

                // Removing all formatting nodes.
                e.Args.RemoveAll(ix => ix.Name == "");

                // Checking type of match.
                if (match.TypeOfMatch == Match.MatchType.count)
                {
                    // Simple count expression.
                    e.Args.Value = match.Count;
                }
                else if (match.TypeOfMatch == Match.MatchType.node)
                {
                    // Node values, single or multiple is irrelevant, still need to clone them.
                    e.Args.AddRange(match.Select(ix => ix.Node.Clone()));
                    e.Args.Value = null;
                }
                else if (match.Count == 1)
                {
                    // Single value, name or value type of value is irrelevant, adding to value anyways.
                    e.Args.Value = match [0].Value;
                }
                else if (match.TypeOfMatch == Match.MatchType.name)
                {
                    // Multiple name values.
                    e.Args.AddRange(match.Select(ix => new Node(ix.Node.Name)));
                    e.Args.Value = null;
                }
                else
                {
                    // Multiple value values.
                    e.Args.AddRange(match.Select(ix => new Node("", ix.Value)));
                    e.Args.Value = null;
                }
            }
            else if (e.Args.Value != null)
            {
                // Returning formatted value.
                e.Args.Value = XUtil.FormatNode(context, e.Args);
            } // else, returning children nodes as is
        }
Exemple #4
0
        public static void eval_x(ApplicationContext context, ActiveEventArgs e)
        {
            // House cleaning.
            using (new ArgsRemover(e.Args, true)) {
                // Looping through all destinations.
                foreach (var idxMatch in XUtil.DestinationMatch(context, e.Args, true))
                {
                    // Checking type of node value.
                    if (idxMatch.Node.Value is Expression)
                    {
                        // Evaluates result of expression, and substitues value with expression result.
                        idxMatch.Node.Value = idxMatch.Node.GetExValue <object> (context, null);

                        // Making sure we remove all formatting parameters for clarity.
                        idxMatch.Node.RemoveAll(ix => ix.Name == "");
                    }
                    else if (idxMatch.Node.Value != null)
                    {
                        // Formats value, and substitutes value with formatting result.
                        idxMatch.Node.Value = XUtil.FormatNode(context, idxMatch.Node);
                    } // Notice, we do not throw, to support recursive evaluations by using the /** iterator, where parts of results are not supposed to be forward evaluated.
                }
            }
        }