The work on integrating JavaScript has got me refactoring the scripting system, and effectively rewriting the plist script parser in the process. I’m currently implementing conditional statements, so now seems a good time to look over that functionality.
As it stands, and as I understand it (I haven’t done any serious OXP scripting; feel free to correct me), a conditional clause consists of an array of conditions. Each condition has one of these forms:
<testable_variable> "undefined"
<testable_variable> "one_of" <number_list> (I don’t think that one’s documented; it’s something dajt added)
<testable_variable> <logical_operator> <constant_expression>
A testable_variable is a string of the form local_foo or mission_foo, or a method selector (property accessor) of the form foo_string, foo_number or foo_bool.
A constant_expression is a testable_variable or a literal (e.g., 42.3, YES or STATUS_DOCKED).
A logical_operator is one of: equal, lessthan, greaterThan or morethan (the last two being synonyms).
Some very easy extensions to this would be:
- Removing the syntactic distinction between testable_variable and constant_expression. This probably wouldn’t be useful, but would slightly simplify the implementation and documentation.
- New operators: defined (inverse of undefined), notoneof (inverse of oneof), notequal, lessthanorequal, greaterthanorequal, or, and, andnot, ornot, xor (exclusive or, i.e. one or the other, but not both).
- Mixed-case operators (greaterThanOrEqual as a synonym for greaterthanorequal).
- Symbolic operators: =, !=, <, >, <=, >=, &, |, &!, |!, ? (for defined), !? (for undefined).
<condition_term> <unary_operator>
<condition_term> <binary_operator> <condition_term>
A unary_operator being one of:
- defined, ?
- undefined, unDefined, !?
- equal, =
- notequal, notEqual, !=
- lessthan, lessThan, <
- greaterthan, greaterThan, morethan, moreThan, >
- lessthanorequal, lessThanOrEqual, <=
- greaterthanorequal, greaterThanOrEqual, morethanorequal, moreThanOrEqual, >=
- and, &
- or, |
- andnot, andNot, &!
- ornot, orNot, |!
- oneof, oneOf
- notoneof, notOneOf