about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libexpr/eval.cc1
-rw-r--r--src/libexpr/parser.y2
-rw-r--r--src/libexpr/primops.cc13
3 files changed, 16 insertions, 0 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index b4d76a137a1a..2281ee7212c9 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -190,6 +190,7 @@ Expr evalExpr2(EvalState & state, Expr e)
     if (atMatch(m, e) >> cons &&
         (cons == "Str" ||
          cons == "Path" ||
+         cons == "SubPath" ||
          cons == "Uri" ||
          cons == "Null" ||
          cons == "Int" ||
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index 44d1e06abefa..b1fe9e093145 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 '~'
 
 %%
 
@@ -79,6 +80,7 @@ expr_op
   | expr_op OR expr_op { $$ = ATmake("OpOr(<term>, <term>)", $1, $3); }
   | 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_app
   ;
 
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 6c2bb33e461f..5aefa5b411b0 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -85,6 +85,7 @@ static void processBinding(EvalState & state, Expr e, StoreExpr & ne,
     string s;
     ATermList es;
     int n;
+    Expr e1, e2;
 
     if (atMatch(m, e) >> "Str" >> s) ss.push_back(s);
     else if (atMatch(m, e) >> "Uri" >> s) ss.push_back(s);
@@ -128,6 +129,18 @@ static void processBinding(EvalState & state, Expr e, StoreExpr & ne,
     }
 
     else if (atMatch(m, e) >> "Null") ss.push_back("");
+
+    else if (atMatch(m, e) >> "SubPath" >> e1 >> e2) {
+        Strings ss2;
+        processBinding(state, evalExpr(state, e1), ne, ss2);
+        if (ss2.size() != 1)
+            throw Error("left-hand side of `~' operator cannot be a list");
+        e2 = evalExpr(state, e2);
+        if (!(atMatch(m, e2) >> "Str" >> s ||
+             (atMatch(m, e2) >> "Path" >> s)))
+            throw Error("right-hand side of `~' operator must be a path or string");
+        ss.push_back(canonPath(ss2.front() + "/" + s));
+    }
     
     else throw badTerm("invalid derivation binding", e);
 }