}
private void parseState(BNFParseResultImpl result) {
BNFPathState sp = (BNFPathState) stack.peek();
BNFState state = sp.getState();
BNFToken token = sp.getToken();
if (!state.isTerminal()) {
BNFStateDefinition sd = stateDefinitions.get(state.getName());
if (sd == null) {
throw new RuntimeException("unknown state " + state.getName());
}
pushToStackOrFirstState(token, sd);
} else if (state.getClass().equals(BNFStateEmpty.class)) {
if (isEmpty(token)) {
result.setSuccess(true);
}
BNFState rewindState = stack.rewindStackEmptyState();
pushToStack(rewindState, token);
} else if (state.match(token)) {
result.setSuccess(true);
token = token.getNextToken();
result.setMaxMatchToken(token);
BNFState rewindState = stack.rewindStackMatchedToken();
pushToStack(rewindState, token);
} else {
result.setSuccess(false);
BNFState nextState = stack.rewindStackUnmatchedToken();
pushToStack(nextState, token);
}
}