private static (string, Atom, Atom, Atom) ReadArguments(Atom args) { var(path, command, rest) = StructureUtils.Split2Next(args); if (path.type != AtomType.String && path.type != AtomType.Symbol) { throw new ArgumentException("argument must be string or symbol!"); } string name = (string)path.value; return(name, path, command, rest); }
private static void ImportSymbols(Context context, Atom result, Atom path, Atom command, Atom rest) { if (command == null) { string name = Path.GetFileNameWithoutExtension((string)path.value); context.Define(name, result); } else { if (!command.IsSymbol) { throw new ArgumentException($"Unexpected symbol '{command}'!"); } switch ((string)command.value) { case Names.MODULE_REQUIRE_AS: Atom name = rest.next?.atom; if (name == null || !name.IsSymbol) { throw new ArgumentException($"Unexpected symbol '{name}'!"); } context.Define((string)name.value, result); break; case Names.MODULE_REQUIRE_IMPORT: string[] nameList = StructureUtils.ListToStringArray(rest, "REQUIRE"); ContextUtils.ImportSymbols((Context)result.value, context, nameList); break; case Names.MODULE_REQUIRE_IMPORT_ALL: ContextUtils.ImportAllSymbols((Context)result.value, context); break; default: throw new ArgumentException($"Unexpected symbol '{command}'!"); } } }