diff options
author | David Robillard <d@drobilla.net> | 2012-12-25 08:35:43 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-12-25 08:35:43 +0000 |
commit | 77d27b3495bfa98c5e13707903e4f885e8521ab6 (patch) | |
tree | b2cadb927fd0ab8732001fc77a580f1dffcd0744 /src/unify.cpp | |
parent | 12314c754187ae246bc38aceb827bf51d1669d73 (diff) | |
download | resp-77d27b3495bfa98c5e13707903e4f885e8521ab6.tar.gz resp-77d27b3495bfa98c5e13707903e4f885e8521ab6.tar.bz2 resp-77d27b3495bfa98c5e13707903e4f885e8521ab6.zip |
Support multiple ellipses in macros.
Support lambda expressions with empty argument lists.
git-svn-id: http://svn.drobilla.net/resp/trunk@445 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/unify.cpp')
-rw-r--r-- | src/unify.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/unify.cpp b/src/unify.cpp index f8ebe1d..9bb2f3c 100644 --- a/src/unify.cpp +++ b/src/unify.cpp @@ -66,12 +66,14 @@ substitute(const AST* in, const AST* from, const AST* to) return to; const ATuple* tup = in->to_tuple(); - if (!tup) + if (!tup || !tup->fst()) return from; List ret; for (const auto& i : *tup->as_tuple()) { - if (*i == *from) { + if (!i) { + continue; + } if (*i == *from) { ret.push_back(to); // FIXME: should be a copy w/ (*i)->loc } else if (i != to) { if (AType::is_expr(i)) @@ -123,7 +125,7 @@ Constraints::replace(const AST* s, const AST* t) } if (*c.second == *s) { c.second = t; // FIXME: should be copy w/ c.second->loc; - } else if (AType::is_expr(c.second)) { + } else if (AType::is_expr(c.second) && c.second->to_tuple()->fst()) { c.second = substitute(c.second, s, t); } } @@ -156,8 +158,10 @@ unify(const Constraints& constraints) for (; si != st->end() && ti != tt->end(); ++si, ++ti) { if (is_dots(*si) || is_dots(*ti)) return unify(cp); - else + else if (*si && *ti) cp.push_back(Constraint(*si, *ti)); + else + throw Error(Cursor(), "match with missing list element"); } if ((si == st->end() && ti == tt->end()) || (si != st->end() && is_dots(*si)) |