mirror of
https://github.com/NixOS/nix.git
synced 2025-11-15 06:52:43 +01:00
* Drop ATmake / ATMatcher also in handling store expressions.
This commit is contained in:
parent
ed09821859
commit
a69534fc21
19 changed files with 118 additions and 258 deletions
|
|
@ -16,95 +16,6 @@ ostream & operator << (ostream & stream, ATerm e)
|
|||
}
|
||||
|
||||
|
||||
ATMatcher & atMatch(ATMatcher & pos, ATerm t)
|
||||
{
|
||||
pos.t = t;
|
||||
pos.pos = ATMatcher::funPos;
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
static inline bool failed(const ATMatcher & pos)
|
||||
{
|
||||
return pos.pos == ATMatcher::failPos;
|
||||
}
|
||||
|
||||
|
||||
static inline ATMatcher & fail(ATMatcher & pos)
|
||||
{
|
||||
pos.pos = ATMatcher::failPos;
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
ATMatcher & operator >> (ATMatcher & pos, ATerm & out)
|
||||
{
|
||||
out = 0;
|
||||
if (failed(pos)) return pos;
|
||||
if (pos.pos == ATMatcher::funPos ||
|
||||
ATgetType(pos.t) != AT_APPL ||
|
||||
pos.pos >= (int) ATgetArity(ATgetAFun(pos.t)))
|
||||
return fail(pos);
|
||||
out = ATgetArgument(pos.t, pos.pos);
|
||||
pos.pos++;
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
ATMatcher & operator >> (ATMatcher & pos, string & out)
|
||||
{
|
||||
out = "";
|
||||
if (pos.pos == ATMatcher::funPos) {
|
||||
if (ATgetType(pos.t) != AT_APPL) return fail(pos);
|
||||
out = ATgetName(ATgetAFun(pos.t));
|
||||
pos.pos = 0;
|
||||
} else {
|
||||
ATerm t;
|
||||
pos = pos >> t;
|
||||
if (failed(pos)) return pos;
|
||||
if (ATgetType(t) != AT_APPL ||
|
||||
ATgetArity(ATgetAFun(t)) != 0)
|
||||
return fail(pos);
|
||||
out = ATgetName(ATgetAFun(t));
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
ATMatcher & operator >> (ATMatcher & pos, const string & s)
|
||||
{
|
||||
string s2;
|
||||
pos = pos >> s2;
|
||||
if (failed(pos)) return pos;
|
||||
if (s != s2) return fail(pos);
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
ATMatcher & operator >> (ATMatcher & pos, int & n)
|
||||
{
|
||||
n = 0;
|
||||
ATerm t;
|
||||
pos = pos >> t;
|
||||
if (failed(pos)) return pos;
|
||||
if (ATgetType(t) != AT_INT) return fail(pos);
|
||||
n = ATgetInt((ATermInt) t);
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
ATMatcher & operator >> (ATMatcher & pos, ATermList & out)
|
||||
{
|
||||
out = 0;
|
||||
ATerm t;
|
||||
pos = pos >> t;
|
||||
if (failed(pos)) return pos;
|
||||
if (ATgetType(t) != AT_LIST) return fail(pos);
|
||||
out = (ATermList) t;
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
Error badTerm(const format & f, ATerm t)
|
||||
{
|
||||
char * s = ATwriteToString(t);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue