示例#1
0
文件: List.cs 项目: yonglehou/otp.net
        public override bool subst(ref Erlang.Object a_term, VarBind binding)
        {
            System.Collections.Generic.List <Erlang.Object> result =
                new System.Collections.Generic.List <Erlang.Object>();
            bool changed = false;

            if (this.elems != null)
            {
                foreach (Erlang.Object term in this.elems)
                {
                    Erlang.Object obj = null;
                    if (term.subst(ref obj, binding))
                    {
                        result.Add(obj);
                    }
                    else
                    {
                        changed = true;
                        result.Add(term);
                    }
                }
            }

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

            a_term = new Erlang.List(result.ToArray());
            return(true);
        }
示例#2
0
文件: List.cs 项目: yonglehou/otp.net
 public override bool match(Erlang.Object pattern, VarBind binding)
 {
     if (pattern is Erlang.Var)
     {
         pattern.match(this, binding);
     }
     else if (!(pattern is Erlang.List))
     {
         return(false);
     }
     Erlang.List tup = pattern as Erlang.List;
     if (arity() != tup.arity())
     {
         return(false);
     }
     for (int i = 0; i < arity(); ++i)
     {
         if (!elems[i].match(tup[i], binding))
         {
             return(false);
         }
     }
     return(true);
 }
示例#3
0
文件: List.cs 项目: saneman1/otp.net
        public override bool subst(ref Erlang.Object a_term, VarBind binding)
        {
            System.Collections.Generic.List<Erlang.Object> result =
                new System.Collections.Generic.List<Erlang.Object>();
            bool changed = false;

            foreach (Erlang.Object term in this.elems)
            {
                Erlang.Object obj = null;
                if (term.subst(ref obj, binding))
                    result.Add(obj);
                else
                {
                    changed = true;
                    result.Add(term);
                }
            }

            if (!changed)
                return false;

            a_term = new Erlang.List(result.ToArray());
            return true;
        }
示例#4
0
文件: Format.cs 项目: saleyn/otp.net
        internal static Erlang.Object create(
            char[] fmt, ref int pos, ref int argc, params object[] args)
        {
            var items = new System.Collections.Generic.List<Erlang.Object>();
            Erlang.Object result = null;
            pos = skip_null_chars(fmt, pos);

            switch (fmt[pos++]) {
                case '{':
                    if (State.ERL_OK != ptuple(fmt, ref pos, ref items, ref argc, args))
                        throw new FormatException(
                            string.Format("Error parsing tuple at pos {0}", pos));
                    result = new Erlang.Tuple(items.ToArray());
                    break;

                case '[':
                    if (fmt[pos] == ']') {
                        result = new Erlang.List();
                        pos++;
                        break;
                    }
                    else if (State.ERL_OK == plist(fmt, ref pos, ref items, ref argc, args))
                    {
                        result = new Erlang.List(items.ToArray());
                        break;
                    }
                    throw new FormatException(
                        string.Format("Error parsing list at pos {0}", pos));

                case '$': /* char-value? */
                    result = new Erlang.Char(fmt[pos++]);
                    break;

                case '~':
                    if (State.ERL_OK != pformat(fmt, ref pos, ref items, ref argc, args))
                        throw new FormatException(
                            string.Format("Error parsing term at pos {0}", pos));
                    result = items[0];
                    break;

                default:
                    char c = fmt[--pos];
                    if (char.IsLower(c)) {         /* atom  ? */
                        string s = patom(fmt, ref pos);
                        result = createAtom(s);
                    } else if (char.IsUpper(c) || c == '_') {
                        TermType t;
                        string s = pvariable(fmt, ref pos, out t);
                        result = new Erlang.Var(s, t);
                    } else if (char.IsDigit(c) || c == '-') {    /* integer/float ? */
                        string s = pdigit(fmt, ref pos);
                        if (s.IndexOf('.') < 0)
                            result = new Erlang.Long(long.Parse(s, CultureInfo.InvariantCulture));
                        else
                            result = new Erlang.Double(double.Parse(s, CultureInfo.InvariantCulture));
                    } else if (c == '"') {      /* string ? */
                        string s = pstring(fmt, ref pos);
                        result = new Erlang.String(s);
                    } else if (c == '\'') {     /* quoted atom ? */
                        string s = pquotedAtom(fmt, ref pos);
                        result = createAtom(s);
                    }
                    break;
            }

            return result;
        }
示例#5
0
        internal static Erlang.Object create(
            char[] fmt, ref int pos, ref int argc, params object[] args)
        {
            var items = new System.Collections.Generic.List <Erlang.Object>();

            Erlang.Object result = null;
            pos = skip_null_chars(fmt, pos);

            switch (fmt[pos++])
            {
            case '{':
                if (State.ERL_OK != ptuple(fmt, ref pos, ref items, ref argc, args))
                {
                    throw new FormatException(
                              string.Format("Error parsing tuple at pos {0}", pos));
                }
                result = new Erlang.Tuple(items.ToArray());
                break;

            case '[':
                if (fmt[pos] == ']')
                {
                    result = new Erlang.List();
                    pos++;
                    break;
                }
                else if (State.ERL_OK == plist(fmt, ref pos, ref items, ref argc, args))
                {
                    result = new Erlang.List(items.ToArray());
                    break;
                }
                throw new FormatException(
                          string.Format("Error parsing list at pos {0}", pos));

            case '$':     /* char-value? */
                result = new Erlang.Char(fmt[pos++]);
                break;

            case '~':
                if (State.ERL_OK != pformat(fmt, ref pos, ref items, ref argc, args))
                {
                    throw new FormatException(
                              string.Format("Error parsing term at pos {0}", pos));
                }
                result = items[0];
                break;

            default:
                char c = fmt[--pos];
                if (char.IsLower(c))               /* atom  ? */
                {
                    string s = patom(fmt, ref pos);
                    result = createAtom(s);
                }
                else if (char.IsUpper(c) || c == '_')
                {
                    TermType t;
                    string   s = pvariable(fmt, ref pos, out t);
                    result = new Erlang.Var(s, t);
                }
                else if (char.IsDigit(c) || c == '-')            /* integer/float ? */
                {
                    string s = pdigit(fmt, ref pos);
                    if (s.IndexOf('.') < 0)
                    {
                        result = new Erlang.Long(long.Parse(s, CultureInfo.InvariantCulture));
                    }
                    else
                    {
                        result = new Erlang.Double(double.Parse(s, CultureInfo.InvariantCulture));
                    }
                }
                else if (c == '"')              /* string ? */
                {
                    string s = pstring(fmt, ref pos);
                    result = new Erlang.String(s);
                }
                else if (c == '\'')             /* quoted atom ? */
                {
                    string s = pquotedAtom(fmt, ref pos);
                    result = createAtom(s);
                }
                break;
            }

            return(result);
        }