This commit is contained in:
2025-01-04 00:34:03 +01:00
parent 41829408dc
commit 0ca14bbc19
18111 changed files with 1871397 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
import RollTerm from "./term.mjs";
/**
* A type of RollTerm used to denote and perform an arithmetic operation.
* @extends {RollTerm}
*/
export default class OperatorTerm extends RollTerm {
constructor({operator, options}={}) {
super({options});
this.operator = operator;
}
/**
* The term's operator value.
* @type {string}
*/
operator;
/**
* An object of operators with their precedence values.
* @type {Readonly<Record<string, number>>}
*/
static PRECEDENCE = Object.freeze({
"+": 10,
"-": 10,
"*": 20,
"/": 20,
"%": 20
});
/**
* An array of operators which represent arithmetic operations
* @type {string[]}
*/
static OPERATORS = Object.keys(this.PRECEDENCE);
/** @inheritdoc */
static REGEXP = new RegExp(this.OPERATORS.map(o => "\\"+o).join("|"), "g");
/** @inheritdoc */
static SERIALIZE_ATTRIBUTES = ["operator"];
/** @inheritdoc */
get flavor() {
return ""; // Operator terms cannot have flavor text
}
/** @inheritdoc */
get expression() {
return ` ${this.operator} `;
}
/** @inheritdoc */
get total() {
return ` ${this.operator} `;
}
}