Exemple #1
0
        /// <exception cref="InterpreterError">The DECL syntax is invalid.</exception>
        public IEnumerable <KeyValuePair <ZilAtom, ZilObject> > GetAtomDeclPairs()
        {
            ZilListoidBase list = this;

            while (!list.IsEmpty)
            {
                if (!list.StartsWith(out ZilList atoms, out ZilObject decl))
                {
                    break;
                }

                if (!atoms.All(a => a is ZilAtom))
                {
                    break;
                }

                foreach (var zo in atoms)
                {
                    var atom = (ZilAtom)zo;
                    yield return(new KeyValuePair <ZilAtom, ZilObject>(atom, decl));
                }

                list = list.GetRest(2);
                Debug.Assert(list != null);
            }

            if (!list.IsEmpty)
            {
                throw new InterpreterError(InterpreterMessages.Malformed_DECL_Object);
            }
        }
Exemple #2
0
        public void Deconstruct([NotNull] out ZilObject first, [NotNull] out ZilListoidBase rest)
        {
            if (IsEmpty)
            {
                throw new InvalidOperationException("Cannot deconstruct an empty list");
            }

            Debug.Assert(this.First != null && this.Rest != null);

            first = this.First;
            rest  = this.Rest;
        }
Exemple #3
0
 public ZilList(ZilObject first, ZilListoidBase rest)
     : base(first, rest)
 {
 }
Exemple #4
0
 public bool IsCons([CanBeNull] out ZilObject first, [CanBeNull] out ZilListoidBase rest)
 {
     (first, rest) = (this.First, this.Rest);
     Debug.Assert(first == null && rest == null || first != null && rest != null);
     return(first != null);
 }