Jalopy 1.0b10

de.hunsicker.jalopy.language
Class Recognizer

java.lang.Object
  |
  +--de.hunsicker.jalopy.language.Recognizer
Direct Known Subclasses:
JavaRecognizer

public class Recognizer
extends Object

Recognizer acts as a helper class to bundle both an ANTLR parser and lexer for the task of language recognition.

Version:
$Revision: 1.5 $
Author:
Marco Hunsicker

Inner Class Summary
static class Recognizer.ParseException
          Indicates an unexpected error during the parsing of an input file or stream.
 
Field Summary
protected  Lexer lexer
          The used lexer.
protected  Parser parser
          The used parser.
static String UNKNOWN_FILE
          Represents an unknown filename that may be used for the filename argument with parse(Reader, String) or parse(String, String).
 
Constructor Summary
protected Recognizer()
          Creates a new Recognizer object.
  Recognizer(Parser parser, Lexer lexer)
          Creates a new Recognizer object.
 
Method Summary
 int getColumn()
          Returns the current column of the lexer.
 FileFormat getFileFormat()
          Gets the file format of the parsed file as reported by the lexer
 Lexer getLexer()
          Returns the used lexer.
 int getLine()
          Returns the current line of the lexer.
 Parser getParser()
          Returns the used parser.
 AST getParseTree()
          Returns the root node of the generated parse tree.
 boolean isFinished()
          Indicates whether the recognizer is currently running.
 boolean isRunning()
          Indicates whether the recognizer is currently running.
 void parse(File file)
          Parses the given file.
 void parse(Reader in, String filename)
          Parses the given stream.
 void parse(String str, String filename)
          Parses the given string.
 void reset()
          Resets both the parser and lexer.
 void setColumn(int column)
          Sets the current column of the lexer.
 void setLine(int line)
          Sets the current line of the lexer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNKNOWN_FILE

public static final String UNKNOWN_FILE
Represents an unknown filename that may be used for the filename argument with parse(Reader, String) or parse(String, String).

lexer

protected Lexer lexer
The used lexer.

parser

protected Parser parser
The used parser.
Constructor Detail

Recognizer

public Recognizer(Parser parser,
                  Lexer lexer)
Creates a new Recognizer object.
Parameters:
parser - the parser to use.
lexer - the lexer to use.

Recognizer

protected Recognizer()
Creates a new Recognizer object.
Method Detail

setColumn

public void setColumn(int column)
Sets the current column of the lexer.
Parameters:
column - current column information.

getColumn

public int getColumn()
Returns the current column of the lexer.
Returns:
current column offset.

getFileFormat

public FileFormat getFileFormat()
Gets the file format of the parsed file as reported by the lexer
Returns:
The file format.
Throws:
IllegalStateException - if nothing has been parsed yet.

isFinished

public boolean isFinished()
Indicates whether the recognizer is currently running.
Returns:
true if the recognizer is currently running.

getLexer

public Lexer getLexer()
Returns the used lexer.
Returns:
lexer.

setLine

public void setLine(int line)
Sets the current line of the lexer.
Parameters:
line - current line information.

getLine

public int getLine()
Returns the current line of the lexer.
Returns:
current line number of the lexer

getParseTree

public AST getParseTree()
Returns the root node of the generated parse tree.
Returns:
root node of the generated parse tree.

getParser

public Parser getParser()
Returns the used parser.
Returns:
parser.

isRunning

public boolean isRunning()
Indicates whether the recognizer is currently running.
Returns:
true if the recognizer is currently running.

parse

public void parse(Reader in,
                  String filename)
Parses the given stream.
Parameters:
in - stream we read from.
filename - name of the file we parse.
Throws:
IllegalStateException - if the parser is currently running.
Recognizer.ParseException - if an unexpected error occured.

parse

public void parse(File file)
Parses the given file.
Parameters:
file - file to parse.

parse

public void parse(String str,
                  String filename)
           throws IOException
Parses the given string.
Parameters:
str - to parse.
filename - name of the file we parse.
Throws:
IOException - if an I/O error occured.

reset

public void reset()
Resets both the parser and lexer.
See Also:
Parser.reset(), Lexer.reset()

Jalopy 1.0b10

Submit a bug or feature.

For further information and documentation, visit the official Jalopy website.
This page generated: November 14 2002