}
// do we need to report errors for that?
if ( lines[i].equals( expanded[lastExpanded] ) ) {
// report error
this.addError( new ExpanderException( "Unable to expand: [" + lines[i] + "]",
i + lineOffset ) );
}
// but if the original starts with a "-", it means we need to add it
// as a constraint to the previous pattern
if ( trimmed.startsWith( "-" ) && (!lines[i].equals( expanded[lastExpanded] )) ) {
int lastMatchStart = -1;
int lastMatchEnd = -1;
String constraints = "";
if ( lastPattern >= 0 ) {
final Matcher m2 = patternFinder.matcher( expanded[lastPattern] );
while ( m2.find() ) {
lastMatchStart = m2.start();
lastMatchEnd = m2.end();
constraints = m2.group( 1 ).trim();
}
}
if ( lastMatchStart > -1 ) {
// rebuilding previous pattern structure
expanded[lastPattern] = expanded[lastPattern].substring( 0,
lastMatchStart ) + "( " + constraints + ((constraints.length() == 0) ? "" : ", ") + expanded[lastExpanded].trim() + " )" + expanded[lastPattern].substring( lastMatchEnd );
} else {
// error, pattern not found to add constraint to
// TODO: can we report character position?
this.addError( new ExpanderException( "No pattern was found to add the constraint to: " + lines[i],
i + lineOffset ) );
}
lastExpanded--;
} else {
lastPattern = lastExpanded;