Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add function to find matching scopes

  • Loading branch information...
commit 135b98582e3c932b1724fd9496bbfe77c3959b3f 1 parent 79dfb22
Alexander Stigsen authored
Showing with 59 additions and 0 deletions.
  1. +1 −0  src/matchers.h
  2. +56 −0 src/styler_syntax.cpp
  3. +2 −0  src/styler_syntax.h
View
1  src/matchers.h
@@ -186,6 +186,7 @@ class span_matcher : public group_matcher {
bool IsSpanEnd(unsigned int callout_id);
match_matcher* GetStartMatcher() const {return m_startMatcher;};
+ match_matcher* GetEndMatcher() const {return m_endMatcher;};
matcher* GetStartMember(unsigned int callout_id) {return m_startMatcher->GetMember(callout_id);};
bool SubIsSpanStart(unsigned int) {return true;};
View
56 src/styler_syntax.cpp
@@ -79,6 +79,62 @@ void Styler_Syntax::ReStyleSub(const submatch& sm) {
}
}
+bool Styler_Syntax::GetNextMatch(const wxString& scope, unsigned int startpos, interval& match, interval& content) const {
+ if(!HaveActiveSyntax()) return false;
+
+ // We only do a very simple scope match
+ const wxString& topScope = m_topMatches.subMatcher->GetName();
+ if (topScope.StartsWith(scope)) {
+ match.start = 0;
+ match.end = m_syntax_end;
+ return true;
+ }
+
+ return GetSubNextMatch(m_topMatches, scope, startpos, match, content);
+}
+
+bool Styler_Syntax::GetSubNextMatch(const submatch& sm, const wxString& scope, unsigned int startpos, interval& match, interval& content) const {
+ for (auto_vector<stxmatch>::const_iterator p = sm.matches.begin(); p != sm.matches.end(); ++p) {
+ stxmatch& m = *(*p);
+ if (m.end <= startpos) continue;
+
+ // We only do a very simple scope match
+ if (m.m_name.StartsWith(scope)) {
+ match.start = m.start;
+ match.end = m.end;
+ content = match;
+
+ // We also want interval for inner contents (if any)
+ if (m.m_matcher && m.m_matcher->IsSpan() && m.subMatch.get()) {
+ match_matcher* startMatcher = ((span_matcher*)m.m_matcher)->GetStartMatcher();
+ match_matcher* endMatcher = ((span_matcher*)m.m_matcher)->GetEndMatcher();
+ const submatch& spansub = *m.subMatch;
+ for (auto_vector<stxmatch>::const_iterator p2 = spansub.matches.begin(); p2 != spansub.matches.end(); ++p2) {
+ stxmatch& m2 = *(*p2);
+ if (m2.m_matcher == startMatcher) content.start = m.start + m2.end;
+ if (m2.m_matcher == endMatcher) content.end = m.start + m2.start;
+ }
+ }
+ return true;
+ }
+
+ // Check if there are submatches
+ if (m.subMatch.get()) {
+ const unsigned int subpos = (startpos > m.start) ? startpos - m.start : 0;
+ if (GetSubNextMatch(*m.subMatch, scope, subpos, match, content)) {
+ match.start += m.start;
+ match.end += m.start;
+ content.start += m.start;
+ content.end += m.start;
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+
bool Styler_Syntax::UpdateSyntax() {
const cxSyntaxInfo* si = m_syntaxHandler->GetSyntax(m_doc);
if (!si) return false; // No new syntax found
View
2  src/styler_syntax.h
@@ -57,6 +57,7 @@ class Styler_Syntax : public Styler {
void GetTextWithScopes(unsigned int start, unsigned int end, vector<char>& text);
const deque<interval> GetScopeIntervals(unsigned int pos) const;
+ bool GetNextMatch(const wxString& scope, unsigned int startpos, interval& match, interval& content) const;
void Clear();
void Invalidate();
@@ -133,6 +134,7 @@ class Styler_Syntax : public Styler {
void GetSubScope(unsigned int pos, const submatch& sm, deque<const wxString*>& scopes) const;
void GetSubScopeIntervals(unsigned int pos, unsigned int offset, const submatch& sm, deque<interval>& scopes) const;
+ bool GetSubNextMatch(const submatch& sm, const wxString& scope, unsigned int startpos, interval& match, interval& content) const;
void AddCaptures(matcher& m, stxmatch& sm, unsigned int offset, const SearchInfo& si, int rc, int* ovector);
void ReInitSpan(span_matcher& sm, unsigned int start, const SearchInfo& si, int rc=0, int* ovector=NULL);
Please sign in to comment.
Something went wrong with that request. Please try again.