Added support for class inheritance parsing

develop_before_lexer_parser_merge_parseName
Tristan B. V. Kildaire 2021-03-21 09:45:40 +02:00
parent ceffcd7b9c
commit 9f6dd813c8
2 changed files with 38 additions and 4 deletions

View File

@ -507,10 +507,44 @@ public final class Parser
expect(SymbolType.IDENTIFIER, getCurrentToken()); expect(SymbolType.IDENTIFIER, getCurrentToken());
string className = getCurrentToken().getToken(); string className = getCurrentToken().getToken();
gprintln("parseClass(): Class name found '" ~ className ~ "'"); gprintln("parseClass(): Class name found '" ~ className ~ "'");
/* Expect a `{` */
nextToken(); nextToken();
expect(SymbolType.OCURLY, getCurrentToken());
/* TODO: If we have the inherit symbol `:` */
if(getSymbolType(getCurrentToken()) == SymbolType.INHERIT_OPP)
{
/* TODO: Loop until `}` */
/* Consume the inheritance operator `:` */
nextToken();
while(true)
{
/* Check if it is an identifier */
expect(SymbolType.IDENTIFIER, getCurrentToken());
nextToken();
/* Check if we have ended with a `{` */
if(getSymbolType(getCurrentToken()) == SymbolType.OCURLY)
{
/* Exit */
break;
}
/* If we get a comma */
else if(getSymbolType(getCurrentToken()) == SymbolType.COMMA)
{
/* Consume */
nextToken();
}
/* Error out if we get anything else */
else
{
expect("Expected either { or ,");
}
}
}
/* TODO: Go through all classes comma seperated */
/* Parse a body */ /* Parse a body */
parseBody(); parseBody();

View File

@ -8,7 +8,7 @@ class clazz1
print("Hello world"); print("Hello world");
} }
class clazz_2_1 class clazz_2_1 : bruh
{ {
class clazz_2_2 class clazz_2_2
{ {