X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Ftib%2FTib.java;h=387f5edda2c3064c1514956377d1b365aa9155bb;hp=a3fd5680b7a2b18086401a75ac0f7cf043ef481b;hb=f65ffd84486b1deb993d17bcdee5c3a9f5638a8c;hpb=2c05c84a714f54b3bc026f51416492ddb13f33b1 diff --git a/src/edu/berkeley/sbp/tib/Tib.java b/src/edu/berkeley/sbp/tib/Tib.java index a3fd568..387f5ed 100644 --- a/src/edu/berkeley/sbp/tib/Tib.java +++ b/src/edu/berkeley/sbp/tib/Tib.java @@ -7,10 +7,6 @@ import edu.berkeley.sbp.chr.*; import java.util.*; import java.io.*; -// TODO: multiple {{ }} for superquotation -// TODO: strings -// TODO: comments - /** * A slow, ugly, inefficient, inelegant, ad-hoc parser for TIB files. * @@ -24,7 +20,7 @@ import java.io.*; */ public class Tib implements Input { - public String showRegion(Region r) { return null; } + public String showRegion(Region r) { return ""; } public Tib(String s) throws IOException { this(new StringReader(s)); } public Tib(Reader r) throws IOException { this(new BufferedReader(r)); } @@ -32,10 +28,8 @@ public class Tib implements Input { public Tib(BufferedReader br) throws IOException { this.br = br; istack.add(-1); - //cur = parse(br); - //System.out.println("\rparsing: \"" + cur.toString(0, -1) + "\""); } - + public String getName() { return null; } private String s = ""; int pos = 0; int spos = 0; @@ -54,12 +48,15 @@ public class Tib implements Input { boolean indenting = true; int indentation = 0; private ArrayList istack = new ArrayList(); + private static boolean debug = "true".equals(System.getProperty("tib.debug", "false")); public Character next() throws IOException { Character ret = nextc(); - if (ret==null) return null; - else if (ret==left) System.out.print("\033[31m{\033[0m"); - else if (ret==right) System.out.print("\033[31m}\033[0m"); - else System.out.print(ret); + if (debug) { + if (ret==null) return null; + else if (ret==left) System.err.print("\033[31m{\033[0m"); + else if (ret==right) System.err.print("\033[31m}\033[0m"); + else System.err.print(ret); + } return ret; } @@ -135,66 +132,5 @@ public class Tib implements Input { } boolean blank = false; - // Grammar ////////////////////////////////////////////////////////////////////////////// - - /* - public static class Grammar extends ReflectiveGrammar { - private int anon = 0; - private final Element ws = Sequence.maximal0(getNonTerminal("w")); - public Grammar(Class c) { super(c); dropAll.add(ws); } - public Object walk(Tree tree) { - String head = tree.head(); - if (tree.numChildren()==0) return super.walk(tree); - if ("{".equals(head)) { - Union u = new Union("???"); - Union u2 = ((PreSequence)walk(tree, 0)).sparse(ws).buildUnion(); - u2.add(Sequence.singleton(new Element[] { u }, 0)); - return anonymousNonTerminal(new Sequence[][] { - new Sequence[] { - Sequence.singleton(new Element[] { CharAtom.leftBrace, - ws, - u2, - ws, - CharAtom.rightBrace - }, 2) - } - }); - } - return super.walk(tree); - } - } - */ - - /* -public class Braces extends Union { - - private static final Element left = string("{"); - private static final Element right = string("}"); - - public static String join(Object[] e) { - StringBuffer ret = new StringBuffer(); - for(int i=0; i0) ret.append(" "); - ret.append(e[i]); - } - return ret.toString(); - } - - public Braces(Element[] e, Element sep) { - super("{"+join(e)+"}"); - Element[] e2 = new Element[sep == null ? e.length+2 : e.length + 4]; - e2[0] = left; - e2[e2.length-1] = right; - if (sep != null) { - e2[1] = sep; - e2[e2.length-2] = sep; - } - for(int i=0; i