org.sc3d.apt.sss.v3
Class Bracket

java.lang.Object
  extended by org.sc3d.apt.sss.v3.Token
      extended by org.sc3d.apt.sss.v3.Bracket

public class Bracket
extends Token

A subclass of Token that represents a string of zero or more Tokens enclosed in brackets. The 'type' field of instances of Bracket will be 'TYPE_BRACKET', 'TYPE_SQUARE' or 'TYPE_BRACE'.


Field Summary
 Token closing
          One of the bracket Tokens passed to the constructor.
 int length
          The number of Tokens nested inside this Bracket.
 Token opening
          One of the bracket Tokens passed to the constructor.
 
Fields inherited from class org.sc3d.apt.sss.v3.Token
sentence, start, type, TYPE_BRACE, TYPE_CHAR, TYPE_COMMENT, TYPE_CONSTANT, TYPE_IDENTIFIER, TYPE_NUMBER, TYPE_ROUND, TYPE_SQUARE, TYPE_STRING, TYPE_WORD
 
Constructor Summary
Bracket(Sentence sentence, Token opening, Token[] tokens, Token closing)
          Constructs a Bracket.
 
Method Summary
 Token get(int index)
          Returns the Token with index 'index' inside this Bracket.
static boolean matches(Token opening, Token closing)
          Returns 'true' if 'opening' is an open round bracket and 'closing' is a close round bracket, or if 'opening' is an open square bracket and 'closing' is a close square bracket, or if 'opening' is an open brace and 'closing' is a close brace.
 Token[] toArray()
          Returns the Tokens inside this Bracket in a fresh array.
 
Methods inherited from class org.sc3d.apt.sss.v3.Token
addError, equals, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

opening

public final Token opening
One of the bracket Tokens passed to the constructor.


closing

public final Token closing
One of the bracket Tokens passed to the constructor.


length

public final int length
The number of Tokens nested inside this Bracket.

Constructor Detail

Bracket

public Bracket(Sentence sentence,
               Token opening,
               Token[] tokens,
               Token closing)
Constructs a Bracket.

Parameters:
opening - the Token which represents the open bracket.
tokens - the Tokens inside the brackets. This array is not copied away, and must therefore not be modified hereafter.
closing - the Token which represents the close bracket.
Method Detail

get

public Token get(int index)
Returns the Token with index 'index' inside this Bracket.


toArray

public Token[] toArray()
Returns the Tokens inside this Bracket in a fresh array.


matches

public static boolean matches(Token opening,
                              Token closing)
Returns 'true' if 'opening' is an open round bracket and 'closing' is a close round bracket, or if 'opening' is an open square bracket and 'closing' is a close square bracket, or if 'opening' is an open brace and 'closing' is a close brace. Returns 'false' otherwise.