diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-03-28T21·15+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-03-28T21·15+0000 |
commit | ac4d39f9db28743b6c1e9def7a61241a50b02335 (patch) | |
tree | 85311119f03b0d44c8a2fe861706924349b792f1 | |
parent | f958bcdf1f9f66759a2512e4b7c0b0ba5647960a (diff) |
* Added an operator `?' to test for attribute existence, e.g.,
`attrs ? x' yields true iff `attrs' has an attribute named `x'.
-rw-r--r-- | src/libexpr/eval.cc | 9 | ||||
-rw-r--r-- | src/libexpr/parser.y | 2 |
2 files changed, 10 insertions, 1 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 2281ee7212c9..0623e4953239 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -288,10 +288,17 @@ Expr evalExpr2(EvalState & state, Expr e) if (atMatch(m, e) >> "OpOr" >> e1 >> e2) return makeBool(evalBool(state, e1) || evalBool(state, e2)); - /* Attribut set update (//). */ + /* Attribute set update (//). */ if (atMatch(m, e) >> "OpUpdate" >> e1 >> e2) return updateAttrs(evalExpr(state, e1), evalExpr(state, e2)); + /* Attribute existence test (?). */ + if (atMatch(m, e) >> "OpHasAttr" >> e1 >> name) { + ATermMap attrs; + queryAllAttrs(evalExpr(state, e1), attrs); + return makeBool(attrs.get(name) != 0); + } + /* Barf. */ throw badTerm("invalid expression", e); } diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index b1fe9e093145..cfcbc589f61c 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -44,6 +44,7 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, void * data, char * s) %nonassoc EQ NEQ %right UPDATE %left NEG +%nonassoc '?' %nonassoc '~' %% @@ -81,6 +82,7 @@ expr_op | expr_op IMPL expr_op { $$ = ATmake("OpImpl(<term>, <term>)", $1, $3); } | expr_op UPDATE expr_op { $$ = ATmake("OpUpdate(<term>, <term>)", $1, $3); } | expr_op '~' expr_op { $$ = ATmake("SubPath(<term>, <term>)", $1, $3); } + | expr_op '?' ID { $$ = ATmake("OpHasAttr(<term>, <term>)", $1, $3); } | expr_app ; |