Bug 232985 - Add RegExp support to source formatter (purple!).

Venkman only.
r=rginda
This commit is contained in:
silver%warwickcompsoc.co.uk 2006-05-24 21:14:54 +00:00
Родитель ec01528c14
Коммит 989547a0d8
2 изменённых файлов: 30 добавлений и 1 удалений

Просмотреть файл

@ -460,6 +460,7 @@ const STRING1 = 2;
const STRING2 = 3;
const WORD = 4;
const NUMBER = 5;
const REGEXP = 6;
var keywords = {
"abstract": 1, "boolean": 1, "break": 1, "byte": 1, "case": 1, "catch": 1,
@ -480,7 +481,7 @@ var specialChars = /[&<>]/g;
var wordStart = /[\w\\\$]/;
var numberStart = /[\d]/;
var otherEnd = /[\w\$\"\']|\\|\/\/|\/\*/;
var otherEnd = /[\w\$\"\']|\\|\//;
var wordEnd = /[^\w\$]/;
var string1End = /\'/;
var string2End = /\"/;
@ -541,6 +542,10 @@ function colorizeSourceLine (line, previousState)
case NUMBER:
result += phrase;
break;
case REGEXP:
result += "<r>" + phrase.replace(specialChars, escapeSpecial) +
"</r>";
break;
}
};
@ -635,6 +640,22 @@ function colorizeSourceLine (line, previousState)
/* look for the end of a number */
pos = line.search (numberEnd);
break;
case REGEXP:
/* look for the end of the regexp */
pos = line.substr(1).search("/") + 1;
while (pos > 0 && line[pos - 1] == "\\")
{
/* if the previous char was \, we are escaped and need
* to keep trying. */
pos += 1;
var newPos = line.substr(pos).search("/");
if (newPos > -1)
pos += newPos;
}
if (pos != -1)
++pos;
break;
}
if (pos == -1)
@ -715,6 +736,10 @@ function colorizeSourceLine (line, previousState)
previousState = OTHER;
line = "";
}
else if (ch == "/")
{
previousState = REGEXP;
}
else if (ch.search (numberStart) == 0)
{
previousState = NUMBER;

Просмотреть файл

@ -121,3 +121,7 @@ c {
t {
color: darkgreen;
}
r {
color: purple;
}