private static GraceObject objectFromElement(XElement root) { GraceObject obj = GraceObject.Done; var stringEl = root.XPathSelectElement("//string"); if (stringEl != null) { obj = GraceString.Create(stringEl.Value); } var numberEl = root.XPathSelectElement("//number"); if (numberEl != null) { double d; if (double.TryParse(numberEl.Value, out d)) { obj = GraceNumber.Create(d); } } var objectEl = root.XPathSelectElement("//object"); if (objectEl != null) { int objKey; if (int.TryParse(objectEl.Value, out objKey)) { obj = new GraceForeignObject(objKey); } } return(obj); }
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)); }
/// <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); }