aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/parser.y
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2010-03-25 12:19:41 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2010-03-25 12:19:41 +0000
commit8a10360c912bc344ea9ce7f8871a47a6e036552f (patch)
tree09ed76a3e11754ee09c48cd491782848df169063 /src/libexpr/parser.y
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/parser.y')
-rw-r--r--src/libexpr/parser.y45
1 files changed, 20 insertions, 25 deletions
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index 8706ce025..e55dfd76f 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -140,31 +140,29 @@ static Expr fixAttrs(bool recursive, ATermList as)
static void checkPatternVars(ATerm pos, ATermMap & map, Pattern pat)
{
- ATerm name;
+ ATerm name = sNoAlias;
ATermList formals;
- Pattern pat1, pat2;
ATermBool ellipsis;
- if (matchVarPat(pat, name)) {
- if (map.get(name))
- throw ParseError(format("duplicate formal function argument `%1%' at %2%")
- % aterm2String(name) % showPos(pos));
- map.set(name, name);
- }
- else if (matchAttrsPat(pat, formals, ellipsis)) {
+
+ if (matchAttrsPat(pat, formals, ellipsis, name)) {
for (ATermIterator i(formals); i; ++i) {
- ATerm d1;
- if (!matchFormal(*i, name, d1)) abort();
- if (map.get(name))
+ ATerm d1, name2;
+ if (!matchFormal(*i, name2, d1)) abort();
+ if (map.get(name2))
throw ParseError(format("duplicate formal function argument `%1%' at %2%")
- % aterm2String(name) % showPos(pos));
- map.set(name, name);
+ % aterm2String(name2) % showPos(pos));
+ map.set(name2, name2);
}
}
- else if (matchAtPat(pat, pat1, pat2)) {
- checkPatternVars(pos, map, pat1);
- checkPatternVars(pos, map, pat2);
+
+ else matchVarPat(pat, name);
+
+ if (name != sNoAlias) {
+ if (map.get(name))
+ throw ParseError(format("duplicate formal function argument `%1%' at %2%")
+ % aterm2String(name) % showPos(pos));
+ map.set(name, name);
}
- else abort();
}
@@ -323,7 +321,7 @@ static void freeAndUnprotect(void * p)
%type <t> start expr expr_function expr_if expr_op
%type <t> expr_app expr_select expr_simple bind inheritsrc formal
-%type <t> pattern pattern2
+%type <t> pattern
%type <ts> binds ids attrpath expr_list string_parts ind_string_parts
%type <formals> formals
%token <t> ID INT STR IND_STR PATH URI
@@ -433,13 +431,10 @@ ind_string_parts
;
pattern
- : pattern2 '@' pattern { $$ = makeAtPat($1, $3); }
- | pattern2
- ;
-
-pattern2
: ID { $$ = makeVarPat($1); }
- | '{' formals '}' { $$ = makeAttrsPat($2.formals, $2.ellipsis ? eTrue : eFalse); }
+ | '{' formals '}' { $$ = makeAttrsPat($2.formals, $2.ellipsis ? eTrue : eFalse, sNoAlias); }
+ | '{' formals '}' '@' ID { $$ = makeAttrsPat($2.formals, $2.ellipsis ? eTrue : eFalse, $5); }
+ | ID '@' '{' formals '}' { $$ = makeAttrsPat($4.formals, $4.ellipsis ? eTrue : eFalse, $1); }
;
binds