Changeset View
Changeset View
Standalone View
Standalone View
src/lib/rule.cpp
Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Line(s) | 75 | if (isOctalChar(c)) { | |||
---|---|---|---|---|---|
80 | } | 80 | } | ||
81 | return newOffset; | 81 | return newOffset; | ||
82 | } | 82 | } | ||
83 | 83 | | |||
84 | return offset; | 84 | return offset; | ||
85 | } | 85 | } | ||
86 | 86 | | |||
87 | static QString replaceCaptures(const QString &pattern, const QStringList &captures, bool quote) | 87 | static QString replaceCaptures(const QString &pattern, const QStringList &captures, bool quote) | ||
88 | { | | |||
89 | auto result = pattern; | | |||
90 | for (int i = captures.size() - 1; i >= 1; --i) { | | |||
91 | result.replace(QLatin1Char('%') + QString::number(i), quote ? QRegularExpression::escape(captures.at(i)) : captures.at(i)); | 88 | { | ||
92 | } | 89 | auto result = pattern; | ||
93 | return result; | 90 | for (int i = captures.size() - 1; i >= 1; --i) { | ||
94 | } | 91 | result.replace(QLatin1Char('%') + QString::number(i), quote ? QRegularExpression::escape(captures.at(i)) : captures.at(i)); | ||
95 | 92 | } | |||
96 | Definition Rule::definition() const | 93 | return result; | ||
97 | { | 94 | } | ||
98 | return m_def.definition(); | 95 | | ||
99 | } | 96 | Definition Rule::definition() const | ||
100 | 97 | { | |||
101 | void Rule::setDefinition(const Definition &def) | 98 | return m_def.definition(); | ||
102 | { | 99 | } | ||
103 | m_def = def; | 100 | | ||
104 | 101 | void Rule::setDefinition(const Definition &def) | |||
105 | // cache for DefinitionData::wordDelimiters, is accessed VERY often | 102 | { | ||
106 | m_wordDelimiter = &DefinitionData::get(m_def.definition())->wordDelimiters; | 103 | m_def = def; | ||
107 | } | 104 | } | ||
108 | 105 | | |||
109 | bool Rule::load(QXmlStreamReader &reader) | 106 | bool Rule::load(QXmlStreamReader &reader) | ||
110 | { | 107 | { | ||
111 | Q_ASSERT(reader.tokenType() == QXmlStreamReader::StartElement); | 108 | Q_ASSERT(reader.tokenType() == QXmlStreamReader::StartElement); | ||
112 | 109 | | |||
113 | m_attribute = reader.attributes().value(QStringLiteral("attribute")).toString(); | 110 | m_attribute = reader.attributes().value(QStringLiteral("attribute")).toString(); | ||
114 | if (reader.name() != QLatin1String("IncludeRules")) // IncludeRules uses this with a different semantic | 111 | if (reader.name() != QLatin1String("IncludeRules")) // IncludeRules uses this with a different semantic | ||
115 | m_context.parse(reader.attributes().value(QStringLiteral("context"))); | 112 | m_context.parse(reader.attributes().value(QStringLiteral("context"))); | ||
116 | m_firstNonSpace = Xml::attrToBool(reader.attributes().value(QStringLiteral("firstNonSpace"))); | 113 | m_firstNonSpace = Xml::attrToBool(reader.attributes().value(QStringLiteral("firstNonSpace"))); | ||
117 | m_lookAhead = Xml::attrToBool(reader.attributes().value(QStringLiteral("lookAhead"))); | 114 | m_lookAhead = Xml::attrToBool(reader.attributes().value(QStringLiteral("lookAhead"))); | ||
118 | bool colOk = false; | 115 | bool colOk = false; | ||
119 | m_column = reader.attributes().value(QStringLiteral("column")).toInt(&colOk); | 116 | m_column = reader.attributes().value(QStringLiteral("column")).toInt(&colOk); | ||
117 | if (!colOk) | ||||
118 | m_column = -1; | ||||
119 | | ||||
120 | if (!colOk) | 120 | auto regionName = reader.attributes().value(QLatin1String("beginRegion")); | ||
121 | m_column = -1; | 121 | if (!regionName.isEmpty()) | ||
122 | 122 | m_beginRegion = FoldingRegion(FoldingRegion::Begin, DefinitionData::get(m_def.definition())->foldingRegionId(regionName.toString())); | |||
123 | auto regionName = reader.attributes().value(QLatin1String("beginRegion")); | 123 | regionName = reader.attributes().value(QLatin1String("endRegion")); | ||
124 | if (!regionName.isEmpty()) | 124 | if (!regionName.isEmpty()) | ||
125 | m_beginRegion = FoldingRegion(FoldingRegion::Begin, DefinitionData::get(m_def.definition())->foldingRegionId(regionName.toString())); | 125 | m_endRegion = FoldingRegion(FoldingRegion::End, DefinitionData::get(m_def.definition())->foldingRegionId(regionName.toString())); | ||
126 | regionName = reader.attributes().value(QLatin1String("endRegion")); | 126 | | ||
127 | if (!regionName.isEmpty()) | 127 | auto result = doLoad(reader); | ||
128 | m_endRegion = FoldingRegion(FoldingRegion::End, DefinitionData::get(m_def.definition())->foldingRegionId(regionName.toString())); | 128 | | ||
129 | 129 | if (m_lookAhead && m_context.isStay()) | |||
130 | auto result = doLoad(reader); | 130 | result = false; | ||
131 | 131 | | |||
132 | if (m_lookAhead && m_context.isStay()) | 132 | // be done with this rule, skip all subelements, e.g. no longer supported sub-rules | ||
133 | result = false; | 133 | reader.skipCurrentElement(); | ||
134 | 134 | return result; | |||
135 | // be done with this rule, skip all subelements, e.g. no longer supported sub-rules | 135 | } | ||
136 | reader.skipCurrentElement(); | 136 | | ||
137 | return result; | 137 | void Rule::resolveContext() | ||
138 | } | 138 | { | ||
139 | 139 | m_context.resolve(m_def.definition()); | |||
140 | void Rule::resolveContext() | 140 | | ||
141 | { | 141 | // cache for DefinitionData::wordDelimiters, is accessed VERY often | ||
142 | m_context.resolve(m_def.definition()); | 142 | m_wordDelimiter = &DefinitionData::get(m_def.definition())->wordDelimiters; | ||
143 | } | 143 | } | ||
144 | 144 | | |||
145 | void Rule::resolveAttributeFormat(Context *lookupContext) | 145 | void Rule::resolveAttributeFormat(Context *lookupContext) | ||
146 | { | 146 | { | ||
147 | /** | 147 | /** | ||
148 | * try to get our format from the definition we stem from | 148 | * try to get our format from the definition we stem from | ||
149 | */ | 149 | */ | ||
150 | if (!m_attribute.isEmpty()) { | 150 | if (!m_attribute.isEmpty()) { | ||
▲ Show 20 Lines • Show All 513 Lines • Show Last 20 Lines |