public Namespace AsNamespace() { var array_ns = new Shell.Types.Namespace(typeof(Array).Name); var pushfn = new Shell.Types.Function(typeof(Shell.Library.Functions.Array.Push).Name); pushfn.AddBuiltinLambda(new Shell.Library.Functions.Array.Push()); array_ns.Set(pushfn.name, pushfn); var popfn = new Shell.Types.Function(typeof(Shell.Library.Functions.Array.Pop).Name); popfn.AddBuiltinLambda(new Shell.Library.Functions.Array.Pop()); array_ns.Set(popfn.name, popfn); var insertfn = new Shell.Types.Function(typeof(Shell.Library.Functions.Array.Insert).Name); insertfn.AddBuiltinLambda(new Shell.Library.Functions.Array.Insert()); array_ns.Set(insertfn.name, insertfn); var deletefn = new Shell.Types.Function(typeof(Shell.Library.Functions.Array.Delete).Name); deletefn.AddBuiltinLambda(new Shell.Library.Functions.Array.Delete()); array_ns.Set(deletefn.name, deletefn); var rangefn = new Shell.Types.Function(typeof(Shell.Library.Functions.Array.Range).Name); rangefn.AddBuiltinLambda(new Shell.Library.Functions.Array.Range()); array_ns.Set(rangefn.name, rangefn); return(array_ns); }
public Namespace AsNamespace() { var string_ns = new Shell.Types.Namespace(typeof(String).Name); var lengthfn = new Shell.Types.Function(typeof(Shell.Library.Functions.String.Length).Name); lengthfn.AddBuiltinLambda(new Shell.Library.Functions.String.Length()); string_ns.Set(lengthfn.name, lengthfn); var substrfn = new Shell.Types.Function(typeof(Shell.Library.Functions.String.Substring).Name); substrfn.AddBuiltinLambda(new Shell.Library.Functions.String.Substring()); string_ns.Set(substrfn.name, substrfn); return(string_ns); }
public Namespace AsNamespace() { var dir_ns = new Shell.Types.Namespace(typeof(Directory).Name); dir_ns.Set("Current", GetCWD()); var changefn = new Shell.Types.Function(typeof(Shell.Library.Functions.Directory.Change).Name); changefn.AddBuiltinLambda(new Shell.Library.Functions.Directory.Change()); dir_ns.Set(changefn.name, changefn); var listfn = new Shell.Types.Function(typeof(Shell.Library.Functions.Directory.List).Name); listfn.AddBuiltinLambda(new Shell.Library.Functions.Directory.List()); listfn.AddBuiltinLambda(new Shell.Library.Functions.Directory.ListDir()); dir_ns.Set(listfn.name, listfn); return(dir_ns); }
public Namespace AsNamespace() { var name_ns = new Shell.Types.Namespace(typeof(Name).Name); var availablefn = new Shell.Types.Function(typeof(Shell.Library.Functions.Name.Available).Name); availablefn.AddBuiltinLambda(new Shell.Library.Functions.Name.Available()); name_ns.Set(availablefn.name, availablefn); var unsetfn = new Shell.Types.Function(typeof(Shell.Library.Functions.Name.Unset).Name); unsetfn.AddBuiltinLambda(new Shell.Library.Functions.Name.Unset()); name_ns.Set(unsetfn.name, unsetfn); var aliasfn = new Shell.Types.Function(typeof(Shell.Library.Functions.Name.Alias).Name); aliasfn.AddBuiltinLambda(new Shell.Library.Functions.Name.Alias()); name_ns.Set(aliasfn.name, aliasfn); return(name_ns); }
public Namespace AsNamespace() { var data_ns = new Shell.Types.Namespace(typeof(Indexable).Name); var lengthfn = new Shell.Types.Function(typeof(Shell.Library.Functions.Indexable.Length).Name); lengthfn.AddBuiltinLambda(new Shell.Library.Functions.Indexable.Length()); data_ns.Set(lengthfn.name, lengthfn); var containsfn = new Shell.Types.Function(typeof(Shell.Library.Functions.Indexable.Contains).Name); containsfn.AddBuiltinLambda(new Shell.Library.Functions.Indexable.Contains()); data_ns.Set(containsfn.name, containsfn); var keysfn = new Shell.Types.Function(typeof(Shell.Library.Functions.Indexable.Keys).Name); keysfn.AddBuiltinLambda(new Shell.Library.Functions.Indexable.Keys()); data_ns.Set(keysfn.name, keysfn); return(data_ns); }
/// <summary> /// namespace : KW_NAMESPACE IDENTIFIER LCURL EOL? namespaced_statement* RCURL ; /// namespaced_statement : EOL | namespaced_declaration EOL | namespace EOL | load_namespace EOL ; /// namespaced_declaration : IDENTIFIER OP_ASSGN (expression | function) ; /// load_namespace : KW_USING STRING (KW_AS IDENTIFIER)? ; /// </summary> public Namespace(string name, string from, Shell.Generated.ShellParser.Namespace_declarationContext context, Visitor visitor) { definitionDirectory = from; contents = new Dictionary <string, Types.IShellNamed>(); this.name = name; if (name == "") { this.name = context.IDENTIFIER().GetText(); } foreach (var stmt in context.namespaced_statement()) { var nsContext = stmt.namespace_declaration(); var nsDecl = stmt.namespaced_declaration(); var nsLoad = stmt.load_namespace(); if (nsContext != null) { var ns = new Namespace("", definitionDirectory, nsContext, visitor) { parent = this }; Set(ns.name, ns); } else if (nsDecl != null) { string nm = nsDecl.IDENTIFIER().GetText(); if (nsDecl.expression() != null) { var value = visitor.VisitExpression(nsDecl.expression()); if (value is Shell.Types.IShellData val) { Set(nm, val); } else { throw new Shell.Problems.UnexpectedType( new Source(nsDecl.expression().Start, nsDecl.expression().Stop), value, typeof(Shell.Types.IShellData) ); } } else if (nsDecl.function() != null) { if (Exists(nm)) { var val = Get(nm); if (val is Shell.Types.Function fn) { fn.AddUserDefinedLambda(nsDecl.function()); } else { throw new Shell.Problems.InvalidDefinition( new Source(nsDecl.function().Start, nsDecl.function().Stop), nm ); } } else { var fn = new Shell.Types.Function(nm); fn.AddUserDefinedLambda(nsDecl.function()); Set(nm, fn); } } } else if (nsLoad != null) { name = Utility.GetString(nsLoad.STRING().GetText(), visitor).contents; string newPath; if (definitionDirectory == "." && name.StartsWith("./")) { newPath = name; } else if (definitionDirectory != "." && name.StartsWith("/")) { newPath = name; } else { if (!(definitionDirectory.EndsWith('/')) && name.StartsWith("./")) { newPath = definitionDirectory + name.Substring(1); } else { newPath = definitionDirectory + name; } } var ns = Utility.LoadNamespace( name, nsLoad.IDENTIFIER() != null ? nsLoad.IDENTIFIER().GetText() : "", visitor ); ns.parent = this; Set(ns.name, ns); } } }