SimpleAutomaton* SimpleAutomatonParser::parse() { Token token; expect(SimpleAutomatonToken::Automaton | SimpleAutomatonToken::Eof, token = m_tokenizer.nextToken()); if (token.type() == SimpleAutomatonToken::Eof) return NULL; SimpleAutomaton* automaton = new SimpleAutomaton(); try { const SimpleAutomatonToken::Type allowed = SimpleAutomatonToken::States | SimpleAutomatonToken::Transition | SimpleAutomatonToken::InitialState |SimpleAutomatonToken::FinalStates | SimpleAutomatonToken::Eof; expect(allowed, token = m_tokenizer.nextToken()); while (token.type() != SimpleAutomatonToken::Eof) { if (token.type() == SimpleAutomatonToken::States) parseStates(*automaton); else if (token.type() == SimpleAutomatonToken::Transition) parseTransition(*automaton); else if (token.type() == SimpleAutomatonToken::InitialState) parseInitialState(*automaton); else if (token.type() == SimpleAutomatonToken::FinalStates) parseFinalStates(*automaton); expect(allowed, token = m_tokenizer.nextToken()); } } catch (...) { delete automaton; throw; } return automaton; }
bool XMLEngine::parse(const QString &data, StateList * states, TransitionList * transitions) { bool result = true; if (validator->validate(data.toAscii())) { QXmlStreamReader reader(data); if (reader.readNextStartElement()) { if (compare(reader.name(), "activity_diagram")) { result &= parseStates(&reader, states, transitions); result &= parseTransitions(&reader, states, transitions); } } result &= !reader.hasError(); } qDebug() << "Parse result" << result; return result; }
void SimpleAutomatonParser::parseFinalStates(SimpleAutomaton& automaton) { FinalStateParserOp op(automaton); parseStates(op); }