Exemple #1
0
        public Executor generateExecutor(string[] args)
        {
            for (int i = args.Count() - 1; i >= 0; --i)
            {
                this.tokens.Push(args[i]);
            }

            if (tokens.Count == 0)
            {
                throw new Exception("Requires at least one path argument");
            }

            var root = new DirectoryInfo(tokens.Pop());

            List <FilterBase> filters = new List <FilterBase>(); // list of logfical helper
            List <OptionBase> options = new List <OptionBase>();
            List <ActionBase> actions = new List <ActionBase>();

            while (tokens.Count > 0)
            {
                // analysize next keyword (name, size, maxdepth) and parameter (*.txt, -1mb, 10)
                // looking for instance of respective node from static dictionary in the class
                PlanNode node = parseOr();
                switch (node.getKind())
                {
                case PlanNodeKind.OPTION:
                    options.Add((OptionBase)node);
                    break;

                case PlanNodeKind.FILTER:
                    filters.Add((FilterBase)node);
                    break;

                case PlanNodeKind.ACTION:
                    actions.Add((ActionBase)node);
                    break;

                default:
                    throw new Exception("Unsupport enum value " + node.getKind().ToString());
                }
            }

            tokens = null;
            return(new Executor(root, filters, options, actions));
        }
Exemple #2
0
        // parse "-not ..." input
        private PlanNode parseNot()
        {
            bool negate = false;

            if (nextTokenIs("-not") || nextTokenIs("-n"))
            {
                tokens.Pop();
                negate = true;
            }
            PlanNode operand = parseAtom();

            if (!negate)
            {
                return(operand);
            }
            if (operand.getKind() != PlanNodeKind.FILTER)
            {
                throw new Exception("Logical NOT can only be applied to a predicate");
            }
            return(new LogicalNot((FilterBase)operand));
        }