X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Fmeta%2FProduction.java;h=bcd240752a0fa0690beae0db933a00c9e2f3facf;hp=117eb57b4ee95a6ffbfdf104efe0f10cd954e26b;hb=9b031db4cefc550c82a8bb6da3b061d3790c2cdc;hpb=a7ed3694a03bf9fe30e3274775c0646554e99bd4 diff --git a/src/edu/berkeley/sbp/meta/Production.java b/src/edu/berkeley/sbp/meta/Production.java index 117eb57..bcd2407 100644 --- a/src/edu/berkeley/sbp/meta/Production.java +++ b/src/edu/berkeley/sbp/meta/Production.java @@ -11,10 +11,13 @@ import java.io.*; public class Production { public String tag; + public String nonTerminal; public boolean[] drops; public Element[] elements; - public String nonTerminal; public int count = 0; + + public String tag() { return tag==null ? nonTerminal : tag; } + public Production(String tag, Element[] elements, boolean[] drops) { this(tag, tag, elements, drops); } public Production(String tag, String nonTerminal, Element[] elements, boolean[] drops) { this.tag = tag; @@ -78,4 +81,39 @@ 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.newRegionRewritingSequence(func, elements, drops); + } + */ + + if (_bindable.isAnnotationPresent(bind.raw.class)) + return Sequence.create(new RawBindingFunctor(tag(), _bindable.createBinding()), elements, drops, false); + int[] map = buildSequence(_bindable); + return Sequence.create(new BindingFunctor(tag(), _bindable.createBinding()), elements, drops, false); + } + }