/// <summary> /// Load extensions to builtins from traits in an /// existing object. /// </summary> /// <param name="ext">Object containing extension traits.</param> public void LoadExtensionsFromObject(GraceObject ext) { var req = MethodRequest.Nullary("ObjectExtension"); req.IsInherits = true; if (ext.RespondsTo(req)) { var uo = new UserObject(); req.InheritingObject = uo; ext.Request(this, req); GraceObject.ExtendDefaultMethods(req.InheritedMethods); } req = MethodRequest.Nullary("NumberExtension"); req.IsInherits = true; if (ext.RespondsTo(req)) { var uo = new UserObject(); req.InheritingObject = uo; ext.Request(this, req); GraceNumber.ExtendWith(req.InheritedMethods); } req = MethodRequest.Nullary("StringExtension"); req.IsInherits = true; if (ext.RespondsTo(req)) { var uo = new UserObject(); req.InheritingObject = uo; ext.Request(this, req); GraceString.ExtendWith(req.InheritedMethods); } }
private GraceObject mParse(GraceObject code) { GraceString gs = code.FindNativeParent <GraceString>(); string s = gs.Value; var p = new Parser(s); return(new GraceObjectProxy(p.Parse())); }
private GraceObject mParseFile(GraceObject code) { GraceString gs = code.FindNativeParent <GraceString>(); string path = gs.Value; using (StreamReader reader = File.OpenText(path)) { var p = new Parser(reader.ReadToEnd()); return(new GraceObjectProxy(p.Parse())); } }
private GraceObject mArguments() { IList <string> unusedArguments = UnusedArguments.UnusedArgs; IList <GraceString> graceUnusedArguments = new List <GraceString>(); foreach (var a in unusedArguments) { graceUnusedArguments.Add(GraceString.Create(a)); } return(GraceVariadicList.Of(graceUnusedArguments)); }
private GraceObject mTranslateFile(GraceObject code) { GraceString gs = code.FindNativeParent <GraceString>(); string path = gs.Value; using (StreamReader reader = File.OpenText(path)) { var p = new Parser(reader.ReadToEnd()); var module = p.Parse(); ExecutionTreeTranslator ett = new ExecutionTreeTranslator(); Node eModule = ett.Translate(module as ObjectParseNode); return(eModule); } }
/// <summary> /// Load a resource file /// </summary> /// <param name="filePath">Filesystem path to resource</param> /// <param name="importPath">Import path used to reach resource</param> private GraceObject loadResource(string filePath, string importPath) { var ext = Path.GetExtension(importPath); if (ext == ".txt") { return(GraceString.Create(File.OpenText(filePath).ReadToEnd())); } ErrorReporting.RaiseError(this, "R2010", new Dictionary <string, string> { { "path", importPath }, { "extension", ext } }, "LookupError: No resource handler for ${importPath}"); return(null); }
private static bool conditionsMet( string l, Dictionary <string, string> data ) { var interpreter = new Interpreter(); interpreter.LoadPrelude(); var ls = new LocalScope(); foreach (var k in data.Keys) { switch (k) { case "method": case "type": case "class": case "object": case "def": case "var": case "dialect": case "import": case "return": case "is": case "where": ls.AddLocalDef(k + "_", GraceString.Create(data[k])); break; default: ls.AddLocalDef(k, GraceString.Create(data[k])); break; } } interpreter.Extend(ls); while (l.StartsWith("|[")) { int end = l.IndexOf("]|"); var condition = l.Substring(2, end - 2); if (!conditionMet(condition, data, interpreter)) { return(false); } l = l.Substring(end + 2); } return(true); }