Commit b7bd4f83 authored by twanvl's avatar twanvl

nicer error messags when aliases don't but should apply

parent 56043e7e
...@@ -32,9 +32,9 @@ Reader::Reader(const String& filename) ...@@ -32,9 +32,9 @@ Reader::Reader(const String& filename)
} }
void Reader::addAlias(Version end_version, const Char* a, const Char* b) { void Reader::addAlias(Version end_version, const Char* a, const Char* b) {
if (file_app_version < end_version) { Alias& alias = aliasses[a];
aliasses[a] = b; alias.new_key = b;
} alias.end_version = end_version;
} }
void Reader::handleAppVersion() { void Reader::handleAppVersion() {
...@@ -126,13 +126,22 @@ void Reader::readLine() { ...@@ -126,13 +126,22 @@ void Reader::readLine() {
void Reader::unknownKey() { void Reader::unknownKey() {
// aliasses? // aliasses?
map<String,String>::const_iterator it = aliasses.find(key); map<String,Alias>::const_iterator it = aliasses.find(key);
if (it != aliasses.end()) { if (it != aliasses.end()) {
if (aliasses.find(it->second) != aliasses.end()) { if (aliasses.find(it->second.new_key) != aliasses.end()) {
// alias points to another alias, don't follow it, there is the risk of infinite loops // alias points to another alias, don't follow it, there is the risk of infinite loops
} else if (it->second.end_version <= file_version) {
// alias not used for this version, use in warning
if (indent == expected_indent) {
warning(_("Unexpected key: '") + key + _("' try '") + it->second.new_key + _("'"));
do {
moveNext();
} while (indent > expected_indent);
return;
}
} else { } else {
// try this key instead // try this key instead
key = it->second; key = it->second.new_key;
return; return;
} }
} }
......
...@@ -121,7 +121,12 @@ class Reader { ...@@ -121,7 +121,12 @@ class Reader {
/// Did we just open a block (i.e. not read any more lines of it)? /// Did we just open a block (i.e. not read any more lines of it)?
bool just_opened; bool just_opened;
/// Aliasses for compatability /// Aliasses for compatability
map<String, String> aliasses; struct Alias {
String new_key;
Version end_version;
};
/// Aliasses for compatability
map<String, Alias> aliasses;
/// Filename for error messages /// Filename for error messages
String filename; String filename;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment