[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Sc-devel] [sc-users] extensions overwriting



On Feb 4, 2008, at 10:38 AM, James Harkins wrote:
Hmm... shouldn't be hard to write a parser in SC to trawl through
uninstalled quarks to locate class names and warn about conflicts...
hjh

Moving to sc-dev. This is my scary, quick and dirty contribution to this effort. It's pretty crude and will probably generate some/a lot of false positives but it will do a lot of the grunt work for us.

// check for duplicate quarks

~classes = IdentityDictionary.new;
~openBrackets = [/*40, 91,*/ 123].collect(_.asAscii);
~closeBrackets = IdentityDictionary.new
// .put($), $()
// .put($], $[)
.put($}, ${);

~checkDir = { |path|
var paths = (path ++ "*.sc").pathMatch;
paths.do({ |p|
"scanning %\n".postf(p);
~scanFile.(p);
});
};

~scanFile = { |path|
var brackets = List.new,
file = File.new(path, "r"),
ch, name, lastWasSpace = true, readChar = true;
protect {
while {
if(readChar) { ch = file.getChar } { readChar = true };
ch.notNil
} {
case
{ lastWasSpace and: { brackets.size == 0 and: { ch >= $A and: { ch <= $Z } } } }
{ name = ~getIdentifier.(file, ch);
if(name.notNil) {
~recordName.(name, path);
ch = ~skipSuperClass.(file);
readChar = false;
// } {
// Error("Unexpected end of file: %".format(path)).throw;
};
}
{ ~openBrackets.includes(ch) }
{ brackets.add(ch); }
{ ~closeBrackets[ch].notNil }
{ // [ch, brackets.last].debug("closing bracket, last");
if(brackets.last == ~closeBrackets[ch]) {
brackets.removeAt(brackets.size - 1)
// } {
// Error("Unmatched bracket in %".format(path)).throw;
};
}
{ ch.isSpace } { lastWasSpace = true }
{ lastWasSpace = false }
};
} { file.close };
};

~recordName = { |name, path|
name = name.asSymbol;
~classes[name] = ~classes[name].add(path);
};

~getIdentifier = { |file, firstChar|
var ch, chars = List.with(firstChar/*.debug("getting identifier")*/);
while { (ch = file.getChar/*.debug("next char")*/).notNil and: { ch.isAlphaNum or: { ch == $_ } } }
{ chars = chars.add(ch); 0.001.wait; };
ch.notNil.if({ chars.asArray.as(String) });
};

~skipSuperClass = { |file|
var ch;
//"swallowing spaces".debug;
while { (ch = file.getChar).notNil and: { ch.isSpace } };
if(ch/*.debug("next nonspace")*/ == $:) {
//"got colon, eating more spaces".debug;
while { (ch = file.getChar).notNil and: { ch.isSpace } };
//"eating identifier".debug;
if((ch = file.getChar).notNil) { ~getIdentifier.(file, ch) };
};
ch
};

r = Routine({
var path = (Quarks.local.path ++ "/"),
recursion = { |path|
~checkDir.(path);
0.05.wait;
((path ++ "*/").pathMatch).do({ |path|
recursion.(path);
});
};
recursion.(path);
~classes.keysValuesDo({ |name, paths|
if(paths.size > 1) {
"\nDUPLICATE CLASS %\n".postf(name);
paths.do({ |path|
"\t%\n".postf(path);
0.001.wait;
});
};
})
}).play(AppClock);


r.stop;



: H. James Harkins

: jamshark70@xxxxxxxxxxxxxxxxx

: http://www.dewdrop-world.net

.::!:.:.......:.::........:..!.::.::...:..:...:.:.:.:..:


"Come said the Muse,

Sing me a song no poet has yet chanted,

Sing me the universal."  -- Whitman