Add a parsingError() function to Parser.hpp
This commit is contained in:
parent
a73c7a9608
commit
6d33f05021
|
@ -8,6 +8,13 @@
|
|||
|
||||
namespace Parser {
|
||||
typedef Yerbacon::Exception ParsingException;
|
||||
void error(const tok& token, const string& text, unsigned long line, const bool& quoteTokenText = false) {
|
||||
throw ParsingException(quoteTokenText ? "\"" + token.toktext + "\"" + text : text, line);
|
||||
}
|
||||
inline void parsingError(
|
||||
const tok& token, const string& text,
|
||||
const bool& quoteTokenText = false
|
||||
) { error(token, text, token.line, quoteTokenText); }
|
||||
ParseTree parseVector(const vector<tok>& lexed) {
|
||||
ParseTree parseTree;
|
||||
using namespace StandardComponents;
|
||||
|
@ -32,13 +39,19 @@ namespace Parser {
|
|||
if (current.toktext == "class" || current.toktext == "structure") {
|
||||
if (next.toktype == IDENTIFIER) {
|
||||
parseTree << Class(next.toktext); ++i;
|
||||
} else throw ParsingException((not (next.toktext.empty() or next.toktype == tok::EOF_)) ? '"' + next.toktext + "\" is not a valid class identifier" : "A class identifier is required", next.line);
|
||||
} else {
|
||||
const bool isNotBlank = (not (next.toktext.empty() or next.toktype == tok::EOF_));
|
||||
parsingError(next, isNotBlank ? " is not a valid class identifier"
|
||||
: "A class identifier is required", isNotBlank);
|
||||
}
|
||||
} else {
|
||||
bool isFinalDefine = nextAre({TAG, DEFINE});
|
||||
if (isFinalDefine || next.toktype == DEFINE) {
|
||||
const optional previousDefinition = parseTree.findReferenceByName<Define>(current.toktext);
|
||||
if (previousDefinition.has_value() && previousDefinition.value().get().final) {
|
||||
throw ParsingException(current.toktext + " cannot be redefined as it is final", current.line);
|
||||
if (previousDefinition.has_value()) {
|
||||
if (previousDefinition.value().get().final || isFinalDefine) {
|
||||
parsingError(current, previousDefinition->get().final ? " cannot be redefined as it is final" : " cannot be made final after it has been declared", true);
|
||||
}
|
||||
}
|
||||
parseTree << Define(isFinalDefine, current.toktext);
|
||||
i += 1 + isFinalDefine;
|
||||
|
|
Loading…
Reference in New Issue