From 40986312bb00f0101a6634db42080daee03f887b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 2 Nov 2003 17:36:15 +0000 Subject: [PATCH] * Boolean constants. --- src/fix-ng/eval.cc | 7 ++++--- src/fix-ng/fix.sdf | 12 ++++++++++++ src/fix-ng/parser.cc | 6 ++++++ src/fix-ng/primops.cc | 4 ++-- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/fix-ng/eval.cc b/src/fix-ng/eval.cc index 38a1d81fc..726bc5dae 100644 --- a/src/fix-ng/eval.cc +++ b/src/fix-ng/eval.cc @@ -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()", &s1) || ATmatch(e, "Path()", &s1) || ATmatch(e, "Uri()", &s1) || + ATmatch(e, "Bool()", &e1) || ATmatch(e, "Function([], )", &e1, &e2) || ATmatch(e, "Attrs([])", &e1) || ATmatch(e, "List([])", &e1)) @@ -188,7 +189,7 @@ Expr evalExpr2(EvalState & state, Expr e) if (ATmatch(e, "OpEq(, )", &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. */ diff --git a/src/fix-ng/fix.sdf b/src/fix-ng/fix.sdf index 251a63f0c..8effe6d21 100644 --- a/src/fix-ng/fix.sdf +++ b/src/fix-ng/fix.sdf @@ -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] diff --git a/src/fix-ng/parser.cc b/src/fix-ng/parser.cc index d310397c2..7dff0363d 100644 --- a/src/fix-ng/parser.cc +++ b/src/fix-ng/parser.cc @@ -50,6 +50,12 @@ struct Cleanup : TermFun return ATmake("Int()", n); } + if (ATmatch(e, "Bool(\"true\")", &s)) + return ATmake("Bool(True)"); + + if (ATmatch(e, "Bool(\"false\")", &s)) + return ATmake("Bool(False)"); + return e; } }; diff --git a/src/fix-ng/primops.cc b/src/fix-ng/primops.cc index 7d060124b..f887d265f 100644 --- a/src/fix-ng/primops.cc +++ b/src/fix-ng/primops.cc @@ -84,8 +84,8 @@ static string processBinding(EvalState & state, Expr e, NixExpr & ne) if (ATmatch(e, "Str()", &s)) return s; if (ATmatch(e, "Uri()", &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([])", &es)) { Expr a = queryAttr(e, "type");