|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.vishia.zbnf.ZbnfParser
public class ZbnfParser
An instance of ZbnfParser contains a syntax prescript inside and is able to parse a text, test the syntax and output
a tree of information given in the input text.
The invocation is in followed manner:
ZbnfParser parser = new ZbnfParser(reportConsole);
try{ parser.setSyntax(syntaxString);}
catch(ParseException exception)
{ writeError("parser reading syntax error: " + exception.getMessage();
return;
}
if(!parser.parse(inputString))
{ writeError(parser.getSyntaxErrorReport());
}
else
{ ParseResultItem resultItem = parser.getFirstParseResult();
while( resultItem != null)
{ evaluateResult(resultItem);
resultItem = resultItem.next(null))
}
}
setSyntax(StringPart) is to be defined in the Semantic Backus Naur-Form
(ZBNF, Z is a reverse S for Semantic).
It is given as a String or StringPart.
The method setSyntax, reads the string and convert it in internal data. The input string (mostly readed from a file)
may be consist of a sequence of variables beginning with $ and syntax terms. A syntax term is described
on the class ZbnfSyntaxPrescript, because this class converts a syntax term in an internal tree of syntax nodes.
Downside it is shown an example of a syntax file or string with all variables.
<?ZBNF-www.vishia.org version="1.0" encoding="iso-8859-1" ?> ##this first line is not prescribed but possible.
$setLinemode. ##if set, than the newline char \n is not overwritten as whitespace
$endlineComment=##. ##defines the string introducing a comment to eol, default is //
$comment=[*...*]. ##... between [* ... *] all chars are ignored, default is /*...* /
$keywords=if|else. ##that identifiers are not accepted as identifiers parsing by <$?...>
$inputEncodingKeyword="encoding". ##it helps to define the encoding of the input file via a keyword input-file
$inputEncoding="UTF-8". ##it helps to define the encoding of the input file (useable outside parser core)
$xmlns:nskey="value". ##defines a namespace key for XML output (useable outside parser core)
component::=<$?name>=<#?number> { <value> , }. ##The first syntax term is the toplevel syntax.
value::= val = [ a | b | c]. ##another syntax term
setSkippingComment(String, String, boolean), setSkippingEndlineComment(String, boolean),
setWhiteSpaces(String), setLinemode(boolean) is not occured after setSyntax(String).<$NoWhiteSpaces>-construct,
see ZbnfSyntaxPrescript.
getFirstParseResult() to get the toplevel item.
| Constructor Summary | |
|---|---|
ZbnfParser(Report report)
Creates a empty parser instance. |
|
ZbnfParser(Report report,
int maxParseResultEntriesOnError)
Creates a empty parser instance. |
|
| Method Summary | |
|---|---|
java.lang.String |
getExpectedSyntaxOnError()
Returns the expected syntax on error position. |
ZbnfParseResultItem |
getFirstParseResult()
Returns the first parse result item to start stepping to the results. |
java.lang.String |
getFoundedInputOnError()
Returns about 50 chars of the input string founded at the parsing error position. |
java.nio.charset.Charset |
getInputEncoding()
Returns the setting of $inputEncoding="...". |
java.lang.String |
getInputEncodingKeyword()
Returns the setting of $inputEncodingKeyword="...". |
long |
getInputPositionOnError()
Returns the position of error in input string. |
java.lang.String |
getLastFoundedResultOnError()
Returns the up to now founded result on error position. |
java.lang.String |
getSyntaxErrorReport()
assembles a string with a user readable syntax error message. |
java.util.TreeMap<java.lang.String,java.lang.String> |
getXmlnsFromSyntaxPrescript()
Returns a TreeMap of all xmlns keys and strings. |
boolean |
parse(java.lang.String input)
Parsed a given Input and produces a parse result. |
boolean |
parse(StringPart input)
parses a given Input and produces a parse result. |
boolean |
parse(StringPart input,
java.util.List<java.lang.String> additionalInfo)
parses a given Input, see [ parse(StringPart), but write additional semantic informations
into the first parse result (into the top level component). |
void |
reportStore(Report report)
Reports the whole content of the parse result in the Report.fineInfo-level. |
void |
reportStore(Report report,
int reportLevel)
|
void |
reportStore(Report report,
int reportLevel,
java.lang.String sTitle)
Reports the whole content of the parse result. |
void |
reportSyntax(Report report,
int reportLevel)
Reports the syntax. |
void |
setLinemode(boolean bTrue)
Sets the line mode or not. |
void |
setReportIdents(int identError,
int identInfo,
int identComponent,
int identFine)
sets the ident number for report of the progress of parsing. |
void |
setSkippingComment(java.lang.String sCommentStringStart,
java.lang.String sCommentStringEnd,
boolean bStoreComment)
Set the mode of skipping comments. |
void |
setSkippingEndlineComment(java.lang.String sCommentStringStart,
boolean bStoreComment)
Set the mode of skipping comments to end of line. |
boolean |
setStoringConstantSyntax(boolean bStore)
Determines wether or not constant syntax (teminal syntax items or terminal morphes) should also strored in the result buffer. |
void |
setSyntax(java.io.File fileSyntax)
|
void |
setSyntax(java.lang.String syntax)
Sets the syntax from given string. |
void |
setSyntax(StringPart syntax)
Sets the syntax from given String. |
void |
setWhiteSpaces(java.lang.String sWhiteSpaces)
Sets the chars which are recognized as white spaces. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ZbnfParser(Report report)
report - A report output
public ZbnfParser(Report report,
int maxParseResultEntriesOnError)
report - A report outputmaxParseResultEntriesOnError - if 0 than no parse result is stored.
If >0, than the last founded parse result is stored to support better analysis of syntax errors,
but the parser is slower.| Method Detail |
|---|
public void setSyntax(java.lang.String syntax)
throws java.text.ParseException
syntax - The ZBNF-Syntax.
java.text.ParseException
public void setSyntax(java.io.File fileSyntax)
throws java.nio.charset.IllegalCharsetNameException,
java.nio.charset.UnsupportedCharsetException,
java.io.FileNotFoundException,
java.io.IOException,
java.text.ParseException
java.nio.charset.IllegalCharsetNameException
java.nio.charset.UnsupportedCharsetException
java.io.FileNotFoundException
java.io.IOException
java.text.ParseException
public void setSyntax(StringPart syntax)
throws java.text.ParseException
SyntaxPrescript.
The class SyntaxPrescript is private inside the Parser, but its matter of principle may be
explained here. SyntaxPrescript contains a list of elements (listSyntaxElements)
or a list of such listSyntaxElements.
The list of listSyntaxElements is used if there are some alternatives. listSyntaxElements contains
objects of type String, SyntaxPrescript,
Component or Repetition. It is the sequence of
syntax elements of one syntax-path in ZBNF. An object of type String represents a
terminal symbol (constant string).
An element of SyntaxPrescript is an option construction [...|..|..]
or also a simple option [...]. The Repetition represents the
{...?...}-construction. A Repetition contains one or two objects
of type SyntaxPrescript for the forward and optional backward syntax. This syntax-prescripts
may be build complexly in the same way.Component in the listSyntaxElements represents a construction
<...?...>. It may contained the semantic information, it may containded a reference
to another SyntaxPrescript if there is required in the wise <syntax....
It is also built if a construction of kind <!regex...,
<$..., <#... or such else is given.SyntaxPrescript is passed by syntax test, the right way is searched,
see method parse()
syntax - The syntax in ZBNF-Format.
java.text.ParseException - If any wrong syntax is containing in the ZBNF-string. A string-wise information
of the error location is given.
public void setSkippingComment(java.lang.String sCommentStringStart,
java.lang.String sCommentStringEnd,
boolean bStoreComment)
sCommentStringStart - The start chars of comment string, at example '/ *'sCommentStringEnd - The end chars of comment string, at example '* /'bStoreComment - If it is true, the comment string will be stored in the ParserStrore
and can be evaluated from the user.
public void setSkippingEndlineComment(java.lang.String sCommentStringStart,
boolean bStoreComment)
sCommentStringStart - The start chars of comment string to end of line, at example '/ /'bStoreComment - If it is true, the comment string will be stored in the ParserStrore
and can be evaluated from the user.public void setWhiteSpaces(java.lang.String sWhiteSpaces)
sWhiteSpaces - Chars there are recognize as white space.setSyntax(String).public void setLinemode(boolean bTrue)
setSyntax(String).
public void setReportIdents(int identError,
int identInfo,
int identComponent,
int identFine)
identError - ident for error and warning outputs.identInfo - ident for progress information output.identComponent - ident for output if a component is parsingidentFine - ident for fine parsing outputs.public boolean parse(java.lang.String input)
input -
public boolean parse(StringPart input)
SyntaxPrescript are tested. If a matching path
is found, the method returns true, otherwise false. The result of parsing is stored inside the parser
(private internal class ParserStore).
To evaluate the parse result see getFirstParseResult().
input - The source to be parsed.
public boolean parse(StringPart input,
java.util.List<java.lang.String> additionalInfo)
parse(StringPart), but write additional semantic informations
into the first parse result (into the top level component).
input - The text to parseadditionalInfo - Pairs of semantic idents and approriate information content.
The elements [0], [2] etc. contains the semantic identifier
whereas the elements [1], [3] etc. contains the information content.
public void reportSyntax(Report report,
int reportLevel)
public void reportStore(Report report,
int reportLevel,
java.lang.String sTitle)
parseResult: <?semanticIdent> Component parseResult: <?semanticIdent> ident="foundedString" parseResult: <?semanticIdent> number=foundedNumber parseResult: </?semanticIdent> ComponentEvery line is exactly one entry in the parsers store.
report - The report output instancereportLevel - level of report. This level is shown in output.
If the current valid reportLevel of report is less than this parameter, no action is done.
public void reportStore(Report report,
int reportLevel)
public void reportStore(Report report)
report - The report output instance.reportStore(Report report, int reportLevel)}.public java.lang.String getInputEncodingKeyword()
$inputEncodingKeyword="...". in the syntax prescript or null it no such entry is given.
public java.nio.charset.Charset getInputEncoding()
$inputEncoding="...". in the syntax prescript or null it no such entry is given.
public java.lang.String getExpectedSyntaxOnError()
public java.lang.String getLastFoundedResultOnError()
public java.lang.String getFoundedInputOnError()
public long getInputPositionOnError()
public java.lang.String getSyntaxErrorReport()
public ZbnfParseResultItem getFirstParseResult()
public java.util.TreeMap<java.lang.String,java.lang.String> getXmlnsFromSyntaxPrescript()
public boolean setStoringConstantSyntax(boolean bStore)
bStore - true if they should strored, false if not.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||