X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Fmeta%2FProduction.java;h=08588d9c3e953cb9bbbbc699d8ee06a20caa9c9a;hp=117eb57b4ee95a6ffbfdf104efe0f10cd954e26b;hb=6e639c9ed89dfda4b14ac4c768e66d25b91f5037;hpb=6777617313e957d0838a23ebf17ae0d9693ee225 diff --git a/src/edu/berkeley/sbp/meta/Production.java b/src/edu/berkeley/sbp/meta/Production.java index 117eb57..08588d9 100644 --- a/src/edu/berkeley/sbp/meta/Production.java +++ b/src/edu/berkeley/sbp/meta/Production.java @@ -78,4 +78,37 @@ public class Production { } } + public boolean isCompatible(Object o) { return isCompatible(Bindable.create(o)); } + public boolean isCompatible(Bindable _bindable) { + bind.as t = _bindable.getAnnotation(bind.as.class); + bind b = _bindable.getAnnotation(bind.class); + + boolean ok = false; + if (t != null && (t.value().equals(tag))) ok = true; + if (t != null && ((t.value().equals("") && _bindable.getSimpleName().equals(tag)))) ok = true; + if (b != null && _bindable.getSimpleName().equals(tag)) ok = true; + + if (ok) return buildSequence(_bindable)!=null; + + return false; + } + + public Sequence makeSequence(Object o) { return makeSequence(Bindable.create(o)); } + public Sequence makeSequence(final Bindable _bindable) { + + if (_bindable.getArgTypes().length > 0 && + _bindable.getArgTypes()[0] == Input.Region.class) { + Functor func = new Functor() { + int[] map = buildSequence(_bindable); + public Object invoke(final Input.Region region) { return _bindable.createBinding(map, region); } + }; + return Sequence.regionRewritingSequence(func, elements, drops); + } + + if (_bindable.isAnnotationPresent(bind.raw.class)) + return Sequence.rewritingSequence(new Tree.RawBindingFunctor(_bindable.createBinding()), elements, drops); + int[] map = buildSequence(_bindable); + return Sequence.rewritingSequence(new Tree.BindingFunctor(_bindable.createBinding()), elements, drops); + } + }