de.hunsicker.jalopy.language
Class Recognizer

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

public class Recognizer
extends java.lang.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.2.2 $
Author:
Marco Hunsicker

Nested 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 java.lang.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.
 antlr.collections.AST getParseTree()
          Returns the root node of the generated parse tree.
 int getStartColumn()
           
 int getStartLine()
           
 boolean isFinished()
          Indicates whether the recognizer is currently running.
 boolean isRunning()
          Indicates whether the recognizer is currently running.
 void parse(java.io.File file)
          Parses the given file.
 void parse(java.io.Reader in, java.lang.String filename)
          Parses the given stream.
 void parse(java.lang.String str, java.lang.String filename)
          Parses the given string.
 void reset()
          Resets both the parser and lexer.
 void set_startLine(int line)
           
 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 java.lang.String UNKNOWN_FILE
Represents an unknown filename that may be used for the filename argument with parse(Reader, String) or parse(String, String).

See Also:
Constant Field Values

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:
java.lang.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 antlr.collections.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(java.io.Reader in,
                  java.lang.String filename)
Parses the given stream.

Parameters:
in - stream we read from.
filename - name of the file we parse.
Throws:
java.lang.IllegalStateException - if the parser is currently running.
Recognizer.ParseException - if an unexpected error occured.

parse

public void parse(java.io.File file)
Parses the given file.

Parameters:
file - file to parse.

parse

public void parse(java.lang.String str,
                  java.lang.String filename)
           throws java.io.IOException
Parses the given string.

Parameters:
str - to parse.
filename - name of the file we parse.
Throws:
java.io.IOException - if an I/O error occured.

reset

public void reset()
Resets both the parser and lexer.

See Also:
Parser.reset(), Lexer.reset()

getStartColumn

public int getStartColumn()

getStartLine

public int getStartLine()

set_startLine

public void set_startLine(int line)


Copyright © 1997-2005 Jalopy. All Rights Reserved.