about summary refs log tree commit diff
path: root/src/libexpr/eval.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2010-03-25T12·19+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2010-03-25T12·19+0000
commit8a10360c912bc344ea9ce7f8871a47a6e036552f (patch)
tree09ed76a3e11754ee09c48cd491782848df169063 /src/libexpr/eval.cc
parent7482349fe8ba9f285f6c7e53d8573fc367ecff8b (diff)
* Simplify @-patterns: only `{attrs}@name' or `name@{attrs}' are now
  allowed.  So `name1@name2', `{attrs1}@{attrs2}' and so on are now no
  longer legal.  This is no big loss because they were not useful
  anyway.

  This also changes the output of builtins.toXML for @-patterns
  slightly.

Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r--src/libexpr/eval.cc15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index cd9c645947..1501fc0480 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -85,16 +85,17 @@ static void patternMatch(EvalState & state,
 {
     ATerm name;
     ATermList formals;
-    Pattern pat1, pat2;
     ATermBool ellipsis;
     
     if (matchVarPat(pat, name)) 
         subs.set(name, arg);
 
-    else if (matchAttrsPat(pat, formals, ellipsis)) {
+    else if (matchAttrsPat(pat, formals, ellipsis, name)) {
 
         arg = evalExpr(state, arg);
 
+        if (name != sNoAlias) subs.set(name, arg);
+
         /* Get the actual arguments. */
         ATermMap attrs;
         queryAllAttrs(arg, attrs);
@@ -131,11 +132,6 @@ static void patternMatch(EvalState & state,
                 % aterm2String(attrs.begin()->key));
     }
 
-    else if (matchAtPat(pat, pat1, pat2)) {
-        patternMatch(state, pat1, arg, subs, subsRecursive);
-        patternMatch(state, pat2, arg, subs, subsRecursive);
-    }
-
     else abort();
 }
 
@@ -425,12 +421,11 @@ Path coerceToPath(EvalState & state, Expr e, PathSet & context)
 Expr autoCallFunction(Expr e, const ATermMap & args)
 {
     Pattern pat;
-    ATerm body, pos;
+    ATerm body, pos, name;
     ATermList formals;
     ATermBool ellipsis;
     
-    /* !!! this should be more general */
-    if (matchFunction(e, pat, body, pos) && matchAttrsPat(pat, formals, ellipsis)) {
+    if (matchFunction(e, pat, body, pos) && matchAttrsPat(pat, formals, ellipsis, name)) {
         ATermMap actualArgs(ATgetLength(formals));
         
         for (ATermIterator i(formals); i; ++i) {