Browse Source

Throw descriptive exception when escape character '@' is at the end of a highlighting expression.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3439 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 18 years ago
parent
commit
ce47d3c5db
  1. 110
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs

110
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs

@ -786,6 +786,8 @@ namespace ICSharpCode.TextEditor.Document
switch (expr[i]) { switch (expr[i]) {
case '@': // "special" meaning case '@': // "special" meaning
++i; ++i;
if (i == expr.Length)
throw new HighlightingDefinitionInvalidException("Unexpected end of @ sequence, use @@ to look for a single @.");
switch (expr[i]) { switch (expr[i]) {
case '!': // don't match the following expression case '!': // don't match the following expression
StringBuilder whatmatch = new StringBuilder(); StringBuilder whatmatch = new StringBuilder();
@ -819,69 +821,69 @@ namespace ICSharpCode.TextEditor.Document
switch (expr[i]) { switch (expr[i]) {
case '@': // "special" meaning case '@': // "special" meaning
++i; ++i;
if (i < expr.Length) { if (i == expr.Length)
switch (expr[i]) { throw new HighlightingDefinitionInvalidException("Unexpected end of @ sequence, use @@ to look for a single @.");
case 'C': // match whitespace or punctuation switch (expr[i]) {
if (index + j == lineSegment.Offset || index + j >= lineSegment.Offset + lineSegment.Length) { case 'C': // match whitespace or punctuation
// nothing (EOL or SOL) if (index + j == lineSegment.Offset || index + j >= lineSegment.Offset + lineSegment.Length) {
} else { // nothing (EOL or SOL)
char ch = document.GetCharAt(lineSegment.Offset + index + j); } else {
if (!Char.IsWhiteSpace(ch) && !Char.IsPunctuation(ch)) { char ch = document.GetCharAt(lineSegment.Offset + index + j);
return false; if (!Char.IsWhiteSpace(ch) && !Char.IsPunctuation(ch)) {
} return false;
} }
break; }
case '!': // don't match the following expression break;
{ case '!': // don't match the following expression
StringBuilder whatmatch = new StringBuilder(); {
++i; StringBuilder whatmatch = new StringBuilder();
while (i < expr.Length && expr[i] != '@') { ++i;
whatmatch.Append(expr[i++]); while (i < expr.Length && expr[i] != '@') {
} whatmatch.Append(expr[i++]);
if (lineSegment.Offset + index + j + whatmatch.Length < document.TextLength) { }
int k = 0; if (lineSegment.Offset + index + j + whatmatch.Length < document.TextLength) {
for (; k < whatmatch.Length; ++k) { int k = 0;
char docChar = ignoreCase ? Char.ToUpperInvariant(document.GetCharAt(lineSegment.Offset + index + j + k)) : document.GetCharAt(lineSegment.Offset + index + j + k); for (; k < whatmatch.Length; ++k) {
char spanChar = ignoreCase ? Char.ToUpperInvariant(whatmatch[k]) : whatmatch[k]; char docChar = ignoreCase ? Char.ToUpperInvariant(document.GetCharAt(lineSegment.Offset + index + j + k)) : document.GetCharAt(lineSegment.Offset + index + j + k);
if (docChar != spanChar) { char spanChar = ignoreCase ? Char.ToUpperInvariant(whatmatch[k]) : whatmatch[k];
break; if (docChar != spanChar) {
} break;
}
if (k >= whatmatch.Length) {
return false;
} }
} }
if (k >= whatmatch.Length) {
return false;
}
}
// --j; // --j;
break; break;
}
case '-': // don't match the expression before
{
StringBuilder whatmatch = new StringBuilder();
++i;
while (i < expr.Length && expr[i] != '@') {
whatmatch.Append(expr[i++]);
} }
case '-': // don't match the expression before if (index - whatmatch.Length >= 0) {
{ int k = 0;
StringBuilder whatmatch = new StringBuilder(); for (; k < whatmatch.Length; ++k) {
++i; char docChar = ignoreCase ? Char.ToUpperInvariant(document.GetCharAt(lineSegment.Offset + index - whatmatch.Length + k)) : document.GetCharAt(lineSegment.Offset + index - whatmatch.Length + k);
while (i < expr.Length && expr[i] != '@') { char spanChar = ignoreCase ? Char.ToUpperInvariant(whatmatch[k]) : whatmatch[k];
whatmatch.Append(expr[i++]); if (docChar != spanChar)
break;
} }
if (index - whatmatch.Length >= 0) { if (k >= whatmatch.Length) {
int k = 0; return false;
for (; k < whatmatch.Length; ++k) {
char docChar = ignoreCase ? Char.ToUpperInvariant(document.GetCharAt(lineSegment.Offset + index - whatmatch.Length + k)) : document.GetCharAt(lineSegment.Offset + index - whatmatch.Length + k);
char spanChar = ignoreCase ? Char.ToUpperInvariant(whatmatch[k]) : whatmatch[k];
if (docChar != spanChar)
break;
}
if (k >= whatmatch.Length) {
return false;
}
} }
// --j;
break;
}
case '@': // matches @
if (index + j >= lineSegment.Length || '@' != document.GetCharAt(lineSegment.Offset + index + j)) {
return false;
} }
// --j;
break; break;
} }
case '@': // matches @
if (index + j >= lineSegment.Length || '@' != document.GetCharAt(lineSegment.Offset + index + j)) {
return false;
}
break;
} }
break; break;
default: default:

Loading…
Cancel
Save