|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.aliasi.corpus.Parser<H>
com.aliasi.corpus.InputSourceParser<H>
com.aliasi.corpus.LineParser<H>
public abstract class LineParser<H extends Handler>
A LineParser provides an abstract adapter for
line-based parsing. For each line of the input, the abstract
method parseLine(String,int) is called. The newline marker
character(s) are not part of the line sent to the line parser
method.
The notion of line is defined by BufferedReader.readLine(). As in that method, newlines may be
marked by any of the markers in the following table:
| Marker | Character Sequence |
|---|---|
| line feed | \n |
| carriage return | \r |
| carriage return, line feed | \r\n |
The newline marker is not returned as part of the line. Zero-length lines will be included as lines except for the very last line. The following table shows some example:
| Input | Lines |
|---|---|
"" |
|
"\n" |
"" |
"\n\n" |
"", "" |
"abc" |
"abc" |
"abc\n" |
"abc" |
"abc\rdef" |
"abc", "def" |
"\nabc\rdef\r\n\n" |
"", "abc", "def", "" |
It is up to the line parser method to handle comments, empty lines, and other conditions defined by the particular input format to be parsed.
| Constructor Summary | |
|---|---|
LineParser()
Construct a line parser without a specified handler. |
|
LineParser(H handler)
Construct a line parser with the handler set to the specified handler. |
|
| Method Summary | |
|---|---|
void |
parse(InputSource inSrc)
Parse the specified input source by converting to a reader and then using a buffered reader to parse out lines. |
protected abstract void |
parseLine(String line,
int lineNumber)
Handle a line of input. |
| Methods inherited from class com.aliasi.corpus.InputSourceParser |
|---|
parseString |
| Methods inherited from class com.aliasi.corpus.Parser |
|---|
getHandler, parse, parse, parseString, setHandler |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public LineParser()
public LineParser(H handler)
handler - Handler to use.| Method Detail |
|---|
public void parse(InputSource inSrc)
throws IOException
The reader or input stream from the input source will be closed before this method exits.
parse in class Parser<H extends Handler>inSrc - Input source from which to extract a reader.
IOException - If there is an underlying I/O error
from the input source's input stream or reader.
protected abstract void parseLine(String line,
int lineNumber)
line - Line to parse.lineNumber - Line number being parsed.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||