X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fedu%2Fberkeley%2Fsbp%2Fmeta%2FMetaGrammarBindings.java;h=c7952b0beebb46e4d1aa80d0c5ef7a2cd5cbae55;hb=0dd3f65037405b4a9dd03d1825b30a6557433892;hp=9ccf8a8e8e515f588147a33511a827b9dc49de65;hpb=11fb48ff93c4fad499e4110e4aa8883357963f6e;p=sbp.git diff --git a/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java b/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java index 9ccf8a8..c7952b0 100644 --- a/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java +++ b/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java @@ -85,12 +85,20 @@ public class MetaGrammarBindings { } } - public static @bind.as("#import") GrammarNode poundimport(String fileName) { - System.err.println("#import " + fileName); + public static @bind.as("#import") GrammarNode poundimport(String fileName, String as) { + if (as==null) as = ""; + else if ("".equals(as)) { } + else as = as +"."; + + System.err.println("#import " + fileName + " as " + as); try { Tree t = new CharParser(MetaGrammar.make()).parse(new FileInputStream(fileName)).expand1(); Tree.TreeFunctor red = (Tree.TreeFunctor)t.head(); - return (MetaGrammarBindings.GrammarNode)red.invoke(t); + String oldprefix = prefix; + prefix = as; + GrammarNode gn = (GrammarNode)red.invoke(t); + prefix = oldprefix; + return gn; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); @@ -209,14 +217,14 @@ public class MetaGrammarBindings { } public Seq(ElementNode e) { this(new ElementNode[] { e }); } public Seq(ElementNode[] elements) { this.elements = elements; } - public Seq tag(String tag) { this.tag = tag; return this; } + public Seq tag(String tag) { this.tag = prefix+tag; return this; } public Seq follow(ElementNode follow) { this.follow = follow; return this; } public Seq dup() { Seq ret = new Seq(elements); ret.and.addAll(and); ret.not.addAll(not); ret.follow = follow; - ret.tag = tag; + ret.tag = prefix+tag; return ret; } public Seq and(Seq s) { and.add(s); s.lame = true; return this; } @@ -241,7 +249,7 @@ public class MetaGrammarBindings { } public Sequence build0(Context cx, boolean lame, NonTerminalNode cnt) { boolean dropAll = lame; - if (tag!=null && "()".equals(tag)) dropAll = true; + if (tag!=null && tag.endsWith("()")) dropAll = true; boolean[] drops = new boolean[elements.length]; Element[] els = new Element[elements.length]; for(int i=0; i