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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
package bjc.utils.ioutils.format;
import bjc.data.Pair;
import bjc.data.SimplePair;
/**
* A decree is the building blocks of what we need to pick and call a directive.
*
* Namely, it is the name of the directive, any modifiers attached to the
* directive, and any prefix parameters that are also attached to the directive.
*
* @author Ben Culkin.
*/
public class SimpleDecree implements Decree {
/**
* The name of the directive.
*/
public String name;
/**
* Is this directive an actual directive, or just a literal string?
*/
public boolean isLiteral;
/**
* Is this directive a user function call?
*/
public boolean isUserCall;
/**
* The prefix parameters for this directive.
*/
public CLParameters parameters;
/**
* The modifiers for this directive.
*/
public CLModifiers modifiers;
/**
* The position in the input this decree had
*/
public Pair<Integer, Integer> position;
/**
* Create a new blank decree.
*/
public SimpleDecree() {
}
/**
* Create a new literal text directive.
*
* @param txt
* The text of the directive.
*/
public SimpleDecree(String txt) {
this.name = txt;
this.isLiteral = true;
}
/**
* Create a new literal text directive.
*
* @param txt
* The text of the directive.
* @param start The starting position of this directive
* @param end The ending position of this directive
*/
public SimpleDecree(String txt, int start, int end) {
this(txt);
this.setPosition(start, end);
}
/**
* Create a new directive.
*
* @param name
* The name of the directive. Whether or not it is an actual
* directive will be auto-determined (if it starts with a ~, it's
* a directive.)
*
* @param params
* The prefix parameters to the directive.
*
* @param mods
* The modifiers to the directive.
*/
public SimpleDecree(String name, CLParameters params, CLModifiers mods) {
this.name = name;
this.parameters = params;
this.modifiers = mods;
this.isLiteral = false;
}
/**
* Create a new directive that may be a user function.
*
* @param name
* The name of the directive. Whether or not it is an actual
* directive will be auto-determined (if it starts with a ~ and is
* not a user function, it's a directive.)
*
* @param isUser
* Is this directive a user function?
*
* @param params
* The prefix parameters to the directive.
*
* @param mods
* The modifiers to the directive.
*/
public SimpleDecree(String name, boolean isUser, CLParameters params, CLModifiers mods) {
this.name = name;
this.parameters = params;
this.modifiers = mods;
this.isUserCall = isUser;
this.isLiteral = isUser;
}
/**
* Check if this decree is a non-literal, with a particular name.
*
* @param nam
* The name to see if we have.
*
* @return Whether or not the provided name equals our name.
*/
public boolean isNamed(String nam) {
// Literals don't have a meaningful name
if (isLiteral) return false;
else return name.equals(nam);
}
/**
* Set the position of this decree.
*
* @param start The starting position of this decree
* @param end The ending position of this decree
*/
public void setPosition(int start, int end) {
position = new SimplePair<>(start, end);
}
@Override
public String toString() {
return String.format(
"Decree [name='%s', isLiteral=%s, isUserCall=%s, parameters=%s, modifiers='%s']",
name, isLiteral, isUserCall, parameters, modifiers);
}
}
|