public Shell.Types.Namespace AsNamespace() { var system = new Shell.Types.Namespace(typeof(System).Name); var libraries = new List <Shell.Types.Namespace> { (new Shell.Library.Indexable()).AsNamespace(), (new Shell.Library.Name()).AsNamespace(), (new Shell.Library.Directory()).AsNamespace(), (new Shell.Library.Array()).AsNamespace(), (new Shell.Library.String()).AsNamespace() }; foreach (var library in libraries) { library.parent = system; system.Set(library.name, library); } var printfn = new Shell.Types.Function(typeof(Shell.Library.Functions.Print).Name); printfn.AddBuiltinLambda(new Shell.Library.Functions.Print()); system.Set(printfn.name, printfn); var printlnnfn = new Shell.Types.Function(typeof(Shell.Library.Functions.PrintLine).Name); printlnnfn.AddBuiltinLambda(new Shell.Library.Functions.PrintLine()); system.Set(printlnnfn.name, printlnnfn); system.Set("Path", GetPath()); var addtopathfn = new Shell.Types.Function(typeof(Shell.Library.Functions.AddToPath).Name); addtopathfn.AddBuiltinLambda(new Shell.Library.Functions.AddToPath()); system.Set(addtopathfn.name, addtopathfn); var removefrompathfn = new Shell.Types.Function(typeof(Shell.Library.Functions.RemoveFromPath).Name); removefrompathfn.AddBuiltinLambda(new Shell.Library.Functions.RemoveFromPath()); system.Set(removefrompathfn.name, removefrompathfn); var setpathfn = new Shell.Types.Function(typeof(Shell.Library.Functions.SetPath).Name); setpathfn.AddBuiltinLambda(new Shell.Library.Functions.SetPath()); system.Set(setpathfn.name, setpathfn); var execfn = new Shell.Types.Function(typeof(Shell.Library.Functions.Exec).Name); execfn.AddBuiltinLambda(new Shell.Library.Functions.Exec()); system.Set(execfn.name, execfn); var exitfn = new Shell.Types.Function(typeof(Shell.Library.Functions.Exit).Name); exitfn.AddBuiltinLambda(new Shell.Library.Functions.Exit()); exitfn.AddBuiltinLambda(new Shell.Library.Functions.ExitWithCode()); system.Set(exitfn.name, exitfn); return(system); }
/// <summary> /// program_statement : namespace_declaration EOL /// | statement /// ; /// </summary> override public Shell.Types.IShellReturnable VisitProgram_statement(ShellParser.Program_statementContext context) { var ctx_ns = context.namespace_declaration(); var ctx_stmt = context.statement(); if (ctx_ns != null) { var ns = new Shell.Types.Namespace("", ".", ctx_ns, this); state.Namespaces.Register(ns); return(defaultReturnValue); } else { return(VisitStatement(ctx_stmt)); } }
public void Set(string name, Shell.Types.Namespace ns) => state.all_namespaces[name] = ns;
public void Register(Shell.Types.Namespace ns) => state.all_namespaces.Add(ns.name, ns);