forked from lix-project/lix
* Primops: baseNameOf, toString.
This commit is contained in:
parent
c8268ca991
commit
adf9a45469
|
@ -145,6 +145,8 @@ Expr evalExpr2(EvalState & state, Expr e)
|
||||||
string primop(s1);
|
string primop(s1);
|
||||||
if (primop == "import") return primImport(state, e2);
|
if (primop == "import") return primImport(state, e2);
|
||||||
if (primop == "derivation") return primDerivation(state, e2);
|
if (primop == "derivation") return primDerivation(state, e2);
|
||||||
|
if (primop == "toString") return primToString(state, e2);
|
||||||
|
if (primop == "baseNameOf") return primBaseNameOf(state, e2);
|
||||||
else throw badTerm("undefined variable/primop", e1);
|
else throw badTerm("undefined variable/primop", e1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,10 +30,6 @@ static Path searchPath(const Paths & searchDirs, const Path & relPath)
|
||||||
#if 0
|
#if 0
|
||||||
static Expr evalExpr2(EvalState & state, Expr e)
|
static Expr evalExpr2(EvalState & state, Expr e)
|
||||||
{
|
{
|
||||||
/* Conditional. */
|
|
||||||
if (ATmatch(e, "If(<term>, <term>, <term>)", &e1, &e2, &e3)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Ad-hoc function for string matching. */
|
/* Ad-hoc function for string matching. */
|
||||||
if (ATmatch(e, "HasSubstr(<term>, <term>)", &e1, &e2)) {
|
if (ATmatch(e, "HasSubstr(<term>, <term>)", &e1, &e2)) {
|
||||||
e1 = evalExpr(state, e1);
|
e1 = evalExpr(state, e1);
|
||||||
|
|
|
@ -204,3 +204,22 @@ Expr primDerivation(EvalState & state, Expr args)
|
||||||
|
|
||||||
return makeAttrs(attrs);
|
return makeAttrs(attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Expr primBaseNameOf(EvalState & state, Expr arg)
|
||||||
|
{
|
||||||
|
string s = evalString(state, arg);
|
||||||
|
return ATmake("Str(<str>)", baseNameOf(s).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Expr primToString(EvalState & state, Expr arg)
|
||||||
|
{
|
||||||
|
arg = evalExpr(state, arg);
|
||||||
|
char * s;
|
||||||
|
if (ATmatch(arg, "Str(<str>)", &s) ||
|
||||||
|
ATmatch(arg, "Path(<str>)", &s) ||
|
||||||
|
ATmatch(arg, "Uri(<str>)", &s))
|
||||||
|
return ATmake("Str(<str>)", s);
|
||||||
|
else throw badTerm("cannot coerce to string", arg);
|
||||||
|
}
|
||||||
|
|
|
@ -19,4 +19,13 @@ Expr primImport(EvalState & state, Expr arg);
|
||||||
Expr primDerivation(EvalState & state, Expr args);
|
Expr primDerivation(EvalState & state, Expr args);
|
||||||
|
|
||||||
|
|
||||||
|
/* Return the base name of the given string, i.e., everything
|
||||||
|
following the last slash. */
|
||||||
|
Expr primBaseNameOf(EvalState & state, Expr arg);
|
||||||
|
|
||||||
|
|
||||||
|
/* Convert the argument (which can be a path or a uri) to a string. */
|
||||||
|
Expr primToString(EvalState & state, Expr arg);
|
||||||
|
|
||||||
|
|
||||||
#endif /* !__PRIMOPS_H */
|
#endif /* !__PRIMOPS_H */
|
||||||
|
|
Loading…
Reference in a new issue