-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvocation.cs
More file actions
71 lines (61 loc) · 2.52 KB
/
Copy pathInvocation.cs
File metadata and controls
71 lines (61 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
namespace Cdp.ScriptableIde;
/// <summary>One call argument — Name null = positional. Types are projection (not stored here).</summary>
public sealed record CallArg(string? Name, string ExprWire);
/// <summary>
/// Invocation entity — Receiver / Name / Params / Bind.
/// Short path remains <see cref="Act.Call"/>; use this when arity / named args matter.
/// </summary>
public sealed class InvocationEntity
{
private string? _receiver;
private string? _name;
private string? _bind;
private readonly List<CallArg> _args = [];
public InvocationEntity On(string receiver)
{
ArgumentException.ThrowIfNullOrWhiteSpace(receiver);
_receiver = receiver.Trim();
return this;
}
public InvocationEntity Named(string methodOrMember)
{
ArgumentException.ThrowIfNullOrWhiteSpace(methodOrMember);
_name = methodOrMember.Trim();
return this;
}
/// <summary>Positional argument (expression wire — no type field).</summary>
public InvocationEntity Arg(string exprWire)
{
ArgumentException.ThrowIfNullOrWhiteSpace(exprWire);
_args.Add(new CallArg(null, exprWire.Trim()));
return this;
}
/// <summary>Named argument — projection emits lang form (csharp <c>name: expr</c>, py <c>name=expr</c>).</summary>
public InvocationEntity Arg(string name, string exprWire)
{
ArgumentException.ThrowIfNullOrWhiteSpace(name);
ArgumentException.ThrowIfNullOrWhiteSpace(exprWire);
_args.Add(new CallArg(name.Trim(), exprWire.Trim()));
return this;
}
public InvocationEntity Bind(string local)
{
ArgumentException.ThrowIfNullOrWhiteSpace(local);
_bind = local.Trim();
return this;
}
public ActIntent ToAct()
{
if (string.IsNullOrWhiteSpace(_receiver))
throw new InvalidOperationException("Invocation.On(receiver) is required");
if (string.IsNullOrWhiteSpace(_name))
throw new InvalidOperationException("Invocation.Named(method) is required");
return new CallAct(_receiver!, _name!, _args.ToArray(), _bind);
}
}
public static class Invocation
{
public static InvocationEntity On(string receiver) => new InvocationEntity().On(receiver);
/// <summary>Start from method Anchor — resolves to Type.Method (static) unless <see cref="InvocationEntity.On"/> set.</summary>
public static CallBuilder At(Anchor methodAnchor) => Act.Call(methodAnchor);
}