* @return
* @throws BadLocationException
*
*/
private Section identifyAnyLabel() throws BadLocationException {
Section section = base;
Symbol symbolSection = null;
Section i = null; // section before symbol section
int state = 1; // initial state must not be RESET
while (section != null) {
// final String content = section.getContent(document); // for
// debugging
Section nextSection = section.getNextSection();
switch (state) {
case RESET:
// TODO: Two LINE_SEPARATOR sections case
if (section instanceof LineSeparator) {
i = section;
state = 1;
}/* else { // Stay in current state. } */
break;
case 1: // The initial state
if (section instanceof LineSeparator) {
break; // Stay in current state.
}
if (section instanceof Symbol) {
symbolSection = (Symbol) section;
state = 2;
} else {
if (section instanceof WhiteSpace) {
i = section;
state = 3;
} else {
state = RESET;
}
}
break;
case 2:
if ((section instanceof WhiteSpace)
|| (section instanceof LineSeparator)) {
state = MATCH;
} else {
if (section instanceof CharacterLiteral) {
if (document.getChar(section.getOffset()) == ':') {
state = MATCH;
} else {
state = RESET;
}
} else {
state = RESET;
}
}
break;
case 3:
if (section instanceof Symbol) {
symbolSection = (Symbol) section;
state = 4;
} else {
state = RESET;
}
break;
case 4:
if (section instanceof CharacterLiteral) {
final char c = document.getChar(section.getOffset());
if (c == ':') {
state = MATCH;
} else {
state = RESET;
}
} else {
state = RESET;
}
break;
case MATCH:
// NOP here
// TODO Review
break;
default:
state = RESET;
}
if (state == MATCH) {
// Replace SYMBOL with LABEL.
Section label = new Label();
label.copyPosition(symbolSection);
label.setNextSection(symbolSection.getNextSection());
i.setNextSection(label);
state = RESET;
}
section = nextSection;