diff --git a/autotests/syntaxrepository_test.cpp b/autotests/syntaxrepository_test.cpp --- a/autotests/syntaxrepository_test.cpp +++ b/autotests/syntaxrepository_test.cpp @@ -192,16 +192,21 @@ void testIncludedDefinitions() { - auto def = m_repo.definitionForName(QLatin1String("C++")); + auto def = m_repo.definitionForName(QLatin1String("PHP (HTML)")); QVERIFY(def.isValid()); auto defs = def.includedDefinitions(); const QStringList expectedDefinitionNames = { - QStringLiteral("ISO C++"), - QStringLiteral("GCCExtensions"), - QStringLiteral("Doxygen"), + QStringLiteral("PHP/PHP"), QStringLiteral("Alerts"), - QStringLiteral("Modelines") + QStringLiteral("CSS/PHP"), + QStringLiteral("JavaScript/PHP"), + QStringLiteral("Doxygen"), + QStringLiteral("Modelines"), + QStringLiteral("HTML"), + QStringLiteral("CSS"), + QStringLiteral("SQL (MySQL)"), + QStringLiteral("JavaScript") }; QStringList definitionNames; for (auto d : defs) { diff --git a/src/lib/definition.cpp b/src/lib/definition.cpp --- a/src/lib/definition.cpp +++ b/src/lib/definition.cpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -241,22 +240,27 @@ { d->load(); - QVector definitions; - - QQueue queue; - queue.enqueue(*this); + // init worklist and result used as guard with this definition + QVector queue{*this}; + QVector definitions{*this}; while (!queue.isEmpty()) { - const auto definition = queue.dequeue(); - definitions.push_back(definition); - // Iterate all context rules to find associated Definitions. This will - // automatically catch other Definitions referenced with IncludeRuldes. - foreach (const auto & context, definition.d->contexts) { - foreach (const auto &rule, context->rules()) { - if ((!definitions.contains(rule->definition())) && - (!queue.contains(rule->definition()))) - { - queue.enqueue(rule->definition()); + // automatically catch other Definitions referenced with IncludeRuldes or ContextSwitch. + const auto definition = queue.takeLast(); + for (const auto & context : definition.d->contexts) { + for (const auto &rule : context->rules()) { + // handle include rules like inclusion + if (!definitions.contains(rule->definition())) { + queue.push_back(rule->definition()); + definitions.push_back(rule->definition()); + } + + // handle context switch context inclusion + if (auto switchContext = rule->context().context()) { + if (!definitions.contains(switchContext->definition())) { + queue.push_back(switchContext->definition()); + definitions.push_back(switchContext->definition()); + } } } }