Error/warning reporting improvements.
- Don't suggest matches when given an empty string or a single, non-alpha character. - Also fixed the parser to be a bit less confusing when it encounters an unexpected EOF.
This commit is contained in:
30
parse.yy
30
parse.yy
@@ -928,9 +928,13 @@ parameter_list
|
|||||||
builtinTokens.push_back(*token);
|
builtinTokens.push_back(*token);
|
||||||
++token;
|
++token;
|
||||||
}
|
}
|
||||||
std::vector<std::string> alternates = MatchStrings(yytext, builtinTokens);
|
if (strlen(yytext) == 0)
|
||||||
std::string alts = lGetAlternates(alternates);
|
Error(@1, "Syntax error--premature end of file.");
|
||||||
Error(@1, "Syntax error--token \"%s\" unknown.%s", yytext, alts.c_str());
|
else {
|
||||||
|
std::vector<std::string> alternates = MatchStrings(yytext, builtinTokens);
|
||||||
|
std::string alts = lGetAlternates(alternates);
|
||||||
|
Error(@1, "Syntax error--token \"%s\" unknown.%s", yytext, alts.c_str());
|
||||||
|
}
|
||||||
$$ = NULL;
|
$$ = NULL;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
@@ -1027,9 +1031,13 @@ statement
|
|||||||
builtinTokens.push_back(*token);
|
builtinTokens.push_back(*token);
|
||||||
++token;
|
++token;
|
||||||
}
|
}
|
||||||
std::vector<std::string> alternates = MatchStrings(yytext, builtinTokens);
|
if (strlen(yytext) == 0)
|
||||||
std::string alts = lGetAlternates(alternates);
|
Error(@1, "Syntax error--premature end of file.");
|
||||||
Error(@1, "Syntax error--token \"%s\" unknown.%s", yytext, alts.c_str());
|
else {
|
||||||
|
std::vector<std::string> alternates = MatchStrings(yytext, builtinTokens);
|
||||||
|
std::string alts = lGetAlternates(alternates);
|
||||||
|
Error(@1, "Syntax error--token \"%s\" unknown.%s", yytext, alts.c_str());
|
||||||
|
}
|
||||||
$$ = NULL;
|
$$ = NULL;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
@@ -1177,9 +1185,13 @@ translation_unit
|
|||||||
builtinTokens.push_back(*token);
|
builtinTokens.push_back(*token);
|
||||||
++token;
|
++token;
|
||||||
}
|
}
|
||||||
std::vector<std::string> alternates = MatchStrings(yytext, builtinTokens);
|
if (strlen(yytext) == 0)
|
||||||
std::string alts = lGetAlternates(alternates);
|
Error(@1, "Syntax error--premature end of file.");
|
||||||
Error(@1, "Syntax error--token \"%s\" unknown.%s", yytext, alts.c_str());
|
else {
|
||||||
|
std::vector<std::string> alternates = MatchStrings(yytext, builtinTokens);
|
||||||
|
std::string alts = lGetAlternates(alternates);
|
||||||
|
Error(@1, "Syntax error--token \"%s\" unknown.%s", yytext, alts.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
4
util.cpp
4
util.cpp
@@ -344,6 +344,10 @@ StringEditDistance(const std::string &str1, const std::string &str2, int maxDist
|
|||||||
|
|
||||||
std::vector<std::string>
|
std::vector<std::string>
|
||||||
MatchStrings(const std::string &str, const std::vector<std::string> &options) {
|
MatchStrings(const std::string &str, const std::vector<std::string> &options) {
|
||||||
|
if (str.size() == 0 || (str.size() == 1 && !isalpha(str[0])))
|
||||||
|
// don't even try...
|
||||||
|
return std::vector<std::string>();
|
||||||
|
|
||||||
const int maxDelta = 2;
|
const int maxDelta = 2;
|
||||||
std::vector<std::string> matches[maxDelta+1];
|
std::vector<std::string> matches[maxDelta+1];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user