has any one any idea about this applet?
code as below:
/**
* SourceMap class,
* reads a generic language source code and returns its map.
* _______________ _______________ _______________ _______________ __
* The SourceMap goals is to create a map of a generic script/program
language.
* The getMap method returns an array/list of arrays/dictionary/
objects
* of source map using delimeters variable to map correctly:
* - multi line comments
* - single line comments
* - double quoted strings
* - single quoted strings
* - pure code
* - everything else (for example regexp [/re/] with javascript),
just adding a correct delimeter
* --------------------------------------------------------------
* What about the delimeter
* It's an array/list of arrays/dictionary/obects with some
properties to find what you're looking for.
*
* parameters are:
* - name, the name of the delimeter (i.e. "doublequot e")
* - start, one or mode chars to find as start delimeter (i.e. " for
double quoted string)
* - end, one or mode chars to find as end delimeter (i.e. " for
double quoted string) [end should be an array/list too]
*
* optional parameters are:
* - noslash, if true find the end of the delimeter only if last char
is not slashed (i.e. "string\"te st" find " after test)
* - match, if choosed language has regexp, verify if string from
start to end matches used regexp (i.e. /^\/[^\n\r]+\/$/ for JavaScript
regexp)
*
* If end parameter is an array, match and noslash are not supported
(i.e. ["\n", "\r"] for end delimeter of a single line comment)
* --------------------------------------------------------------
* What about SourceMap usage
* It should be a good solution to create sintax highlighter, parser,
* verifier or some other source code parsing procedure
* --------------------------------------------------------------
* What about SourceMap performance script/languages
* I've created different version of this class to test each script/
program language performance too.
* Python with or without Psyco is actually the faster parser.
* --------------------------------------------------------------
* @Compatibility >= JavaScript 1.1
* @Author Andrea Giammarchi
* @Site http://www.devpro.it/
* @Date 2006/08/01
* @LastMOd 2006/08/01
* @Version 0.1
*/
function SourceMap() {
/**
* public method
* getMap(source:s tring, delimeters:arra y):array
* Maps the source code using $delimeters rules and returns map as an
array
* NOTE: read comments to know more about map and delimeter
*
* @param string generic source code
* @param array array with nested objects with code rules
*/
this.getMap = function(source , delimeters) {
// "unsigned integer" variables
var sourcePosition = 0,
delimetersPosit ion = 0,
findLength = 0,
len = 0,
tempIndex = 0,
sourceLength = source.length,
delimetersLengt h = delimeters.leng th;
// integer variables
var tempPosition = -1,
endPosition = -1;
// array variables
var map = [],
tempMap = [];
// object variable
var tempDelimeter = {};
while(sourcePos ition < sourceLength) {
endPosition = -1;
for(delimetersP osition = 0; delimetersPosit ion < delimetersLengt h;
delimetersPosit ion++) {
tempPosition =
source.indexOf( delimeters[delimetersPosit ion].start, sourcePosition) ;
if(tempPosition !== -1 && (tempPosition < endPosition ||
endPosition === -1)) {
endPosition = tempPosition;
tempIndex = delimetersPosit ion;
}
}
if(endPosition !== -1) {
sourcePosition = endPosition;
tempDelimeter = delimeters[tempIndex];
findLength = tempDelimeter.s tart.length;
if(tempDelimete r.end.construct or === Array) {
delimetersPosit ion = 0;
endPosition = -1;
for(len = tempDelimeter.e nd.length; delimetersPosit ion < len;
delimetersPosit ion++) {
tempPosition =
source.indexOf( tempDelimeter.e nd[delimetersPosit ion], sourcePosition +
findLength);
if(tempPosition !== -1 && (tempPosition < endPosition ||
endPosition === -1)) {
endPosition = tempPosition;
tempIndex = delimetersPosit ion;
}
}
if(endPosition !== -1)
endPosition = endPosition + tempDelimeter.e nd[tempIndex].length;
else
endPosition = sourceLength;
map.push({name: tempDelimeter.n ame, start:sourcePos ition,
end:endPosition });
sourcePosition = endPosition - 1;
}
else if(tempDelimete r.match) {
tempPosition = source.indexOf( tempDelimeter.e nd, sourcePosition +
findLength);
len = tempDelimeter.e nd.length;
if(tempPosition !== -1 &&
tempDelimeter.m atch.test(sourc e.substr(source Position, tempPosition -
sourcePosition + len))) {
endPosition = tempDelimeter.n oslash ? __endCharNoSlas h(source,
sourcePosition, tempDelimeter.e nd, sourceLength) : tempPosition + len;
map.push({name: tempDelimeter.n ame, start:sourcePos ition,
end:endPosition });
sourcePosition = endPosition - 1;
}
}
else {
if(tempDelimete r.noslash)
endPosition = __endCharNoSlas h(source, sourcePosition,
tempDelimeter.e nd, sourceLength);
else {
tempPosition = source.indexOf( tempDelimeter.e nd, sourcePosition
+ findLength);
if(tempPosition !== -1)
endPosition = tempPosition + tempDelimeter.e nd.length;
else
endPosition = sourceLength;
}
map.push({name: tempDelimeter.n ame, start:sourcePos ition,
end:endPosition });
sourcePosition = endPosition - 1;
}
}
else
sourcePosition = sourceLength - 1;
++sourcePositio n;
}
len = map.length;
if(len === 0)
tempMap.push({n ame:'code', start:0, end:sourceLengt h});
else {
for(tempIndex = 0; tempIndex < len; tempIndex++) {
if(tempIndex === 0 && map[tempIndex].start 0)
tempMap.push({n ame:'code', start:0, end:map[tempIndex].start});
else if(tempIndex 0 && map[tempIndex].start >
map[tempIndex-1].end)
tempMap.push({n ame:'code', start:map[tempIndex-1].end,
end:map[tempIndex].start});
tempMap.push({n ame:map[tempIndex].name,
start:map[tempIndex].start, end:map[tempIndex].end});
if(tempIndex + 1 === len && map[tempIndex].end < sourceLength)
tempMap.push({n ame:'code', start:map[tempIndex].end,
end:sourceLengt h});
}
}
return tempMap;
};
function __endCharNoSlas h(source, position, find, len) {
var temp = find.length;
do {
position = source.indexOf( find, position + 1);
}while(position !== -1 && !__charNoSlash( source, position));
if(position === -1) position = len - temp;
return position + temp;
};
function __charNoSlash(s ource, position) {
var next = 1,
len = position - next;
while(len 0 && source.charAt(l en) === '\\') len = position - (+
+next);
return ((next - 1) % 2 === 0);
};
};
Comment