# Copyright 2005-2007 Kevin Reid, under the terms of the MIT X license # found at http://www.opensource.org/licenses/mit-license.html ................ pragma.syntax("0.9") pragma.enable("accumulator") def SourceSpan :DeepFrozen := .asType() def EventuallyDeepFrozen :()[DeepFrozen."eventually"()] := DeepFrozen."eventually"() def Term :DeepFrozen := any # XXX restrict def AstroTag :DeepFrozen := any # XXX restrict def AstroArg :DeepFrozen := any # XXX restrict def makeBaseAstroBuilder :DeepFrozen := def makeTerm :DeepFrozen := def makeAstroTag :DeepFrozen := def makeTermBuilder implements DeepFrozen, ExitViaHere { 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 implements DeepFrozen { to obtainTagForName(name) { return makeAstroTag(null, name, nullOk) } } def termBuilder def baseBuilder := makeBaseAstroBuilder(termBuilder, schema, ["BAstroArg" => AstroArg, ]) bind termBuilder extends baseBuilder implements EventuallyDeepFrozen { method __optSealedDispatch(brand) :any { if (brand == EventuallyDeepFrozen.getPeekBrand()) { EventuallyDeepFrozen.getPeekSealer().seal(meta.getState()) } } 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[SourceSpan]) { return makeTerm(tag, null, optSpan, []) } to leafData(data, optSpan :nullOk[SourceSpan]) { 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 } }