|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--uk.org.ogsadai.activity.files.SubstitutionStringParser
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:
where n is an integer, 0 <= n <= 9; c is a character.
STRING ::=CHAR | CHAR STRING CHAR ::=\c | c | VARVAR ::=$INT |${INT}INT ::=n | n INT
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.
| 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 |
public SubstitutionStringParser(java.lang.String[] groups,
java.lang.String string)
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 |
public void lex()
public java.lang.String readString()
throws MalformedReplacementStringException
MalformedReplacementStringException - if the string could not be parsed
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||