Improved language parsing and validation. This fixes #58
This commit is contained in:
parent
485761f45c
commit
e1e73077a1
@ -297,13 +297,13 @@ namespace hex::lang {
|
||||
nodes.push_back(parseCustomTypePointerVariableDecl(curr, true));
|
||||
else {
|
||||
for(auto &node : nodes) delete node;
|
||||
this->m_error = { curr->lineNumber, "Invalid sequence, expected member declaration" };
|
||||
this->m_error = { curr[-1].lineNumber, "Invalid sequence, expected member declaration" };
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (!tryConsume(curr, {Token::Type::EndOfExpression})) {
|
||||
this->m_error = { curr->lineNumber, "Expected ';' after struct definition" };
|
||||
this->m_error = { curr[-1].lineNumber, "Expected ';' after struct definition" };
|
||||
for(auto &node : nodes) delete node;
|
||||
return nullptr;
|
||||
}
|
||||
@ -344,7 +344,7 @@ namespace hex::lang {
|
||||
nodes.push_back(parseCustomTypePointerVariableDecl(curr, true));
|
||||
else {
|
||||
for(auto &node : nodes) delete node;
|
||||
this->m_error = { curr->lineNumber, "Invalid sequence, expected member declaration" };
|
||||
this->m_error = { curr[-1].lineNumber, "Invalid sequence, expected member declaration" };
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@ -428,7 +428,7 @@ namespace hex::lang {
|
||||
fields.emplace_back(curr[-4].identifierToken.identifier, curr[-2].integerToken.integer);
|
||||
}
|
||||
else {
|
||||
this->m_error = { curr->lineNumber, "Invalid sequence, expected member declaration" };
|
||||
this->m_error = { curr[-1].lineNumber, "Invalid sequence, expected member declaration" };
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@ -591,6 +591,12 @@ namespace hex::lang {
|
||||
return { };
|
||||
}
|
||||
|
||||
if (curr[-6].keywordToken.keyword != Token::KeywordToken::Keyword::LittleEndian && curr[-6].keywordToken.keyword != Token::KeywordToken::Keyword::BigEndian) {
|
||||
this->m_error = { curr[-3].lineNumber, "Expected endianess identifier" };
|
||||
for(auto &node : program) delete node;
|
||||
return { };
|
||||
}
|
||||
|
||||
auto variableDecl = parseFreeBuiltinVariableDecl(curr, true);
|
||||
|
||||
program.push_back(variableDecl);
|
||||
@ -605,6 +611,12 @@ namespace hex::lang {
|
||||
return { };
|
||||
}
|
||||
|
||||
if (curr[-6].keywordToken.keyword != Token::KeywordToken::Keyword::LittleEndian && curr[-6].keywordToken.keyword != Token::KeywordToken::Keyword::BigEndian) {
|
||||
this->m_error = { curr[-6].lineNumber, "Expected endianess identifier" };
|
||||
for(auto &node : program) delete node;
|
||||
return { };
|
||||
}
|
||||
|
||||
auto variableDecl = parseFreeCustomTypeVariableDecl(curr, true);
|
||||
|
||||
program.push_back(variableDecl);
|
||||
@ -624,8 +636,10 @@ namespace hex::lang {
|
||||
while (curr->type != endTokenType) {
|
||||
auto newTokens = parseStatement(curr);
|
||||
|
||||
if (!newTokens.has_value())
|
||||
break;
|
||||
if (!newTokens.has_value()) {
|
||||
for (auto &node : program) delete node;
|
||||
return { };
|
||||
}
|
||||
|
||||
program.insert(program.end(), newTokens->begin(), newTokens->end());
|
||||
}
|
||||
|
@ -16,6 +16,11 @@ namespace hex::lang {
|
||||
std::unordered_set<std::string> typeNames;
|
||||
|
||||
for (const auto &node : ast) {
|
||||
if (node == nullptr) {
|
||||
this->m_error = { 1, "Empty AST" };
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (node->getType()) {
|
||||
case ASTNode::Type::VariableDecl:
|
||||
{
|
||||
|
@ -296,6 +296,7 @@ namespace hex {
|
||||
auto [parseResult, ast] = parser.parse(tokens);
|
||||
if (parseResult.failed()) {
|
||||
this->m_textEditor.SetErrorMarkers({ parser.getError() });
|
||||
printf("%d %s\n", parser.getError().first, parser.getError().second.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user