uk.org.ogsadai.activity.files
Class SubstitutionStringParser

java.lang.Object
  |
  +--uk.org.ogsadai.activity.files.SubstitutionStringParser

public class SubstitutionStringParser
extends java.lang.Object

Implementation of a recursive-descent parser intended to parse strings which contain variables represented by $n or ${n}, where n is a non-negative integer.

The grammar from which valid strings are drawn is:

STRING::=CHAR | CHAR STRING
CHAR::=\ c | c | VAR
VAR::=$ INT | $ { INT }
INT::=n | n INT
where n is an integer, 0 <= n <= 9; c is a character.

This class is intended to be used in the following way:

String[] groups = matcher.groups();
SubstitutionStringParser parser = new SubstitutionStringParser(groups, string);
String result = parser.readString();
Initially, we have a matcher object, of type AbstractMatcher, which has already found a match of its regular expression. The string object, of type String, is a string containing group variables. The resulting result string contains the contents of string with group variables replaced by the matching text in the appropriate element of the groups array.

Author:
The OGSA-DAI Project Team

Constructor Summary
SubstitutionStringParser(java.lang.String[] groups, java.lang.String string)
          Construct a new parser, with supplied text matched by groups in a regular expression, and a string containing group variables.
 
Method Summary
 void lex()
          Move forward to consider the next character in the string.
 java.lang.String readString()
          Return the original string, but with the group variables replaced by the corresponding values from the matched groups of text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SubstitutionStringParser

public SubstitutionStringParser(java.lang.String[] groups,
                                java.lang.String string)
Construct a new parser, with supplied text matched by groups in a regular expression, and a string containing group variables.

Parameters:
groups - the text matched by the parenthesised groups in the regular expression. The element at index zero is the string matched by the entire regular expression.
string - the string containing group variables
Method Detail

lex

public void lex()
Move forward to consider the next character in the string.


readString

public java.lang.String readString()
                            throws MalformedReplacementStringException
Return the original string, but with the group variables replaced by the corresponding values from the matched groups of text. This corresponds to the STRING non-terminal in the grammar.

Returns:
the string, with appropriate replacements made
Throws:
MalformedReplacementStringException - if the string could not be parsed