mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-14 02:06:16 +02:00
* Shorter list syntax ([a b c] instead of [a, b, c]).
This commit is contained in:
parent
ad0976f8d5
commit
e2655aa332
3 changed files with 15 additions and 8 deletions
|
@ -4,8 +4,6 @@
|
||||||
|
|
||||||
ATerm bottomupRewrite(TermFun & f, ATerm e)
|
ATerm bottomupRewrite(TermFun & f, ATerm e)
|
||||||
{
|
{
|
||||||
e = f(e);
|
|
||||||
|
|
||||||
if (ATgetType(e) == AT_APPL) {
|
if (ATgetType(e) == AT_APPL) {
|
||||||
AFun fun = ATgetAFun(e);
|
AFun fun = ATgetAFun(e);
|
||||||
int arity = ATgetArity(fun);
|
int arity = ATgetArity(fun);
|
||||||
|
@ -14,10 +12,10 @@ ATerm bottomupRewrite(TermFun & f, ATerm e)
|
||||||
for (int i = arity - 1; i >= 0; i--)
|
for (int i = arity - 1; i >= 0; i--)
|
||||||
args = ATinsert(args, bottomupRewrite(f, ATgetArgument(e, i)));
|
args = ATinsert(args, bottomupRewrite(f, ATgetArgument(e, i)));
|
||||||
|
|
||||||
return (ATerm) ATmakeApplList(fun, args);
|
e = (ATerm) ATmakeApplList(fun, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ATgetType(e) == AT_LIST) {
|
else if (ATgetType(e) == AT_LIST) {
|
||||||
ATermList in = (ATermList) e;
|
ATermList in = (ATermList) e;
|
||||||
ATermList out = ATempty;
|
ATermList out = ATempty;
|
||||||
|
|
||||||
|
@ -26,10 +24,10 @@ ATerm bottomupRewrite(TermFun & f, ATerm e)
|
||||||
in = ATgetNext(in);
|
in = ATgetNext(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (ATerm) ATreverse(out);
|
e = (ATerm) ATreverse(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
return e;
|
return f(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,9 @@ exports
|
||||||
Bind ";" -> BindSemi
|
Bind ";" -> BindSemi
|
||||||
BindSemi* -> Binds
|
BindSemi* -> Binds
|
||||||
|
|
||||||
"[" Expr* "]" -> Expr {cons("List")}
|
"[" ExprList "]" -> Expr {cons("List")}
|
||||||
|
"" -> ExprList {cons("ExprNil")}
|
||||||
|
Expr ExprList -> ExprList {cons("ExprCons")}
|
||||||
|
|
||||||
Expr "." Id -> Expr {cons("Select")}
|
Expr "." Id -> Expr {cons("Select")}
|
||||||
|
|
||||||
|
@ -58,7 +60,7 @@ exports
|
||||||
context-free priorities
|
context-free priorities
|
||||||
|
|
||||||
Expr "." Id -> Expr
|
Expr "." Id -> Expr
|
||||||
>
|
> Expr ExprList -> ExprList
|
||||||
> Expr Expr -> Expr
|
> Expr Expr -> Expr
|
||||||
> "{" {Id ","}* "}" ":" Expr -> Expr
|
> "{" {Id ","}* "}" ":" Expr -> Expr
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,13 @@ struct Cleanup : TermFun
|
||||||
if (ATmatch(e, "Bool(\"false\")", &s))
|
if (ATmatch(e, "Bool(\"false\")", &s))
|
||||||
return ATmake("Bool(False)");
|
return ATmake("Bool(False)");
|
||||||
|
|
||||||
|
if (ATmatch(e, "ExprNil"))
|
||||||
|
return (ATerm) ATempty;
|
||||||
|
|
||||||
|
ATerm e1, e2;
|
||||||
|
if (ATmatch(e, "ExprCons(<term>, [<list>])", &e1, &e2))
|
||||||
|
return (ATerm) ATinsert((ATermList) e2, e1);
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue