org.vishia.zbnf
Interface ZbnfParseResultItem

All Superinterfaces:
SortedTree<ZbnfParseResultItem>
All Known Implementing Classes:
ZbnfParserStore.ParseResultItemImplement

public interface ZbnfParseResultItem
extends SortedTree<ZbnfParseResultItem>

This interface is used to query the results of parsing. Every result item can be query at the readed values from input. The next item can getted, so the user can stepped through all items. Especially the item after the end of a metamorphem item can getted directly, if the parsed result of a metamorphem is not interested.
The evaluation of the parsing result may be done with the followed pattern:

  ParseResultItem item = parser.getFirstParseResult();  //after successfull parsing.
  while(item != null)
  { String semantic = item.getSemantic();
    if(semantic.equals("myExpectedSemantic"))
    { //do something
    }
    else if(semantic.equals("myOtherExpectedSemantic"))  
    { //do something:
      getOtherExpectedComponentResult();
    }
    item = item.next(null);  //get the next.
  }
 
The doSomehing means, calling of getParsedText(), getParsedInteger() and so on from this item and write the values according the users requests. In the example above a mehtod getOtherExpectedComponentResult() is be written. It is a example to get results from parsing of a metamorphem, it is typically. In this case the followed pattern may be used:
  void getOtherExpectedComponentResult(ParseResultItem parent)
  { //do something with info in parent
    // ...
    ParseResultItem item = parent.nextSkipIntoComponent(parent);  
    //start with the second item of the component 'parent'.
    //It may be null if the parent is only composed of one item. 
    while(item != null)
    { String semantic = item.getSemantic();
      if(semantic.equals("mySecondSemantic"))
      { //do something
      }
      else if(semantic.equals("myThirdExpectedSemantic"))  
      { //do something
        getUsersInnerComponentResult();
      }
      item = item.next(parent);  //get the next, null on end of the component 'parent'
    }
  }    
 
The inner structure is the same, if a component with the expected semantic is detect, the component is examined by calling nextSkipIntoComponent(parent) at first, but, to step throw its components next(parent) is calling inside the while-loop to skip over inner components. Note: The documentation above uses the older deprecated methods, using the methods from interface are more simple.


Method Summary
 ZbnfParseResultItem firstChild()
          Gets the first child of a component.
 java.lang.String getChildString(java.lang.String child)
          Returns the String content of the given child or null, if no such child is found.
 java.lang.String getDescription()
          Returns a short description for report, error report, from the current item.
 int getInputColumn()
          returns the column of the input line while parsing.
 int getNrofAlternative()
          Returns the number of the alternative, -1 if there is not a alternative choice, 0 if there is an empty option.
 double getParsedFloat()
          Returns the parsed float value if isFloat() returns true.
 long getParsedInteger()
          Returns the parsed integer value if isInteger() returns true.
 java.lang.String getParsedString()
          Returns the parsed string if isString() returns true.
 java.lang.String getParsedText()
          Returns the input text at the parsed area of this result.
 java.lang.String getSemantic()
          Gets the semantic of the item.
 boolean isComponent()
          Tests if the actual item is a start item of a component.
 boolean isFloat()
          Tests if the actual item represents a parsed float number.
 boolean isIdentifier()
          Tests if the actual item represents an identifier.
 boolean isInteger()
          Tests if the actual item represents a parsed integer number.
 boolean isOnlySemantic()
          Tests if the actual item represents a entry describes only semantic.
 boolean isOption()
          Tests if the actual item represents an entry describes a option construct of something.
 int isRepeat()
          Tests if the actual item represents an entry describes a repetition of something.
 int isRepetition()
          Tests if the actual item represents an entry describes a repetition of something.
 boolean isString()
          Tests if the actual item represents a parsed string.
 boolean isTerminalSymbol()
          Tests if the actual item represents a parsed terminal symbol.
 java.util.Iterator<ZbnfParseResultItem> iteratorChildren()
          Creates an iterator and returns it reference for the actual item to iterate to its childs.
 ZbnfParseResultItem next()
          Deprecated. use instead iteratorChildren() or getChildren() from the parent item.
 ZbnfParseResultItem next(ZbnfParseResultItem parent)
          Deprecated. use instead iteratorChildren() or getChildren() from the parent item.
 ZbnfParseResultItem nextSkipIntoComponent(ZbnfParseResultItem parent)
          Deprecated. use instead iteratorChildren() or getChildren() from the current item.
 
Methods inherited from interface org.vishia.util.SortedTree
getChild, iterChildren, iterChildren, listChildren, listChildren
 

Method Detail

getSemantic

java.lang.String getSemantic()
Gets the semantic of the item. If no semantic is given, this method returns a string beginning with "-" such as "--NoSemantic--". This string is manual readable. The users evaluation will be oriented on the semantic of the items.


getParsedText

java.lang.String getParsedText()
Returns the input text at the parsed area of this result. At example a float is parsed, this method returns the string represents the float number.

Returns:
null if the mode of not stored input is used.

getParsedFloat

double getParsedFloat()
Returns the parsed float value if isFloat() returns true. Note: "float" doesn't mean the float type in java, it means a float value in mathematical wise. Thats why the return value is double. The user may cast it to float, if it knows, that the value is inside the float range.

Returns:
The parsed float value or 0.0 if isFloat() returns false.

getParsedInteger

long getParsedInteger()
Returns the parsed integer value if isInteger() returns true. Note: "integer" doesn't mean the int type in java, it means a integer value in mathematical wise. Thats why the return value is long. The user may cast it to int or short or byte, if it knows, that the value is inside the expected range.

Returns:
The parsed integer value or 0 if isInteger() returns false.

getParsedString

java.lang.String getParsedString()
Returns the parsed string if isString() returns true.

Returns:
The parsed string or null if isString() returns false.

getChildString

java.lang.String getChildString(java.lang.String child)
Returns the String content of the given child or null, if no such child is found.

Parameters:
child -

getNrofAlternative

int getNrofAlternative()
Returns the number of the alternative, -1 if there is not a alternative choice, 0 if there is an empty option.

Returns:
Number of alternative 1.. if a alternative is used actively.

getDescription

java.lang.String getDescription()
Returns a short description for report, error report, from the current item. The form is <value?semantic>>.

Returns:
A short description.

getInputColumn

int getInputColumn()
returns the column of the input line while parsing.


isComponent

boolean isComponent()
Tests if the actual item is a start item of a component. A component is a complex part of the parsed input file, represent by the appropriated items after this item here, determined by a non-terminal symbol of syntax.

Returns:
true if it is a component, false if it is a single morphem, once of the other is___().

isInteger

boolean isInteger()
Tests if the actual item represents a parsed integer number.

Returns:
true if it is a integer number, false if it is once of the others types querried with is___().

isFloat

boolean isFloat()
Tests if the actual item represents a parsed float number.

Returns:
true if it is a integer number, false if it is once of the others types querried with is___().

isString

boolean isString()
Tests if the actual item represents a parsed string. It is possible to generate such an entry if the syntax SBNF-file contains <EXPR?semantic>, where EXPR is a regular expression, quotion string, String to an end char or such. Use getString() to get the string value of this item.

Returns:
true if it is a string, false if it is once of the others types querried with is___().

isTerminalSymbol

boolean isTerminalSymbol()
Tests if the actual item represents a parsed terminal symbol.

Returns:
true if it is terminal symbol, false if it is once of the others types querried with is___().

isIdentifier

boolean isIdentifier()
Tests if the actual item represents an identifier. An identifier is stored in result only if <$ ...> is given in the syntax prescript.

Returns:
true if it is a identifier, false if it is once of the others types querried with is___().

isOnlySemantic

boolean isOnlySemantic()
Tests if the actual item represents a entry describes only semantic. It is possible to generate such an entry if the syntax SBNF-file contains <?semantic>.

Returns:
true if it is a only-semantic-describing entry, false if it is once of the others types querried with is___().

isRepetition

int isRepetition()
Tests if the actual item represents an entry describes a repetition of something. It is possible to generate such an entry if the syntax SBNF-file contains {<?semantic> ... }.

Returns:
>0 if it is a repetition, it is the count of repetition; < 0 if it isn't..

isRepeat

int isRepeat()
Tests if the actual item represents an entry describes a repetition of something. It is possible to generate such an entry if the syntax SBNF-file contains { ... ?<?semantic> ... }.

Returns:
>0 if it is a repeat (backward) part of repetition, it is the count of repetition; < 0 if it isn't..

isOption

boolean isOption()
Tests if the actual item represents an entry describes a option construct of something. It is possible to generate such an entry if the syntax SBNF-file contains [<?semantic>...| ...|].

Returns:
true if it is a alternative, it is the count of alternative; < 0 if it isn't..

next

ZbnfParseResultItem next()
Deprecated. use instead iteratorChildren() or getChildren() from the parent item.

Gets the next item or component followed by the current item or component in the current tree level. use it if it is known that at least one followed item should exist.

Returns:
The next item or null on end of all items. If next() is called but the curren tree level is ended, the next item of the level above is returned. It is not tested here.

next

ZbnfParseResultItem next(ZbnfParseResultItem parent)
Deprecated. use instead iteratorChildren() or getChildren() from the parent item.

Gets the next item or component followed by the current item in the current tree level. inside the component 'parent' or inside the whole parsers store. This method is useful if the overview over results, test some components, is interested.

Parameters:
parent - The item that is the first item of a component. If null, than no test of parent occurs.
Returns:
The next item or null on end of parent or end of all.

nextSkipIntoComponent

ZbnfParseResultItem nextSkipIntoComponent(ZbnfParseResultItem parent)
Deprecated. use instead iteratorChildren() or getChildren() from the current item.

Gets the next item immediate after this item inside the component 'parent' or inside the whole parsers store. If this is the components first item, it supplies the components second item. After that, next(componentesFirstItem) steps inside the component and supplies null on end of the component.
This method is useful especially if the content of the component is interested.

Parameters:
parent - The item that is the first item of a component. If null, than no test of parent occurs.
Returns:
The next item after a meta morphem or null on end.

firstChild

ZbnfParseResultItem firstChild()
Gets the first child of a component. Use it if it is known that at least one child should exist.

Returns:
first child or null if it is not a component with children.

iteratorChildren

java.util.Iterator<ZbnfParseResultItem> iteratorChildren()
Creates an iterator and returns it reference for the actual item to iterate to its childs.