public final class TokenVisualizer extends Object
These methods are particularly useful for conveniently checking
the behaviour of a lexical analyzer, in particular in terms of
the positions associated to each token. These positions are often
used in parsers built on top of the lexical analyzer, and are hard
to thoroughly check and debug. Visualizing all tokens at once in situ
is a great help for that purpose.
If you are interested in recording the precise results of a lexical analysis,
for instance for the purpose of continuous integration, consider using
the Tokenizer
debugging feature.
Beware: the token visualization feature does not support
lexical analyzers which manipulate the token locations (LexBuffer.curLoc
and LexBuffer.startLoc
) in ways that are not monotonic. This is for
example the case with lexical analyzers supporting GCC-like #line
or #include
directives, or any analyzer which will move to another
input stream midway through the analysis in general. To debug such lexers,
consider using the less fancy Tokenizer
interface.
visualize(LexerInterface, String, Reader, Writer)
,
string(LexerInterface, String, Writer)
,
file(LexerInterface, String, String)
Modifier and Type | Class and Description |
---|---|
static interface |
TokenVisualizer.LexerInterface<L extends LexBuffer,T,Cat>
This interface acts as a generic proxy to using a Dolmen-generated
lexer in the static debugging functions provided in
TokenVisualizer . |
Constructor and Description |
---|
TokenVisualizer() |
Modifier and Type | Method and Description |
---|---|
static <L extends LexBuffer,T,Cat> |
file(TokenVisualizer.LexerInterface<L,T,Cat> lexer,
String input,
String output)
Outputs to the given
output file a stand-alone HTML page which
displays the tokenization of the given input file contents. |
static <L extends LexBuffer,T,Cat> |
string(TokenVisualizer.LexerInterface<L,T,Cat> lexer,
String input,
Writer output)
Outputs to the given writer a stand-alone HTML page which
displays the tokenization of the given
input string's contents. |
static <L extends LexBuffer,T,Cat> |
visualize(TokenVisualizer.LexerInterface<L,T,Cat> lexer,
String inputName,
Reader input,
Writer output)
Outputs to the given writer a stand-alone HTML page which
displays the tokenization of the given
input contents. |
public static <L extends LexBuffer,T,Cat> void visualize(TokenVisualizer.LexerInterface<L,T,Cat> lexer, String inputName, Reader input, Writer output) throws IOException
input
contents.
The tokenization is performed based on the lexing interface
described by lexer
.lexer
- the lexing interface used to tokenize and highlightinputName
- the name of the input streaminput
- the input stream to read fromoutput
- the output stream to write the HTML page toIOException
public static <L extends LexBuffer,T,Cat> void string(TokenVisualizer.LexerInterface<L,T,Cat> lexer, String input, Writer output) throws IOException
input
string's contents.
The tokenization is performed based on the lexing interface
described by lexer
.lexer
- the lexing interface used to tokenize and highlightinput
- the input string to tokenizeoutput
- the output stream to write the HTML page toIOException
public static <L extends LexBuffer,T,Cat> void file(TokenVisualizer.LexerInterface<L,T,Cat> lexer, String input, String output) throws IOException
output
file a stand-alone HTML page which
displays the tokenization of the given input
file contents.
The tokenization is performed based on the lexing interface
described by lexer
.lexer
- the lexing interface used to tokenize and highlightinput
- the name of the input fileoutput
- the name of the output file to write the HTML page toIOException