X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Fmeta%2FProduction.java;h=4cbbef2bf69868410efb8da3cb187bbf9c8b9aab;hb=fb8694140dd9736855795e64a9bd4c3d50f7f2ea;hp=0abb9968c47ef073c06ef14bcfda7722a2915458;hpb=2bee2b032b0422d212e17082cc4dcbf28cb897ac;p=sbp.git diff --git a/src/edu/berkeley/sbp/meta/Production.java b/src/edu/berkeley/sbp/meta/Production.java index 0abb996..4cbbef2 100644 --- a/src/edu/berkeley/sbp/meta/Production.java +++ b/src/edu/berkeley/sbp/meta/Production.java @@ -1,3 +1,5 @@ +// Copyright 2006 all rights reserved; see LICENSE file for BSD-style license + package edu.berkeley.sbp.meta; import edu.berkeley.sbp.util.*; import edu.berkeley.sbp.*; @@ -11,10 +13,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; @@ -25,4 +30,92 @@ public class Production { if (!drops[i]) count++; } + + public int[] buildSequence(Bindable _bindable) { + Annotation[][] annotations = _bindable.getArgAnnotations(); + Class[] types = _bindable.getArgTypes(); + String[] names = _bindable.getArgNames(); + String name = _bindable.getSimpleName(); + int len = annotations.length; + int ofs = 0; + bind.arg[] argtags = new bind.arg[len]; + for(int i=0; i0 && types[0]==Input.Region.class; + for(int i=0; i 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); + } + }