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; }
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); }