1 // (C) 2006-2007 all rights reserved; see LICENSE file for BSD-style license
3 package edu.berkeley.sbp;
6 import edu.berkeley.sbp.util.*;
8 // FEATURE: Region implements Topology<Location<Tok>>
10 /** <font color=purple>a stream of <tt>Token</tt>s to be parsed</font> */
11 public interface Input<Token> {
13 /** the current location within the input stream */
14 public Location<Token> getLocation();
16 /** returns the token just beyond the current location and advances beyond it */
17 public Token next() throws IOException;
19 /** a short string describing where the input is coming from, such as a filename */
20 public String getName();
22 /** might called by Parser when it is done with the input */
26 * <b>Optional:</b> <i>If possible</i>, this method will return a
27 * rendering of the input region (for example, if the input is a
28 * region of characters, it would be those characters) --
29 * otherwise, returns null. In any case, the string returned
30 * will be no more than <tt>maxLength</tt> characters long;
31 * typically ellipses will be inserted to perform truncation.
33 public abstract String showRegion(Region<Token> r, int maxLength);
35 /** <font color=purple>a location (position) in the input stream <i>between tokens</i></font> */
36 public static interface Location<Token> extends Comparable<Location> {
38 /** return the region between this location and <tt>loc</tt> */
39 public Region<Token> createRegion(Location<Token> loc);
41 public String toString();
43 /** the location following this one */
44 public Location next();
46 /** the location preceding this one */
47 public Location prev();
50 /** <font color=purple>a contiguous set of <tt>Location</tt>s</font> */
51 public static interface Region<Token> {
53 /** should return less than 80 chars if possible */
54 public abstract String toString();
56 /** The location of the start of this region */
57 public abstract Location<Token> getStart();
59 /** The location of the end of this region */
60 public abstract Location<Token> getEnd();