aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-02-04 16:49:51 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-02-04 16:49:51 +0000
commit9d25466b34a5f7c1c8b1c273976cf59c33961a6c (patch)
treeee4a5a60ae5de90fb301d75258ea627300065b2a /src
parent6d46e647ba16e19100dcd0abda9ca5a81ccf764f (diff)
* An attribute set update operator (//). E.g.,
{x=1; y=2; z=3;} // {y=4;} => {x=1; y=4; z=3;}
Diffstat (limited to 'src')
-rw-r--r--src/libexpr/eval.cc16
-rw-r--r--src/libexpr/lexer.l1
-rw-r--r--src/libexpr/parser.y2
3 files changed, 19 insertions, 0 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 802b83aa1..eaa4b4ea4 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -134,6 +134,18 @@ ATerm expandRec(ATerm e, ATermList rbnds, ATermList nrbnds)
}
+static Expr updateAttrs(Expr e1, Expr e2)
+{
+ /* Note: e1 and e2 should be in normal form. */
+
+ ATermMap attrs;
+ queryAllAttrs(e1, attrs);
+ queryAllAttrs(e2, attrs);
+
+ return makeAttrs(attrs);
+}
+
+
string evalString(EvalState & state, Expr e)
{
e = evalExpr(state, e);
@@ -264,6 +276,10 @@ Expr evalExpr2(EvalState & state, Expr e)
if (atMatch(m, e) >> "OpOr" >> e1 >> e2)
return makeBool(evalBool(state, e1) || evalBool(state, e2));
+ /* Attribut set update (//). */
+ if (atMatch(m, e) >> "OpUpdate" >> e1 >> e2)
+ return updateAttrs(evalExpr(state, e1), evalExpr(state, e2));
+
/* Barf. */
throw badTerm("invalid expression", e);
}
diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l
index 853362cd0..ce1c4673d 100644
--- a/src/libexpr/lexer.l
+++ b/src/libexpr/lexer.l
@@ -57,6 +57,7 @@ inherit { return INHERIT; }
\&\& { return AND; }
\|\| { return OR; }
\-\> { return IMPL; }
+\/\/ { return UPDATE; }
{ID} { yylval->t = ATmake("<str>", yytext); return ID; /* !!! alloc */ }
{INT} { int n = atoi(yytext); /* !!! overflow */
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index d97106fca..6c0fdbda2 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -42,6 +42,7 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, void * data, char * s)
%left OR
%left AND
%nonassoc EQ NEQ
+%right UPDATE
%left NEG
%%
@@ -69,6 +70,7 @@ expr_op
| expr_op AND expr_op { $$ = ATmake("OpAnd(<term>, <term>)", $1, $3); }
| 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_app
;