Tag Expressions: Difference between revisions
No edit summary |
|||
Line 27: | Line 27: | ||
==Examples== | ==Examples== | ||
The following are a | The following are a couple of sample expressions utilizing parenthetical sub-expressions and combinations of the above operators. | ||
<pre> | |||
(TRUE & FALSE) ^ (TRUE & TRUE) ^ (FALSE & FALSE) | (TRUE & FALSE) ^ (TRUE & TRUE) ^ (FALSE & FALSE) | ||
</pre> | |||
Evaluates to | :Evaluates to "true". The first term evaluates to "false" and the second term evaluates to "true". The Xor of "true" and "false" (the first two terms) yields "true". The third term evaluates to "false". The Xor of "true" and "false" (the result of the first Xor and the third term) yields "true". | ||
TRUE ^ !(FALSE | TRUE) | TRUE ^ !(FALSE | TRUE) | ||
Evaluates to “true”. The sub-expression “(FALSE | TRUE)” evaluates to “true”. The negation of the sub-expression yields “false”. The Xor of “true” and the negated sub-expression result of “false” yields “true”. | Evaluates to “true”. The sub-expression “(FALSE | TRUE)” evaluates to “true”. The negation of the sub-expression yields “false”. The Xor of “true” and the negated sub-expression result of “false” yields “true”. |
Revision as of 12:04, 17 November 2008
[Context: HL Kit … Basic Concepts and Terminology … Tags and Tag Expressions]
Overview
Combinations of tags indicate meta-characteristics of an object. Tag expressions are the mechanism through which objects with specific combinations of attributes can be identified. Specifically, tag expressions are Boolean expressions that delineate a combination of tags that an object must possess. For example, a tag expression could easily be used to determine if an object is a "first-level wizard spell". Separate tag groups could be defined that identify the "class" of the object (fighter, wizard, etc.) and the "level" of the object (1st, 2nd, etc.). An additional tag group could be defined that identifies the "type" of the object (e.g. spell, weapon, skill, etc.). A tag expression could then be written to identify all objects that possess tags for all three characteristics: the "class.wizard" tag, the "level.1" tag, and the "type.spell" tag.
Syntax
Tag expressions are Boolean expressions comprised of tag terms. The tag expression evaluates each of the tag terms against a particular object to determine whether the object does or does not match the criteria. These terms are then combined using Boolean logic, where the expression specifies the relationships to use. Four Boolean operators are supported, and parentheses may be freely used to define appropriate groupings of sub-expressions. The operators supported are outlined below.
& Logical "And". Evaluates the two terms on either side and returns "true" only if both terms are "true". Example: "term1 & term2". | Logical "Or". Evaluates the two terms on either side and returns "true" if either of the terms is "true". Example: "term1 | term2". ^ Logical "Xor". Evaluates the two terms on either side and returns "true" if exactly one of the terms is "true". Example: "term1 ^ term2". ! Logical "Not". Evaluates the following term and returns "true" if that term is "false". Otherwise, it returns "false". Example: "!term1".
Examples
The following are a couple of sample expressions utilizing parenthetical sub-expressions and combinations of the above operators.
(TRUE & FALSE) ^ (TRUE & TRUE) ^ (FALSE & FALSE)
- Evaluates to "true". The first term evaluates to "false" and the second term evaluates to "true". The Xor of "true" and "false" (the first two terms) yields "true". The third term evaluates to "false". The Xor of "true" and "false" (the result of the first Xor and the third term) yields "true".
TRUE ^ !(FALSE | TRUE)
Evaluates to “true”. The sub-expression “(FALSE | TRUE)” evaluates to “true”. The negation of the sub-expression yields “false”. The Xor of “true” and the negated sub-expression result of “false” yields “true”.