1 // Copyright 2006 all rights reserved; see LICENSE file for BSD-style license
3 package edu.berkeley.sbp;
6 import java.lang.reflect.*;
7 import java.lang.ref.*;
8 import edu.berkeley.sbp.*;
9 import edu.berkeley.sbp.util.*;
11 /** <font color=purple>a stream of <tt>Token</tt>s to be parsed</font> */
12 public interface Input<Token> {
14 /** returns the token just beyond the current location and advances beyond it */
15 public Token next() throws IOException;
17 /** returns the location the input stream is currently at */
18 public Location<Token> getLocation();
21 * <b>Optional:</b> <i>If possible</i>, this method will return a
22 * <60 char long rendering of the input region (for example, if
23 * the input is a region of characters, it would be those
24 * characters, possibly with ellipses in the middle to truncate
25 * the length) -- otherwise, returns null.
27 public abstract String showRegion(Region<Token> r);
29 /** <font color=purple>a location (position) in the input stream -- <i>between tokens</i></font> */
30 public static interface Location<Token> extends Comparable<Location> {
32 /** return the region between this location and <tt>loc</tt> */
33 public Region<Token> createRegion(Location<Token> loc);
35 public String toString();
37 /** the location following this one */
38 public Location next();
40 /** the location preceding this one */
41 public Location prev();
44 /** <font color=purple>a contiguous set of <tt>Location</tt>s</font> */
45 public static interface Region<Token> /* implements Topology<Location<Tok>> */ {
48 * the toString() method of Region should return a <80char
49 * "rendition" of the input region, if possible
51 public abstract String toString();
53 /** The location of the start of this region */
54 public abstract Location<Token> getStart();
56 /** The location of the end of this region */
57 public abstract Location<Token> getEnd();