forked from qt-creator/qt-creator
GenericHighlighter: Fix parsing of HTML/PHP definition file
Change-Id: I54e43e0e0d5c55fee51ff001dfb92b1b8eb47d30 Reviewed-by: Christian Stenger <christian.stenger@digia.com> Reviewed-by: David Schulz <david.schulz@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
6a6d903db8
commit
6bb5903c13
@@ -238,17 +238,22 @@ void HighlightDefinitionHandler::contextElementStarted(const QXmlAttributes &att
|
|||||||
void HighlightDefinitionHandler::ruleElementStarted(const QXmlAttributes &atts,
|
void HighlightDefinitionHandler::ruleElementStarted(const QXmlAttributes &atts,
|
||||||
const QSharedPointer<Rule> &rule)
|
const QSharedPointer<Rule> &rule)
|
||||||
{
|
{
|
||||||
|
const QString context = atts.value(kContext);
|
||||||
// The definition of a rule is not necessarily the same of its enclosing context because of
|
// The definition of a rule is not necessarily the same of its enclosing context because of
|
||||||
// externally included rules.
|
// externally included rules.
|
||||||
rule->setDefinition(m_definition);
|
rule->setDefinition(m_definition);
|
||||||
rule->setItemData(atts.value(kAttribute));
|
rule->setItemData(atts.value(kAttribute));
|
||||||
rule->setContext(atts.value(kContext));
|
rule->setContext(context);
|
||||||
rule->setBeginRegion(atts.value(kBeginRegion));
|
rule->setBeginRegion(atts.value(kBeginRegion));
|
||||||
rule->setEndRegion(atts.value(kEndRegion));
|
rule->setEndRegion(atts.value(kEndRegion));
|
||||||
rule->setLookAhead(atts.value(kLookAhead));
|
rule->setLookAhead(atts.value(kLookAhead));
|
||||||
rule->setFirstNonSpace(atts.value(kFirstNonSpace));
|
rule->setFirstNonSpace(atts.value(kFirstNonSpace));
|
||||||
rule->setColumn(atts.value(kColumn));
|
rule->setColumn(atts.value(kColumn));
|
||||||
|
|
||||||
|
if (context.contains(kDoubleHash)) {
|
||||||
|
IncludeRulesInstruction includeInstruction(context, m_currentContext->rules().size(), QString());
|
||||||
|
m_currentContext->addIncludeRulesInstruction(includeInstruction);
|
||||||
|
}
|
||||||
if (m_currentRule.isEmpty())
|
if (m_currentRule.isEmpty())
|
||||||
m_currentContext->addRule(rule);
|
m_currentContext->addRule(rule);
|
||||||
else
|
else
|
||||||
@@ -428,13 +433,17 @@ void HighlightDefinitionHandler::processIncludeRules(const QSharedPointer<Contex
|
|||||||
|
|
||||||
QSharedPointer<Context> sourceContext;
|
QSharedPointer<Context> sourceContext;
|
||||||
const QString &sourceName = instruction.sourceContext();
|
const QString &sourceName = instruction.sourceContext();
|
||||||
if (sourceName.startsWith(kDoubleHash)) {
|
if (sourceName.contains(kDoubleHash)) {
|
||||||
// This refers to an external definition. The rules included are the ones from its
|
// This refers to an external definition. Context can be specified before the double
|
||||||
|
// hash (e.g. Normal##Javascript). If it isn't, the rules included are the ones from its
|
||||||
// initial context. Others contexts and rules from the external definition will work
|
// initial context. Others contexts and rules from the external definition will work
|
||||||
// transparently to the highlighter. This is because contexts and rules know the
|
// transparently to the highlighter. This is because contexts and rules know the
|
||||||
// definition they are from.
|
// definition they are from.
|
||||||
QString externalName = QString::fromRawData(sourceName.unicode() + 2,
|
const QStringList values = sourceName.split(kDoubleHash);
|
||||||
sourceName.length() - 2);
|
if (values.count() != 2)
|
||||||
|
return;
|
||||||
|
const QString externalContext = values.at(0);
|
||||||
|
const QString externalName = values.at(1);
|
||||||
const QString &id = Manager::instance()->definitionIdByName(externalName);
|
const QString &id = Manager::instance()->definitionIdByName(externalName);
|
||||||
|
|
||||||
// If there is an incorrect circular dependency among definitions this is skipped.
|
// If there is an incorrect circular dependency among definitions this is skipped.
|
||||||
@@ -446,7 +455,10 @@ void HighlightDefinitionHandler::processIncludeRules(const QSharedPointer<Contex
|
|||||||
if (externalDefinition.isNull() || !externalDefinition->isValid())
|
if (externalDefinition.isNull() || !externalDefinition->isValid())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
sourceContext = externalDefinition->initialContext();
|
if (externalContext.isEmpty())
|
||||||
|
sourceContext = externalDefinition->initialContext();
|
||||||
|
else
|
||||||
|
sourceContext = externalDefinition->context(externalContext);
|
||||||
} else if (!sourceName.startsWith(kHash)) {
|
} else if (!sourceName.startsWith(kHash)) {
|
||||||
sourceContext = m_definition->context(sourceName);
|
sourceContext = m_definition->context(sourceName);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user