diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2008-08-14 10:04:22 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2008-08-14 10:04:22 +0000 |
commit | efe4b690ae4de5f0adea99abb1176a64a099d433 (patch) | |
tree | 3ee26b49848b04b5f6dad8edc06509fe4d4ee067 /src/libexpr/expr-to-xml.cc | |
parent | c03b729319997b4e38c3f586d7c76352228b22e7 (diff) |
* Refactoring: combine functions that take an attribute set and
functions that take a single argument (plain lambdas) into one AST
node (Function) that contains a Pattern node describing the
arguments. Current patterns are single lazy arguments (VarPat) and
matching against an attribute set (AttrsPat).
This refactoring allows other kinds of patterns to be added easily,
such as Haskell-style @-patterns, or list pattern matching.
Diffstat (limited to 'src/libexpr/expr-to-xml.cc')
-rw-r--r-- | src/libexpr/expr-to-xml.cc | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/src/libexpr/expr-to-xml.cc b/src/libexpr/expr-to-xml.cc index c47f24e6c..5aa537b20 100644 --- a/src/libexpr/expr-to-xml.cc +++ b/src/libexpr/expr-to-xml.cc @@ -40,6 +40,23 @@ static void showAttrs(const ATermMap & attrs, XMLWriter & doc, } +static void printPatternAsXML(Pattern pat, XMLWriter & doc, PathSet & context) +{ + ATerm name; + ATermList formals; + if (matchVarPat(pat, name)) + doc.writeEmptyElement("varpat", singletonAttrs("name", aterm2String(name))); + else if (matchAttrsPat(pat, formals)) { + XMLOpenElement _(doc, "attrspat"); + for (ATermIterator i(formals); i; ++i) { + Expr name; ATerm dummy; + if (!matchFormal(*i, name, dummy)) abort(); + doc.writeEmptyElement("attr", singletonAttrs("name", aterm2String(name))); + } + } +} + + static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context, ExprSet & drvsSeen) { @@ -47,8 +64,8 @@ static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context, string s; ATerm s2; int i; - ATermList as, es, formals; - ATerm body, pos; + ATermList as, es; + ATerm pat, body, pos; checkInterrupt(); @@ -109,14 +126,9 @@ static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context, printTermAsXML(*i, doc, context, drvsSeen); } - else if (matchFunction(e, formals, body, pos)) { + else if (matchFunction(e, pat, body, pos)) { XMLOpenElement _(doc, "function"); - - for (ATermIterator i(formals); i; ++i) { - Expr name; ATerm dummy; - if (!matchFormal(*i, name, dummy)) abort(); - XMLOpenElement _(doc, "arg", singletonAttrs("name", aterm2String(name))); - } + printPatternAsXML(pat, doc, context); } else |