* Boolean constants.

This commit is contained in:
Eelco Dolstra 2003-11-02 17:36:15 +00:00
parent adf9a45469
commit 40986312bb
4 changed files with 24 additions and 5 deletions

View file

@ -109,8 +109,8 @@ Path evalPath(EvalState & state, Expr e)
bool evalBool(EvalState & state, Expr e)
{
e = evalExpr(state, e);
if (ATmatch(e, "True")) return true;
else if (ATmatch(e, "False")) return false;
if (ATmatch(e, "Bool(True)")) return true;
else if (ATmatch(e, "Bool(False)")) return false;
else throw badTerm("expecting a boolean", e);
}
@ -124,6 +124,7 @@ Expr evalExpr2(EvalState & state, Expr e)
if (ATmatch(e, "Str(<str>)", &s1) ||
ATmatch(e, "Path(<str>)", &s1) ||
ATmatch(e, "Uri(<str>)", &s1) ||
ATmatch(e, "Bool(<term>)", &e1) ||
ATmatch(e, "Function([<list>], <term>)", &e1, &e2) ||
ATmatch(e, "Attrs([<list>])", &e1) ||
ATmatch(e, "List([<list>])", &e1))
@ -188,7 +189,7 @@ Expr evalExpr2(EvalState & state, Expr e)
if (ATmatch(e, "OpEq(<term>, <term>)", &e1, &e2)) {
string s1 = evalString(state, e1);
string s2 = evalString(state, e2);
return s1 == s2 ? ATmake("True") : ATmake("False");
return s1 == s2 ? ATmake("Bool(True)") : ATmake("Bool(False)");
}
/* Barf. */

View file

@ -68,6 +68,9 @@ exports
Expr "==" Expr
-> Expr {cons("OpEq")}
Bool
-> Expr {cons("Bool")}
context-free priorities
Expr "." Id -> Expr
@ -84,10 +87,19 @@ exports
lexical syntax
[a-zA-Z\_][a-zA-Z0-9\_\']* -> Id
"rec" -> Id {reject}
"true" -> Id {reject}
"false" -> Id {reject}
[0-9]+ -> Int
"\"" ~[\n\"]* "\"" -> Str
PathComp ("/" PathComp)+ -> Path
[a-zA-Z0-9\.\_\-]+ -> PathComp
"true" -> Bool
"false" -> Bool
lexical restrictions
Id -/- [a-zA-Z0-9\_\']
Int -/- [0-9]

View file

@ -50,6 +50,12 @@ struct Cleanup : TermFun
return ATmake("Int(<int>)", n);
}
if (ATmatch(e, "Bool(\"true\")", &s))
return ATmake("Bool(True)");
if (ATmatch(e, "Bool(\"false\")", &s))
return ATmake("Bool(False)");
return e;
}
};

View file

@ -84,8 +84,8 @@ static string processBinding(EvalState & state, Expr e, NixExpr & ne)
if (ATmatch(e, "Str(<str>)", &s)) return s;
if (ATmatch(e, "Uri(<str>)", &s)) return s;
if (ATmatch(e, "True")) return "1";
if (ATmatch(e, "False")) return "";
if (ATmatch(e, "Bool(True)")) return "1";
if (ATmatch(e, "Bool(False)")) return "";
if (ATmatch(e, "Attrs([<list>])", &es)) {
Expr a = queryAttr(e, "type");