[e-lang] XML support in E
Mark Miller
erights at gmail.com
Sat Jan 16 18:01:23 PST 2010
On Sat, Jan 16, 2010 at 5:19 PM, Kevin Reid <kpreid at mac.com> wrote:
>
> That does seem like something I might have written, but I don't recall
> where I might have done so. I did write a guard called Termish, but it
> was just an incidental example of using trinary-define; what it did
> was match recursive trees of ["tagname", subterms...].
> http://www.eros-os.org/pipermail/e-lang/2005-August/010942.html
>
> Now that I see it, I'm rather sure that is what I was remembering. But it
inspired a good solution:
def AntiTerm {
to coerce(specimen, optEjector) {
if (specimen.getOptData() =~ data :notNull) { return data }
def term`@{tag :String}(@{args :List[AntiTerm]}*)` exit optEjector
:=
specimen
if (tag == ".tuple.") { return args }
if (tag == ".bag.") {
def result := [].asMap().diverge()
for arg in args {
if (arg =~ [`.attr.`, key, value]) {
result[key] := value
} else {
return [tag] + args
}
}
return result.snapshot()
}
return [tag] + args
}
}
? term`{[1,2]:[3,4], foo:oo(bar)}` :AntiTerm
# value: [[1, 2] => [3, 4], ["foo"] => ["oo", ["bar"]]]
--
Text by me above is hereby placed in the public domain
Cheers,
--MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.eros-os.org/pipermail/e-lang/attachments/20100116/2bccb346/attachment.html
More information about the e-lang
mailing list