add token module ignoring

This commit is contained in:
John Bintz 2008-10-21 07:06:28 -04:00
parent f281a1e838
commit e00809afa1
4 changed files with 37 additions and 4 deletions

6
README
View File

@ -47,6 +47,12 @@ the following in your code:
//harmonious @maxdb //harmonious @maxdb
* To ignore the version information for a particular module for a
particular token (ex: the rename function of the zip module), place
at the top of the file the following:
//harmonious @zip:rename
No build instructions for Windows yet, but Cygwin + haXe for Windows should No build instructions for Windows yet, but Cygwin + haXe for Windows should
be able to perform the build. be able to perform the build.

View File

@ -8,12 +8,14 @@ import ConstantTokenProcessor;
class CodeParser { class CodeParser {
public var token_processors(get_token_processors, null) : Hash<TokenProcessor>; public var token_processors(get_token_processors, null) : Hash<TokenProcessor>;
public var ignored_modules(get_ignored_modules, null) : Hash<Bool>; public var ignored_modules(get_ignored_modules, null) : Hash<Bool>;
public var ignored_tokens_in_modules(get_ignored_tokens_in_modules, null) : Hash<Hash<Bool>>;
public static var processor_types = [ "FunctionTokenProcessor", "ConstantTokenProcessor" ]; public static var processor_types = [ "FunctionTokenProcessor", "ConstantTokenProcessor" ];
public function new() { public function new() {
this.token_processors = new Hash<TokenProcessor>(); this.token_processors = new Hash<TokenProcessor>();
this.ignored_modules = new Hash<Bool>(); this.ignored_modules = new Hash<Bool>();
this.ignored_tokens_in_modules = new Hash<Hash<Bool>>();
} }
#if neko #if neko
@ -38,6 +40,7 @@ class CodeParser {
public function get_token_processors() { return this.token_processors; } public function get_token_processors() { return this.token_processors; }
public function get_ignored_modules() { return this.ignored_modules; } public function get_ignored_modules() { return this.ignored_modules; }
public function get_ignored_tokens_in_modules() { return this.ignored_tokens_in_modules; }
/** /**
Flatten a list of hashes into a single hash. Flatten a list of hashes into a single hash.
@ -143,8 +146,22 @@ class CodeParser {
for (token in new_tokens_to_ignore) { for (token in new_tokens_to_ignore) {
if (token.charAt(0) == "@") { if (token.charAt(0) == "@") {
if (token.toLowerCase() != "@php") { if (token.toLowerCase() != "@php") {
if (token.indexOf(":") != -1) {
var parts = token.split(":");
var module = parts[0].substr(1);
var token = parts[1];
if (!this.ignored_tokens_in_modules.exists(module)) {
this.ignored_tokens_in_modules.set(token, new Hash<Bool>());
}
var token_info = this.ignored_tokens_in_modules.get(token);
token_info.set(module, true);
this.ignored_tokens_in_modules.set(token, token_info);
} else {
this.ignored_modules.set(token.substr(1), true); this.ignored_modules.set(token.substr(1), true);
} }
}
} else { } else {
tokens_to_ignore_hash.set(token, true); tokens_to_ignore_hash.set(token, true);
} }

View File

@ -124,7 +124,7 @@ class CodeVersionInformation {
Create a new CodeVersionInformation object based on the provided Create a new CodeVersionInformation object based on the provided
Result set and, optionally, while ignoring the provided modules. Result set and, optionally, while ignoring the provided modules.
**/ **/
public function new(results : Array<Result>, ?ignored_modules : Hash<Bool>) { public function new(results : Array<Result>, ?ignored_modules : Hash<Bool>, ?ignored_tokens_in_modules : Hash<Hash<Bool>>) {
var start_minimum_versions = new Hash<Array<String>>(); var start_minimum_versions = new Hash<Array<String>>();
var start_maximum_versions = new Hash<Array<String>>(); var start_maximum_versions = new Hash<Array<String>>();
@ -142,6 +142,14 @@ class CodeVersionInformation {
if (ignored_modules != null) { if (ignored_modules != null) {
ok_to_use = !ignored_modules.exists(source); ok_to_use = !ignored_modules.exists(source);
} }
if (ok_to_use) {
if (ignored_tokens_in_modules != null) {
if (ignored_tokens_in_modules.exists(result.token)) {
var token_info = ignored_tokens_in_modules.get(result.token);
ok_to_use = !token_info.exists(source);
}
}
}
if (ok_to_use) { if (ok_to_use) {
if (!internal_minimum_version.exists(source)) { if (!internal_minimum_version.exists(source)) {

View File

@ -8,7 +8,8 @@ class TestCodeParser extends haxe.unit.TestCase {
[ "//harmonious json_encode\narray_shift() json_encode()\n//harmonious_end\njson_encode()", "2", "{minimum => {PHP => 5.2.0, json => 1.2.0}, maximum => {}}" ], [ "//harmonious json_encode\narray_shift() json_encode()\n//harmonious_end\njson_encode()", "2", "{minimum => {PHP => 5.2.0, json => 1.2.0}, maximum => {}}" ],
[ "//harmonious @json\narray_shift() json_encode()\n//harmonious_end\njson_encode()", "2", "{minimum => {PHP => 5.2.0}, maximum => {}}" ], [ "//harmonious @json\narray_shift() json_encode()\n//harmonious_end\njson_encode()", "2", "{minimum => {PHP => 5.2.0}, maximum => {}}" ],
[ "//harmonious @PHP\narray_shift()", "1", "{minimum => {PHP => 4}, maximum => {}}" ], [ "//harmonious @PHP\narray_shift()", "1", "{minimum => {PHP => 4}, maximum => {}}" ],
[ "PATHINFO_BASENAME", "1", "{minimum => {PHP => 4}, maximum => {}}" ] [ "PATHINFO_BASENAME", "1", "{minimum => {PHP => 4}, maximum => {}}" ],
[ "//harmonious @zip:rename\nrename()", "1", "{minimum => {PHP => 4}, maximum => {}}" ]
]; ];
#if neko #if neko
@ -26,8 +27,9 @@ class TestCodeParser extends haxe.unit.TestCase {
for (code in test_code) { for (code in test_code) {
var result = p.parse(code[0]); var result = p.parse(code[0]);
var ignored_modules = p.ignored_modules; var ignored_modules = p.ignored_modules;
var ignored_tokens_in_modules = p.ignored_tokens_in_modules;
assertEquals(Std.parseInt(code[1]), result.length); assertEquals(Std.parseInt(code[1]), result.length);
var code_version_info = new CodeVersionInformation(result, ignored_modules); var code_version_info = new CodeVersionInformation(result, ignored_modules, ignored_tokens_in_modules);
assertEquals(code[2], code_version_info.final_versions.toString()); assertEquals(code[2], code_version_info.final_versions.toString());
} }
} }