1 package org.codehaus.groovy.syntax.lexer;
2
3 import org.codehaus.groovy.syntax.ReadException;
4 import org.codehaus.groovy.syntax.Token;
5
6 /***
7 * The minimal interface provided by all Lexers.
8 *
9 * @author Bob Mcwhirter
10 * @author James Strachan
11 * @author John Wilson
12 * @author Chris Poirier
13 */
14
15 public interface Lexer
16 {
17
18
19 /***
20 * Gets the lexer that is actually doing the <code>nextToken()</code>
21 * work, if it isn't us.
22 */
23
24 public Lexer getDelegate();
25
26
27
28 /***
29 * Gets the lexer from which this lexer is obtaining characters.
30 */
31
32 public Lexer getSource();
33
34
35
36 /***
37 * Finds and returns (consuming) the next token from the underlying stream.
38 * Returns null when out of tokens.
39 */
40
41 public Token nextToken() throws ReadException, LexerException;
42
43
44
45
46
47
48
49
50 /***
51 * Resets a lexer for reuse.
52 */
53
54 public void reset();
55
56
57
58 /***
59 * Delegates our duties to another Lexer.
60 */
61
62 public void delegate( Lexer to );
63
64
65
66 /***
67 * Retakes responsibility for our duties.
68 */
69
70 public void undelegate();
71
72
73
74 /***
75 * Returns true if we are delegated.
76 */
77
78 public boolean isDelegated();
79
80
81
82 /***
83 * Sets the source lexer.
84 */
85
86 public void setSource( Lexer source );
87
88
89
90 /***
91 * Unsets the source lexer.
92 */
93
94 public void unsetSource( );
95
96
97
98 /***
99 * Returns true if we have an external source.
100 */
101
102 public boolean isExternallySourced();
103
104
105
106
107
108
109
110
111 /***
112 * Returns the current line number.
113 */
114
115 public int getLine();
116
117
118
119 /***
120 * Returns the current column on that line.
121 */
122
123 public int getColumn();
124
125
126
127
128 /***
129 * Returns the next character, without consuming it.
130 */
131
132 public char la() throws LexerException, ReadException;
133
134
135
136 /***
137 * Returns the next <code>k</code>th character, without consuming any.
138 */
139
140 public char la(int k) throws LexerException, ReadException;
141
142
143
144 /***
145 * Eats a single character from the input stream.
146 */
147
148 public char consume() throws LexerException, ReadException;
149
150
151 }