chrriis.uihierarchy.util
Class HStringTokenizer

java.lang.Object
  extended bychrriis.uihierarchy.util.HStringTokenizer

public class HStringTokenizer
extends Object

A tokenizer with a hierarchy of tokens, used to parse a String with groups and operations.

The format of the string to parse is: "expression" or "expression1, expression2, ...".

An expression is composed of operations between expressions, groups and/or functions. It can use the '=' sign as a group separator.
An operation is defined by the use of one of these operators: '+', '-', '*' and '/'.
A group is defined by the use of surrounding '(' and ')', '[' and ']', or '{' and '}'.
A function is the same as a group, but is prefixed by a function name.

The tokenization priorities , from highest to lowest, are: ',', '=', '*' and '/', '+' and '-'. Groups and functions are processed as single expressions, which are themselves tokenized.

The tokens that are generated reflect the groups and operations. The root token contains the full text as a token, and no operator (with value 0 that is). Its subtokens (from 0 to n) reflect the expressions.
The getOperator() indicates the operation, group or function that links subtokens. The operator is one of '=', '+', '-', '*', '/', '(', '[' or '{'. For functions, the getToken() returns the name of the function.

For example "x=5+3*max(2, min(1, 3)), -5*-3" is decomposed into the following tree of tokens (notation is "operator, text"):

 0, "x=5+3*max(2, min(1, 3)), -5*-3"
   '=', null
     0, "x"
     '+', null
       0, "5"
       '*', null
         0, "3"
         '(', "max"
           0, "2"
           '(', "min"
             0, "1"
             0, "3"
   '*', null
     '-', null
       (null token)
       0, "5"
     '-', null
       (null token)
       0, "-3"
 

Version:
1.0 2004.01.06
Author:
Christopher Deckers (chrriis@brainlex.com)

Constructor Summary
HStringTokenizer(String text)
          Construct a tokenizer for the particular text.
 
Method Summary
 char getOperator()
          Get the operator.
 HStringTokenizer[] getSubTokenizers()
          Get the sub tokenizers.
 String getToken()
          Get the token.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HStringTokenizer

public HStringTokenizer(String text)
Construct a tokenizer for the particular text.

Parameters:
text - The text to break into grouped tokens.
Method Detail

getOperator

public char getOperator()
Get the operator. The operator is one of:

Returns:
The operator, or 0 if not defined.

getToken

public String getToken()
Get the token.

Returns:
The token, or null if sub tokens contain the information.

getSubTokenizers

public HStringTokenizer[] getSubTokenizers()
Get the sub tokenizers. For a group that contain different comma-separated elements, the elements are direct sub tokenizers.

Returns:
The sub tokenizers, or null if this tokenizer contains the information.