////////////////////////////////////////////////////////////////////////// // Factory ////////////////////////////////////////////////////////////////////////// /// <summary> /// Parse the signature into a loaded type. /// </summary> public static Type load(string sig, bool check, Pod loadingPod) { // if last character is ?, then parse a nullable int len = sig.Length; int last = len > 1 ? sig[len-1] : 0; if (last == '?') return load(sig.Substring(0, len-1), check, loadingPod).toNullable(); // if the last character isn't ] or |, then this a non-generic // type and we don't even need to allocate a parser if (last != ']' && last != '|') { string podName, typeName; try { int colon = sig.IndexOf(':'); if (sig[colon+1] != ':') throw new System.Exception(); podName = sig.Substring(0, colon); typeName = sig.Substring(colon+2); if (podName.Length == 0 || typeName.Length == 0) throw new System.Exception(); } catch (System.Exception) { throw ArgErr.make("Invalid type signature '" + sig + "', use <pod>::<type>").val; } // if the type is from the pod being loaded then return to the pod if (loadingPod != null && podName == loadingPod.name()) return loadingPod.type(typeName, check); // do a straight lookup return find(podName, typeName, check); } // we got our work cut out for us - create parser try { return new TypeParser(sig, check, loadingPod).LoadTop(); } catch (Err.Val e) { throw e; } catch (System.Exception) { throw Err(sig).val; } }