|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
TextLexerBase.java | 0% | 0% | 0% | 0% |
|
1 |
package org.codehaus.groovy.syntax.lexer;
|
|
2 |
|
|
3 |
import org.codehaus.groovy.syntax.ReadException;
|
|
4 |
|
|
5 |
/**
|
|
6 |
* A base class for Lexers that process embedded text.
|
|
7 |
*
|
|
8 |
* @author Chris Poirier
|
|
9 |
*/
|
|
10 |
|
|
11 |
public class TextLexerBase extends LexerBase implements Delimiter |
|
12 |
{ |
|
13 |
|
|
14 |
protected boolean delimited = true; // When true, the lexer can do its delimiting |
|
15 |
protected boolean finished = true; // When true, the lexer is dry |
|
16 |
|
|
17 |
|
|
18 |
/**
|
|
19 |
* Turns delimiting on or off. This should affect <code>la()</code>
|
|
20 |
* and <code>consume()</code>. However, once the delimiter has been
|
|
21 |
* reached, this routine should have no effect.
|
|
22 |
*/
|
|
23 |
|
|
24 | 0 |
public void delimit( boolean delimited ) |
25 |
{ |
|
26 | 0 |
this.delimited = delimited;
|
27 |
} |
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
/**
|
|
32 |
* Returns true if the lexer is applying its delimiter policy.
|
|
33 |
*/
|
|
34 |
|
|
35 | 0 |
public boolean isDelimited() |
36 |
{ |
|
37 | 0 |
return this.delimited; |
38 |
} |
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
/**
|
|
43 |
* Returns true if the lexer stream is dry.
|
|
44 |
*/
|
|
45 |
|
|
46 | 0 |
public boolean isFinished() |
47 |
{ |
|
48 | 0 |
return finished;
|
49 |
} |
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
/**
|
|
54 |
* Restarts the lexer stream after a <code>finish()</code>
|
|
55 |
* and some intevening act (like a new source).
|
|
56 |
*/
|
|
57 |
|
|
58 | 0 |
protected void restart() |
59 |
{ |
|
60 | 0 |
finished = false;
|
61 |
} |
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
/**
|
|
66 |
* Stops the lexer stream.
|
|
67 |
*/
|
|
68 |
|
|
69 | 0 |
protected void finish() |
70 |
{ |
|
71 | 0 |
finished = true;
|
72 |
} |
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
//---------------------------------------------------------------------------
|
|
79 |
// STREAM ROUTINES
|
|
80 |
|
|
81 |
|
|
82 |
/**
|
|
83 |
* Returns the next <code>k</code>th character, without consuming any.
|
|
84 |
*/
|
|
85 |
|
|
86 | 0 |
public char la(int k) throws LexerException, ReadException |
87 |
{ |
|
88 | 0 |
if( finished )
|
89 |
{ |
|
90 | 0 |
return CharStream.EOS;
|
91 |
} |
|
92 | 0 |
else if( source != null ) |
93 |
{ |
|
94 | 0 |
return source.la(k);
|
95 |
} |
|
96 |
else
|
|
97 |
{ |
|
98 | 0 |
return CharStream.EOS;
|
99 |
} |
|
100 |
} |
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
/**
|
|
105 |
* Eats a character from the input stream.
|
|
106 |
*/
|
|
107 |
|
|
108 | 0 |
public char consume() throws LexerException, ReadException |
109 |
{ |
|
110 | 0 |
if( finished )
|
111 |
{ |
|
112 | 0 |
return CharStream.EOS;
|
113 |
} |
|
114 | 0 |
else if( source != null ) |
115 |
{ |
|
116 | 0 |
return source.consume();
|
117 |
} |
|
118 |
else
|
|
119 |
{ |
|
120 | 0 |
return CharStream.EOS;
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
} |
|
125 |
|
|