# Copyright 2005 Kevin Reid, under the terms of the MIT X license # found at http://www.opensource.org/licenses/mit-license.html ................ pragma.enable("easy-return") pragma.disable("explicit-result-guard") pragma.enable("accumulator") def Term := any # XXX restrict def AstroTag := any # XXX restrict def AstroArg := any # XXX restrict def makeBaseAstroBuilder := def makeTerm := def makeAstroTag := def makeTermBuilder implements DeepFrozen { to run() { # XXX schema parameter # XXX should be from schema def dataTags := accum [] for guard in [int, float64, char, String] { _.with(makeAstroTag(null, `.$guard.`, guard)) } /** XXX faked for now */ def schema { to obtainTagForName(name) { return makeAstroTag(null, name, nullOk) } } def termBuilder def baseBuilder := makeBaseAstroBuilder(termBuilder, schema, ["BAstroArg" => AstroArg, ]) bind termBuilder := def "termBuilder" extends baseBuilder { to empty() { return termBuilder.seq() } to term(functor :Term ? (functor.getArgs() == []), args :AstroArg) { # XXX args guard? return makeTerm(functor.getTag(), functor.getData(), null, switch (args) { match [] + l { l } match _ { args.getTerms() }}) } # XXX partially belongs to BaseBuilder in the Java system to leafTag(tag :AstroTag, optSpan :nullOk) { # XXX SourceSpan return makeTerm(tag, null, optSpan, []) } to leafData(data, optSpan :nullOk) { def [tag, cdata] := escape found { for tag ? (data =~ cdata :(tag.getDataGuard())) in dataTags { found([tag, cdata]) } throw(`no tag in schema for data: $data`) } return makeTerm(tag, cdata, optSpan, []) } to seq(single :Term) { # XXX right guard? return single } match [=="seq", args] { def termBuilderSeq { to getTerms() { return args } to __printOn(out :TextWriter) { out.write("termSeq`(") var sep := "" for arg in args { out.write(sep) if (arg =~ t :Term ? (t == arg)) { out.print(arg) } else { out.quote(arg) } sep := ", " } out.write(")`") } } } } return termBuilder } }