コード例 #1
0
        public bool Subst(ref IErlObject term, ErlVarBind binding)
        {
            bool changed = false;

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

            var r = m_Items.Select(o =>
            {
                IErlObject obj = null;
                if (o.Subst(ref obj, binding))
                {
                    changed = true; return(obj);
                }
                return(o);
            }).ToList();

            if (!changed)
            {
                return(false);
            }

            term = makeInstance(r);
            return(true);
        }
コード例 #2
0
        public bool Subst(ref IErlObject term, ErlVarBind binding)
        {
            bool changed = false;

            var r = m_Items.Select(o =>
            {
                IErlObject key = null, value = null;
                if (o.Key.Subst(ref key, binding))
                {
                    changed = true;
                }
                if (o.Value.Subst(ref value, binding))
                {
                    changed = true;
                }
                return(new KeyValuePair <IErlObject, IErlObject>(
                           key ?? o.Key,
                           value ?? o.Value
                           ));
            }).ToList();

            if (!changed)
            {
                return(false);
            }

            term = new ErlMap(r.ToDictionary(kvp => kvp.Key, kvp => kvp.Value));
            return(true);
        }
コード例 #3
0
 public void Merge(ErlVarBind other)
 {
     init();
     foreach (var kv in other.m_Dict)
     {
         m_Dict[kv.Key] = kv.Value;
     }
 }
コード例 #4
0
        /// <summary>
        /// Receive a message and match it against a given pattern
        /// </summary>
        /// <param name="pattern">Pattern to match the message against</param>
        /// <param name="timeoutMsec">Timeout in milliseconds</param>
        /// <returns>Return a tuple containing the received message and variable
        /// binding object. On timeout the first element of the tuple is null.
        /// On unsuccessful match the second element of the tuple is null</returns>
        public Tuple <IErlObject, ErlVarBind> ReceiveMatch(IErlObject pattern, int timeoutMsec = -1)
        {
            var m = Receive(timeoutMsec);

            if (m == null)
            {
                return(Tuple.Create <IErlObject, ErlVarBind>(null, null));
            }

            var  binding = new ErlVarBind();
            bool res     = m.Match(pattern, binding);

            return(Tuple.Create(m, res ? binding : null));
        }
コード例 #5
0
ファイル: ErlPatternMatcher.cs プロジェクト: dotnetchris/nfx
        /// <summary>
        /// Match a term against the patterns in the collection.
        /// The first successful match will result in invocation of the func
        /// associated with the pattern, and storing func result in the term
        /// </summary>
        /// <param name="term">Term to match against patterns</param>
        /// <param name="args">Arguments to be passed to an func on successful pattern match</param>
        /// <returns>ID of the pattern that matched, or -1 if there were no matches</returns>
        public int Match(ref IErlObject term, params object[] args)
        {
            var binding = new ErlVarBind();

            foreach (var p in m_patterns)
            {
                if (p.Term.Match(term, binding))
                {
                    term = p.Func(p, term, binding, args);
                    return(p.ID);
                }
                binding.Clear();
            }

            return(-1);
        }
コード例 #6
0
        /// <summary>
        /// Perform pattern match on this Erlang term, storing matched variables
        /// found in the pattern into the binding.
        /// </summary>
        public bool Match(IErlObject pattern, ErlVarBind binding)
        {
            if (pattern is ErlVar)
            {
                return(pattern.Match(this, binding));
            }

            var rhs = pattern as ErlTupleBase;

            if (rhs == null || GetType() != pattern.GetType() || Count != rhs.Count)
            {
                return(false);
            }

            return(!m_Items.SkipWhile((o, i) => o.Match(rhs[i], binding)).Any());
        }
コード例 #7
0
ファイル: ErlVar.cs プロジェクト: luozhiping1987/nfx
        /// <summary>
        /// Perform pattern match on this Erlang term, storing matched variables
        /// found in the pattern into the binding.
        /// </summary>
        public bool Match(IErlObject pattern, ErlVarBind binding)
        {
            if (binding == null)
            {
                return(false);
            }
            IErlObject value = binding[Name];

            if (value != null)
            {
                return(checkType(value) ? value.Match(pattern, binding) : false);
            }
            if (!checkType(pattern))
            {
                return(false);
            }
            IErlObject term = null;

            binding[Name] = pattern.Subst(ref term, binding) ? term : pattern;
            return(true);
        }
コード例 #8
0
ファイル: ErlVar.cs プロジェクト: luozhiping1987/nfx
        public bool Subst(ref IErlObject obj, ErlVarBind binding)
        {
            if (IsAny || binding == null || binding.Empty)
            {
                throw new ErlException(StringConsts.ERL_UNBOUND_VARIABLE_ERROR);
            }

            IErlObject term = binding[Name];

            if (term == null)
            {
                //throw new ErlException(StringConsts.VARIABLE_NOT_FOUND_ERROR, Name);
                return(false);
            }
            if (!checkType(term))
            {
                throw new ErlException(StringConsts.ERL_VARIABLE_INVALID_VALUE_TYPE_ERROR,
                                       Name, obj.GetType().Name, ValueType);
            }
            obj = term;
            return(true);
        }
コード例 #9
0
        public bool Match(IErlObject pattern, ErlVarBind binding)
        {
            if (pattern is ErlVar)
            {
                return(pattern.Match(this, binding));
            }

            var other = pattern as ErlMap;

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

            if (m_Items.Count != other.m_Items.Count)
            {
                return(false);
            }

            // TODO: Sensible matching for maps (like in Erlang)
            return(false);
        }
コード例 #10
0
ファイル: ErlLong.cs プロジェクト: dotnetchris/nfx
 /// <summary>
 /// Perform pattern match on this Erlang term, storing matched variables
 /// found in the pattern into the binding.
 /// </summary>
 public bool Match(IErlObject pattern, ErlVarBind binding)
 {
     return(pattern is ErlVar?pattern.Match(this, binding) : Equals(pattern));
 }
コード例 #11
0
ファイル: ErlLong.cs プロジェクト: dotnetchris/nfx
 public bool Subst(ref IErlObject term, ErlVarBind binding)
 {
     return(false);
 }
コード例 #12
0
ファイル: ErlObject.cs プロジェクト: uzbekdev1/nfx
        /// <summary>
        /// Substibute all variables in the given object using provided binding
        /// and return the resulting object
        /// </summary>
        public static IErlObject Subst(this IErlObject o, ErlVarBind binding)
        {
            IErlObject term = null;

            return(o.Subst(ref term, binding) ? term : o);
        }
コード例 #13
0
        /// <summary>
        /// Perform pattern match on this Erlang term returning null if match fails
        /// or a dictionary of matched variables bound in the pattern
        /// </summary>
        public ErlVarBind Match(IErlObject pattern)
        {
            var binding = new ErlVarBind();

            return(Match(pattern, binding) ? binding : null);
        }