added performance instrumentation (commented out)
[sbp.git] / src / edu / berkeley / sbp / Input.java
1 // (C) 2006-2007 all rights reserved; see LICENSE file for BSD-style license
2
3 package edu.berkeley.sbp;
4 import java.io.*;
5 import java.util.*;
6 import edu.berkeley.sbp.util.*;
7
8 // FEATURE: Region implements Topology<Location<Tok>>
9
10 /** <font color=purple>a stream of <tt>Token</tt>s to be parsed</font> */
11 public interface Input<Token> {
12
13     /** the current location within the input stream */
14     public Location<Token> getLocation();
15
16     /** returns the token just beyond the current location and advances beyond it */
17     public Token next() throws IOException;
18    
19     /** a short string describing where the input is coming from, such as a filename */
20     public String getName();
21
22     /** might called by Parser when it is done with the input */
23     public void close();
24
25     /**
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.
32      */
33     public abstract String showRegion(Region<Token> r, int maxLength);
34
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> {
37
38         /** return the region between this location and <tt>loc</tt> */
39         public Region<Token> createRegion(Location<Token> loc);
40
41         public String toString();
42
43         /** the location following this one */
44         public Location next();
45
46         /** the location preceding this one */
47         public Location prev();
48     }
49
50     /** <font color=purple>a contiguous set of <tt>Location</tt>s</font> */
51     public static interface Region<Token> {
52
53         /** should return less than 80 chars if possible */
54         public abstract String toString();
55         
56         /** The location of the start of this region */
57         public abstract Location<Token> getStart();
58
59         /** The location of the end of this region */
60         public abstract Location<Token> getEnd();
61
62     }
63
64 }
65
66