diff options
Diffstat (limited to 'support/arara/source/src/main/kotlin/org/islandoftex/arara/ruleset/Conditional.kt')
-rw-r--r-- | support/arara/source/src/main/kotlin/org/islandoftex/arara/ruleset/Conditional.kt | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/support/arara/source/src/main/kotlin/org/islandoftex/arara/ruleset/Conditional.kt b/support/arara/source/src/main/kotlin/org/islandoftex/arara/ruleset/Conditional.kt new file mode 100644 index 0000000000..8a4ec6cb35 --- /dev/null +++ b/support/arara/source/src/main/kotlin/org/islandoftex/arara/ruleset/Conditional.kt @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: BSD-3-Clause +package org.islandoftex.arara.ruleset + +/** + * The conditional class, it represents the type of conditional available + * for a directive and its corresponding expression to be evaluated. + * + * @author Island of TeX + * @version 5.0 + * @since 4.0 + */ +data class Conditional( + /** + * The type of the condition indicates the meaning when evaluated. + * Defaults to [ConditionalType.NONE]. + */ + val type: ConditionalType = ConditionalType.NONE, + /** + * The expression to be evaluated according to its type. Defaults + * to no evaluation (empty string). + */ + val condition: String = "" +) { + /** + * The types of conditionals arara is able to recognize. + */ + enum class ConditionalType { + /** + * Evaluated beforehand, directive is interpreted if and only if the + * result is true. + */ + IF, + /** + * There is no evaluation, directive is interpreted, no extra effort is + * needed. + */ + NONE, + /** + * Evaluated beforehand, directive is interpreted if and only if the + * result is false. + */ + UNLESS, + /** + * Directive is interpreted the first time, then the evaluation is + * done; while the result is false, the directive is interpreted again + * and again. + */ + UNTIL, + /** + * Evaluated beforehand, directive is interpreted if and only if the + * result is true, and the process is repeated while the result still + * holds true. + */ + WHILE + } + + /** + * Provides a textual representation of the conditional object. + * @return A string representation of this object. + */ + override fun toString(): String { + return "{ $type" + + if (type != ConditionalType.NONE) + ", expression: ${condition.trim()}" + else "" + " }" + } +} |