5
namespace VQDR.Expression {
6
public abstract class FunctionToken : Token {
7
protected FunctionToken () {
11
// We only store the type, as that is what is important.
12
private static Gee.HashMap<string, Type?> _allowed_functions;
14
protected const long UNDEFINED = long.MIN + 1; //+1 so that I can still use Long.MIN_VALUE.
16
protected const string CH_RARR = "\u2192";
18
protected const string CH_LARR = "\u2190";
19
/** Round up open bracket */
20
protected const string CH_RUP_OP = "\u2308";
21
/** Round up closed bracket */
22
protected const string CH_RUP_CL = "\u2309";
23
/** Round down open bracket */
24
protected const string CH_RDN_OP = "\u230a";
25
/** Round down closed bracket */
26
protected const string CH_RDN_CL = "\u230b";
27
/** Absolute open bracket */
28
protected const string CH_ABS_OP = "|";
29
/** Absolute closed bracket */
30
protected const string CH_ABS_CL = "|";
32
protected const string CH_GT = ">";
34
protected const string CH_LT = "<";
36
protected const string CH_EQUAL = "=";
38
/** Begin of a complex result */
39
protected const string SYM_BEGIN = "[";
40
/** End of a complex result */
41
protected const string SYM_END = "]";
42
/** Begin of a complex result, alternative */
43
protected const string SYM_BEGIN_ALT = "{";
44
/** End of a complex result, alternative */
45
protected const string SYM_END_ALT = "}";
46
/** Separator for different roll result */
47
protected const string SYM_SEP = ",";
48
/** Separator for different value of same roll */
49
protected const string SYM_SEP_SAME = ":";
50
/** Separator for overall (fumble, critical, botch, glitch) */
51
protected const string SYM_SEP_ = "\u2261"; //"=" (with 3 lines)
52
/** Denotes a success */
53
protected const string SYM_SUCCESS = "!";
54
/** Denotes a failure */
55
protected const string SYM_FAILURE = "*";
56
/** Denotes an extra result */
57
protected const string SYM_EXTRA = "!";
58
/** Denotes a selected result */
59
protected const string SYM_SELECTED = "!";
60
/** Separator for exploding rolls */
61
protected const string SYM_EXPLODE = "\u00bb"; //">>"
63
/** Truncated output: ellipsis */
64
protected const string SYM_TRUNK_PART_ELLIPSIS = "\u2026"; //"..."
65
/** Truncated output: equal */
66
protected const string SYM_TRUNK_PART_EQUAL = CH_EQUAL; //"="
67
/** Truncated output: begin */
68
protected const string SYM_TRUNK_BEGIN = SYM_BEGIN + SYM_TRUNK_PART_ELLIPSIS + SYM_TRUNK_PART_EQUAL; //"[...="
69
/** Truncated output: end */
70
protected const string SYM_TRUNK_END = SYM_END; //"]"
73
_allowed_functions = new Gee.HashMap<string, Type?> ();
74
this.priority = PRIO_FUNCTION;
78
* Ititialise the right functon token by it's name.
80
* @param token Token of the Function.
81
* @param position Token position.
82
* @return An instance representing the function, or @c null if not found.
84
public static FunctionToken? init_token (string token, int position) {
85
FunctionToken? retval = null;
87
// We get the token type.
88
Type? t = _allowed_functions.@get (token.down ());
91
// Construct a new instance of the token.
92
retval = (FunctionToken) GLib.Object.@new (t, null, null);
100
* Add a FunctionToken Type to the list of allowed functions.
102
* Note: The Type must be derived from FunctionToken, as there is an
103
* assert that chkecks.
105
public static void add_function (string token, Type t) {
106
assert (t.is_a (typeof (FunctionToken)) == true);
107
_allowed_functions.@set (token, t);
110
public static string get_function_name (Type t) {
111
assert (t.is_a (typeof (FunctionToken)) == true);
112
string ret_val = null;
114
_allowed_functions.map_iterator ().@foreach ((k,v) => {
125
protected long get_optional_child_raw_result (Context instance,
129
Token? tmp_roll = get_child (index);
131
if (tmp_roll != null) {
132
tmp_roll.evaluate (instance);
133
return tmp_roll.result_value;
135
return default_result;