Beispiel #1
0
        public static void lambda_apply_braid(ApplicationContext context, ActiveEventArgs e)
        {
            // Retrieving [template], and performing basic sanity check.
            var templates = e.Args.Children.Where(ix => ix.Name == "template");

            if (templates.Count() != 1)
            {
                throw new LambdaException("You must provide exactly one [template] to [apply]", e.Args, context);
            }
            var template = templates.First();

            // Retrieving source, ignoring [template], and making sure source is not null, before we start braiding source(s) and template into destination.
            var source = XUtil.Sources(context, e.Args, "template");

            if (source.Count != 0)
            {
                // Looping through each destination, and braiding source(s) and template, before appending into destination node,
                // assuming destination is node type of expression.
                foreach (var idxDest in XUtil.DestinationMatch(context, e.Args, true))
                {
                    // Iterating through each source, braiding with template, and appending to destination node.
                    foreach (var idxSource in source)
                    {
                        // Braiding template and source, appending into destination.
                        idxDest.Node.AddRange(BraidTemplateWithSource(context, template, idxSource));
                    }
                }
            }
        }
Beispiel #2
0
        public static void lambda_for_each(ApplicationContext context, ActiveEventArgs e)
        {
            // Storing old [for-each] lambda, such that we can make sure each iteration becomes "locally immutable".
            Node originalLambda = e.Args.Clone();

            // Retrieving what to iterate.
            var match = XUtil.DestinationMatch(context, e.Args);

            // Evaluating lambda, until either all iterations are done, or stop flag condition tells us we're done, due to some condition stopping loop early.
            var first = true;

            foreach (var idx in match)
            {
                // Making sure we reset back lambda block, each consecutive time, after the initial iteration.
                // Notice, this logic first of all preserves some CPU cycles, not having to excessively clone the original lambda, but also actually makes
                // sure we can view the last iteration, if an exception or something similar occurs during execution.
                if (first)
                {
                    first = false;
                }
                else
                {
                    e.Args.Clear().AddRange(originalLambda.Clone().Children);
                }

                // Perform a single iteration.
                if (!Iterate(context, idx.Value, e.Args))
                {
                    break;
                }
            }
        }
Beispiel #3
0
        public static void lambda_set(ApplicationContext context, ActiveEventArgs e)
        {
            // Finding source value, notice that if we have no source, we still iterate each destination, such that we can set it to a "null value".
            var src = XUtil.Source(context, e.Args);

            // Updating destination(s) with value of source.
            foreach (var idxDestination in XUtil.DestinationMatch(context, e.Args))
            {
                // Single source, or null source.
                idxDestination.Value = src;
            }
        }
Beispiel #4
0
        public static void lambda_add(ApplicationContext context, ActiveEventArgs e)
        {
            // Finding source nodes, and returning early if no source is given.
            var src = XUtil.Sources(context, e.Args);

            if (src.Count == 0)
            {
                return;
            }

            // Looping through each destination, adding all source nodes to it, cloning them before adding them.
            foreach (var idxDestination in XUtil.DestinationMatch(context, e.Args, true))
            {
                idxDestination.Node.AddRange(src.Select(ix => ix.Clone()));
            }
        }
Beispiel #5
0
        /*
         * Common insertion method for both of the above Active Events.
         */
        private static void InsertNodes(ApplicationContext context, Node args, bool after)
        {
            // Finding source nodes, and returning early if no source is given.
            var src = XUtil.Sources(context, args);

            if (src.Count == 0)
            {
                return;
            }

            // Looping through each destination, and inserting all source node at specified position, in order of appearance.
            foreach (var idxDestination in XUtil.DestinationMatch(context, args, true))
            {
                // Figuring out insertion point before we insert nodes.
                var index = idxDestination.Node.Parent.IndexOf(idxDestination.Node) + (after ? 1 : 0);
                idxDestination.Node.Parent.InsertRange(index, src.Select(ix => ix.Clone()));
            }
        }
Beispiel #6
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.
                }
            }
        }