1 module gamma.grammar.affixes.Signature;
2 
3 import gamma.grammar.affixes.Mode;
4 import gamma.grammar.Nonterminal;
5 import gamma.util.Position;
6 import std.range;
7 
8 public class Signature
9 {
10     private const Mode[] modes_;
11 
12     private Nonterminal[] domains_;
13 
14     private Position position_;
15 
16     public this(Mode[] modes, Nonterminal[] domains, Position position)
17     in (modes.length == domains.length)
18     {
19         this.modes_ = modes.dup;
20         this.domains_ = domains.dup;
21         this.position_ = position;
22     }
23 
24     public this(Position position)
25     {
26         this.modes_ = null;
27         this.position_ = position;
28     }
29 
30     public override string toString() const
31     {
32         import std.array : appender;
33         import std.conv : to;
34 
35         auto buffer = appender!string();
36 
37         buffer.put('<');
38         foreach (i; 0 .. length)
39         {
40             if (i > 0)
41                 buffer.put(", ");
42             buffer.put(this.modes_[i].to!string);
43             buffer.put(' ');
44             buffer.put(this.domains_[i].toString);
45         }
46         buffer.put('>');
47         return buffer[];
48     }
49 
50     public size_t length() const
51     {
52         return this.domains_.length;
53     }
54 
55     public bool isEmpty() const
56     {
57         return this.domains_.empty;
58     }
59 
60     public const(Mode)[] modes() const
61     {
62         return this.modes_;
63     }
64 
65     public Nonterminal[] domains()
66     {
67         return this.domains_;
68     }
69 
70     public Position position()
71     {
72         return this.position_;
73     }
74 }