Example #1
0
        static void DoJsonObject(JsonTextBuffer avb, AltListTerm t, bool first)
        {
            if (t.IsEmptyList)
            {
                return;
            }

            DoJsonPair(avb, t.Arg(0), first);
            DoJsonObject(avb, (AltListTerm)t.Arg(1), false);
        }
Example #2
0
        static void DoJsonObject(XmlTextWriter xwr, string [] attributes, AltListTerm t, ref bool contentWritten)
        {
            if (t.IsEmptyList)
            {
                return;
            }

            DoJsonPair(xwr, attributes, t.Arg(0), ref contentWritten);
            DoJsonObject(xwr, attributes, (AltListTerm)t.Arg(1), ref contentWritten);
        }
            public override ListTerm FlattenList()
            {
                List <BaseTerm> a = FlattenListEx(functor);

                AltListTerm result = new AltListTerm(leftBracket, rightBracket);

                for (int i = a.Count - 1; i >= 0; i--)
                {
                    result = new AltListTerm(leftBracket, rightBracket, a [i], result); // [a0, a0, ...]
                }
                return(result);
            }
            public override ListTerm Reverse()
            {
                AltListTerm result = new AltListTerm(leftBracket, rightBracket);

                foreach (BaseTerm t in this)
                {
                    result =
                        new AltListTerm(leftBracket, rightBracket, t, result);
                }

                return(result);
            }
            public static AltListTerm ListFromArray(
                string leftBracket, string rightBracket, BaseTerm [] ta, BaseTerm afterBar)
            {
                AltListTerm result = null;

                for (int i = ta.Length - 1; i >= 0; i--)
                {
                    result = new AltListTerm(leftBracket, rightBracket, ta [i], result == null ? afterBar : result);
                }

                return(result);
            }
Example #6
0
            BaseTerm CopyEx(int newVerNo, bool mustBeNamed)
            {
                if (IsUnified)
                {
                    return(ChainEnd().CopyEx(newVerNo, mustBeNamed));
                }

                // A neater solution would be to use overrides for each term subtype.
                if (this is Variable)
                {
                    Variable v = (Variable)this;

                    if (newVerNo == v.verNo)
                    {
                        return(v.newVar);
                    }

                    v.verNo = newVerNo;

                    return(v.newVar = (mustBeNamed && this is NamedVariable)
                      ? new NamedVariable(((NamedVariable)v).Name)
                      : new Variable());
                }
                else if (this is CatchOpenTerm)
                {
                    CatchOpenTerm c = (CatchOpenTerm)this;

                    return(new CatchOpenTerm(c.Id, c.ExceptionClass, c.MsgVar.CopyEx(newVerNo, mustBeNamed),
                                             c.SeqNo, c.SaveStackSize));
                }
                else
                {
                    if (arity == 0)
                    {
                        return(this);
                    }

                    BaseTerm   t = null;
                    BaseTerm[] a = new BaseTerm[arity];

                    for (int i = 0; i < arity; i++)
                    {
                        if (args[i] != null)                              // may be null for a GapTerm
                        {
                            a[i] = args[i].CopyEx(newVerNo, mustBeNamed); // recursively refresh arguments
                        }
                    }
                    if (this is ListPatternTerm)
                    {
                        t = new ListPatternTerm(a);
                    }
                    else if (this is AltListTerm)
                    {
                        AltListTerm alt = (AltListTerm)this;
                        t = new AltListTerm(alt.LeftBracket, alt.RightBracket, a[0], a[1]);
                    }
                    else if (this is ListTerm)
                    {
                        if (((ListTerm)this).CharCodeString == null)
                        {
                            t = new ListTerm(a[0], a[1]);
                        }
                        else // it's an ISO-style string
                        {
                            t = new ListTerm(((ListTerm)this).CharCodeString);
                        }
                    }
                    else if (this is OperatorTerm)
                    {
                        t = new OperatorTerm(((OperatorTerm)this).od, a);
                    }
                    else if (this is DcgTerm)
                    {
                        t = new DcgTerm(functor, a);
                    }
                    else if (this is WrapperTerm)
                    {
                        t = new WrapperTerm((WrapperTerm)this, a);
                    }
                    else if (this is IntRangeTerm)
                    {
                        t = new IntRangeTerm((IntRangeTerm)this);
                    }
                    else if (this is ListPatternElem)
                    {
                        t = new ListPatternElem(a, ((ListPatternElem)this).downRepFactor, ((ListPatternElem)this).IsNegSearch);
                    }
                    else if (this is CompoundTerm)
                    {
                        t = new CompoundTerm(functor, a);
                    }
                    else
                    {
                        IO.Error("CopyEx(): type '{0}' not handled explicitly", this.GetType());
                    }

                    return(t);
                }
            }