Fixed parsing of types.

This commit is contained in:
2017-06-16 04:21:19 +02:00
parent 30a092b365
commit 1876d1fe0b
5 changed files with 51 additions and 35 deletions

View File

@@ -23,9 +23,8 @@ ast::Type parseType(Context &context, ast::Domain &domain)
if (tokenizer.testAndReturn<char>('('))
{
// TODO: put into Type parsing unit
// TODO: refactor
auto p =
auto parsePrimitiveTypeWrapper =
[](auto &context, auto &astContext, auto &) -> std::experimental::optional<ast::PrimitiveTypePointer>
{
return parsePrimitiveType(context, *astContext.domain);
@@ -35,7 +34,7 @@ ast::Type parseType(Context &context, ast::Domain &domain)
ASTContext astContext(domain);
VariableStack variableStack;
auto eitherType = parseEither<ast::PrimitiveTypePointer>(context, astContext, variableStack, p);
auto eitherType = parseEither<ast::PrimitiveTypePointer>(context, astContext, variableStack, parsePrimitiveTypeWrapper);
if (!eitherType)
throw ParserException(tokenizer.location(), "expected primitive type or “either” expression");

View File

@@ -49,13 +49,12 @@ ast::VariableDeclarations parseVariableDeclarations(Context &context, ast::Domai
continue;
auto parentType = parseType(context, domain);
parentType = ast::deepCopy(parentType);
for (size_t i = inheritanceIndex; i < variableDeclarations.size(); i++)
variableDeclarations[i]->type = ast::deepCopy(parentType);
// All types up to now are labeled with their parent types
inheritanceIndex = variableDeclarations.size() + 1;
inheritanceIndex = variableDeclarations.size();
tokenizer.skipWhiteSpace();
}