Ejemplo n.º 1
0
        internal override bool match(ATerm pattern, ArrayList list)
        {
            if (pattern.getType() == ATermType.LIST)
            {
                ATermList l = (ATermList)pattern;

                if (l.isEmpty())
                {
                    return(this.isEmpty());
                }

                if (l.getFirst().getType() == ATermType.PLACEHOLDER)
                {
                    ATerm ph_type = ((ATermPlaceholder)l.getFirst()).getPlaceholder();
                    if (ph_type.getType() == ATermType.APPL)
                    {
                        ATermAppl appl = (ATermAppl)ph_type;
                        if (appl.getName().Equals("list") && appl.getArguments().isEmpty())
                        {
                            list.Add(this);
                            return(true);
                        }
                    }
                }

                if (!isEmpty())
                {
                    ArrayList submatches = first.match(l.getFirst());
                    if (submatches == null)
                    {
                        return(false);
                    }

                    list.AddRange(submatches);

                    submatches = next.match(l.getNext());

                    if (submatches == null)
                    {
                        return(false);
                    }

                    list.AddRange(submatches);
                    return(true);
                }
                else
                {
                    return(l.isEmpty());
                }
            }

            return(base.match(pattern, list));
        }
Ejemplo n.º 2
0
        internal virtual bool matchArguments(ATerm[] pattern_args, ArrayList list)
        {
            for (int i = 0; i < args.Length; i++)
            {
                if (i >= pattern_args.Length)
                {
                    return(false);
                }

                ATerm arg         = args[i];
                ATerm pattern_arg = pattern_args[i];

                if (pattern_arg.getType() == ATermType.PLACEHOLDER)
                {
                    ATerm ph_type = ((ATermPlaceholder)pattern_arg).getPlaceholder();
                    if (ph_type.getType() == ATermType.APPL)
                    {
                        ATermAppl appl = (ATermAppl)ph_type;
                        if (appl.getName().Equals("list") && appl.getArguments().isEmpty())
                        {
                            ATermList result = ((PureFactory)getFactory()).getEmpty();
                            for (int j = args.Length - 1; j >= i; j--)
                            {
                                result = result.insert(args[j]);
                            }
                            list.Add(result);
                            return(true);
                        }
                    }
                }

                ArrayList submatches = arg.match(pattern_arg);
                if (submatches == null)
                {
                    return(false);
                }
                list.AddRange(submatches);
            }

            return(args.Length == pattern_args.Length);
        }