ERights Home elang / kernel 
Back to: Ignore Pattern On to: List Pattern

Such-That Pattern


Adds an arbitrary test to a pattern that must also be satisfied in order to have a successful match. If the left-hand pattern fails, the such-that pattern as a whole fails. If the left hand pattern succeeds, the right hand expression is evaluated to a boolean. If the boolean is true, the such-that pattern as a whole succeeds. If false, the match fails. Any other value results in a thrown exception.

Normal left to right execution and scoping both apply. The expression can use variables defined by the pattern, and variables defined by the expression are also available in the succeeding scope -- they are variables defined by the such-that pattern as a whole.

BNF:
pattern "?" eExpr
XML DTD:
<!ELEMENT suchThatPattern (%pattern;, %eExpr;)>
Java:

Patterns are expanded either for boolean or for exception. In the first case, there's a break_label to go to if we fail. In the second case, there's a variable holding the problem to throw. The pattern within the suchThatPattern inherits this same context. Following success of the inner pattern, we generate an

if (! jExpr) {
    //either
    break break_label;
    //or
    throw(problem);
}
Example:
See ifExpr
in Kernel-E:
 
in XML:
 
in Java:
 

 

x
 
Unless stated otherwise, all text on this page which is either unattributed or by Mark S. Miller is hereby placed in the public domain.
ERights Home elang / kernel 
Back to: Ignore Pattern On to: List Pattern
Download    FAQ    API    Mail Archive    Donate

report bug (including invalid html)

Golden Key Campaign Blue Ribbon Campaign