com.varankin.bnf.tree
Class SyntaxImpl<Atom>

java.lang.Object
  extended by com.varankin.bnf.tree.SyntaxImpl<Atom>
Type Parameters:
Atom - elementary object of stream described by the syntax.
All Implemented Interfaces:
Accumulator<Atom>, Receiver<Atom>, java.lang.Iterable<ParsedRule<Atom>>

public class SyntaxImpl<Atom>
extends java.lang.Object
implements Accumulator<Atom>, java.lang.Iterable<ParsedRule<Atom>>

Accumulator of incoming elementary objects separated by syntax into parsed bush. Valid instance contains one or more parsed trees. Every node (ParsedUnit) of the tree is either ParsedRule or ParsedTerminal.

Author:
© 2010 Nikolai Varankine

Constructor Summary
SyntaxImpl(Syntax aSyntax, Converter<Atom> aConverter)
          Creates empty accumulator ready to accept stream of elementary objects.
 
Method Summary
 boolean add(Atom aCharacter)
          A procedure to accept object.
 java.util.Iterator<ParsedRule<Atom>> iterator()
          Seamless iterator over all syntax rules recognized by the syntax.
 java.util.List<Atom> tail()
           
 boolean tail(Atom aAtom)
          Deprecated. 
 java.lang.String toString()
           
 boolean valid()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SyntaxImpl

public SyntaxImpl(Syntax aSyntax,
                  Converter<Atom> aConverter)
Creates empty accumulator ready to accept stream of elementary objects.

Parameters:
aSyntax - syntax definition.
aConverter - text-to-Atom converter.
Method Detail

add

public boolean add(Atom aCharacter)
Description copied from interface: Receiver
A procedure to accept object.

Specified by:
add in interface Receiver<Atom>
Parameters:
aCharacter - a candidate object to accept or null to indicate break in delivery.
Returns:
true if candidate has been accepted and false if it was rejected.

iterator

public java.util.Iterator<ParsedRule<Atom>> iterator()
Seamless iterator over all syntax rules recognized by the syntax. Rules of same ID come out for every variant that might exists.

Specified by:
iterator in interface java.lang.Iterable<ParsedRule<Atom>>
Returns:
iterator over parsed syntax reles.

tail

@Deprecated
public boolean tail(Atom aAtom)
Deprecated. 

Description copied from interface: Accumulator
Adds next elementary object to the end of tail.

Specified by:
tail in interface Accumulator<Atom>
Parameters:
aAtom - elementary object to add.
Returns:
true if object was added and false otherwise.

tail

public java.util.List<Atom> tail()
Specified by:
tail in interface Accumulator<Atom>
Returns:
current sequence of last elementary objects that were accepted but not used.

valid

public boolean valid()
Specified by:
valid in interface Accumulator<Atom>
Returns:
true if syntax implementation stands in a good shape and false otherwise.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object