public static call HasBlock(this call kall) { if (kall.block != null && kall.block.calls.Count > 0) { return(kall); } throw ObjException.BlockRequired(kall); }
public static call NoBlock(this call kall) { if (kall.block != null && kall.block.calls.Count > 0) { throw ObjException.BlockNotAccepted(kall); } return(kall); }
public static call DomBuilt(this call kall, IDocument dom) { if (dom == null) { throw ObjException.MissingDomAndCalled(kall); } return(kall); }
public async Task eval(call kall) { bool hadResult = resultSet; bool addedResult = await funcs[kall.name](kall); if (hadResult && addedResult) { throw ObjException.ExpressionDiscarded(kall, trace.FindLast(x => true)); } hadResult = addedResult; trace.Add(kall); }
public static call ElementSelected(this call kall, obj env) { var lastCall = env.trace.Last(); if (lastCall.name == "sel" || lastCall.name == "id") { return(kall); throw ObjException.MissingElementAndCalled(kall); } return(kall); }
public static call ArityMatches(this call kall, int expected) { if (kall.args == null && expected == 0) { return(kall); } if (kall.args?.Count != expected) { throw ObjException.ArityMismatch(kall, 1); } return(kall); }
public static skript ToSkript(string[] args) { if (args.Length == 0) { return(new skript() { }); } bool isCallName(string maybeCallName) => maybeCallName.StartsWith("-"); string cleanName(string callName) => new string(callName.SkipWhile(c => c == '-').ToArray()); int callDepth(string callName) => callName.TakeWhile(c => c == '-').Count(); bool parsing = true; //List<call> stack = new List<call>(); Stack <call> stack = new Stack <call>(); stack.Push(new call() { name = "Toplevel", depth = 0, }); int currentDepth = 0; int idx = 0; while (parsing) { string tok = args[idx]; int tokDepth = callDepth(tok); bool isCall = isCallName(tok); /* * toplevel * -site abc * -site bce */ if (isCall && tokDepth == currentDepth) { stack.Pop(); call k = new call() { name = cleanName(tok), depth = callDepth(tok) }; // Add to parent stack.Peek().AddCall(k); // Put on stack for followup calls stack.Push(k); } else if (isCall && tokDepth == currentDepth + 1) { call k = new call() { name = cleanName(tok), depth = callDepth(tok), }; stack.Peek().AddCall(k); stack.Push(k); currentDepth++; } else if (isCallName(tok) && callDepth(tok) < currentDepth && currentDepth > 0) { while (tokDepth < currentDepth) { stack.Pop(); currentDepth--; } stack.Pop(); call k = new call() { name = cleanName(tok), depth = callDepth(tok) }; // Add to parent stack.Peek().AddCall(k); // Put on stack for followup calls stack.Push(k); } else if (!isCall && currentDepth > 0) { // Values aren't valid at the top level stack.Peek().AddArg(tok); } else if (!isCall) { Curse.ValueIsNotCall(tok); } idx++; parsing = idx < args.Length; } while (stack.Count > 1) { stack.Pop(); } return(stack.Peek().block); }
public void AddCall(call child) { block = block ?? new skript(); block.calls.Add(child); }
internal static Exception UrlFailed(call kall) { return(new ObjException($"The URL {kall.args[0]} failed to load!")); }
internal static Exception BlockRequired(call kall) { return(new ObjException($"{kall.name} requires a block. Perhaps you wanted to use more dashes for the next argument?")); }
internal static Exception BlockNotAccepted(call kall) { return(new ObjException($"{kall.name} doesn't accept block. Perhaps you meant to use less dashes for {kall.block.calls[0].name}?")); }
public static ObjException ExpressionDiscarded(call current, call prev) { return(new ObjException($"Calling {current.DebugName} discarded result from {prev.DebugName}. Either use any/all with {prev.DebugName} as a sub-call")); }
public static ObjException MissingElementAndCalled(call kall) { return(new ObjException($"Order issue: -site and --id or --sel should be called before {kall.DebugName}")); }
public static ObjException MissingDomAndCalled(call kall) { return(new ObjException($"Order issue: -site should be called before {kall.DebugName}")); }
public static ObjException ArityMismatch(call kall, int expected) { return(new ObjException($"Arg mismatch: {kall.DebugName} exepects {expected} argument(s), not {kall.args.Count} arguments")); }