internal RantPattern(string name, RantPatternSource type, string code) { Name = name; Type = type; Code = code; Action = RantCompiler.Compile(name, code); }
private static IEnumerator<RantAction> Branch(Sandbox sb, string id, RantAction branchAction) { sb.RNG.Branch(id.Hash()); yield return branchAction; sb.RNG.Merge(); }
private static IEnumerator<RantAction> Else(Sandbox sb, RantAction conditionFailPattern) { if (sb.Engine.Flags.Any(flag => sb.ConditionFlags.Contains(flag) != sb.FlagConditionExpectedResult)) { yield return conditionFailPattern; } }
private static IEnumerator<RantAction> Then(Sandbox sb, RantAction conditionPassPattern) { if (sb.Engine.Flags.All(flag => sb.ConditionFlags.Contains(flag) == sb.FlagConditionExpectedResult)) { yield return conditionPassPattern; } }
private static IEnumerator<RantAction> Chan(Sandbox sb, string channelName, ChannelVisibility visibility, RantAction pattern) { sb.Output.OpenChannel(channelName, visibility); yield return pattern; sb.Output.CloseChannel(); }
/// <summary> /// Creates a new RantObject instance from the specified object. /// </summary> /// <param name="obj">The value to assign to the object.</param> public RantObject(object obj) { if (obj == null) return; if (obj is string) { _string = obj.ToString(); Type = RantObjectType.String; } else if (obj is bool) { _boolean = (bool)obj; Type = RantObjectType.Boolean; } else if (IsNumber(obj)) { _number = (double)obj; Type = RantObjectType.Number; } else if (obj is List<RantObject>) { _list = (List<RantObject>)obj; Type = RantObjectType.List; } else if (obj.GetType().IsArray) { _list = ((object[])obj).Select(o => new RantObject(o)).ToList(); Type = RantObjectType.List; } else if (obj is RantPattern) { _pattern = (RantPattern)obj; } else if (obj is RantAction) { _action = (RantAction)obj; Type = RantObjectType.Action; } }
internal RantObject(RantAction action) { Type = RantObjectType.Action; _action = action; }
internal void AddActionFunction(string name, RantAction body) { _objects[name] = new RantObject(body); }
protected void AddToOutput(RantAction action) { // NOTE: kinda sucks we can't include the caller's name here because this method's signature must stay just as it is if (!outputDelegates.Any()) throw new RantInternalException($"{GetType().Name}.AddToOutput({action.GetType().Name}): Output delegate stack is empty."); outputDelegates.Peek()(action); }
public RAReplacer(Stringe range, Regex regex, RantAction sourceAction, RantAction matchEvalAction) : base(range) { _regex = regex; _sourceAction = sourceAction; _matchEvalAction = matchEvalAction; }