Added support for accessors to nested classes, classes and variables

Updated test case respectively
develop_before_lexer_parser_merge_parseName
Tristan B. V. Kildaire 2021-03-21 14:03:13 +02:00
parent 7adf0aad12
commit 8fe1737433
3 changed files with 44 additions and 14 deletions

View File

@ -15,7 +15,7 @@ import misc.exceptions : TError;
public enum AccessorType
{
PUBLIC, PRIVATE, PROTECTED
PUBLIC, PRIVATE, PROTECTED, UNKNOWN
}
public enum FunctionType
@ -239,6 +239,11 @@ public final class Parser
/* Might be a function, might be a variable */
parseTypedDeclaration();
}
/* If it is an accessor */
else if (isAccessor(tok))
{
parseAccessor();
}
/* If it is a branch */
else if (symbol == SymbolType.IF)
{
@ -286,11 +291,31 @@ public final class Parser
gprintln("parseBody(): Leave", DebugType.WARNING);
}
private AccessorType getAccessorType(Token token)
{
if(getSymbolType(token) == SymbolType.PUBLIC)
{
return AccessorType.PUBLIC;
}
else if(getSymbolType(token) == SymbolType.PROTECTED)
{
return AccessorType.PROTECTED;
}
else if(getSymbolType(token) == SymbolType.PRIVATE)
{
return AccessorType.PRIVATE;
}
else
{
return AccessorType.UNKNOWN;
}
}
/* STATUS: Not being used yet */
private void parseAccessor()
{
/* Save and consume the accessor */
string accessor = getCurrentToken().getToken();
AccessorType accessorType = getAccessorType(getCurrentToken());
nextToken();
/* TODO: Only allow, private, public, protected */
@ -299,18 +324,15 @@ public final class Parser
/* Get the current token's symbol type */
SymbolType symbolType = getSymbolType(getCurrentToken());
/* Before calling any, consume the token (accessor) */
nextToken();
/* If class */
if(symbolType == SymbolType.CLASS)
{
parseClass(accessorType);
}
/* If typed-definition (function or variable) */
else if(symbolType == SymbolType.TYPE)
{
/* TODO: Call parseClass with parseClass(View=) */
parseTypedDeclaration(accessorType);
}
/* Error out */
else
@ -497,7 +519,7 @@ public final class Parser
gprintln("parseExpression(): Leave", DebugType.WARNING);
}
private void parseTypedDeclaration()
private void parseTypedDeclaration(AccessorType accessorType = AccessorType.PUBLIC)
{
gprintln("parseTypedDeclaration(): Enter", DebugType.WARNING);
@ -563,7 +585,7 @@ public final class Parser
* This is called when there is an occurrence of
* a token `class`
*/
private void parseClass()
private void parseClass(AccessorType accessorType = AccessorType.PUBLIC)
{
gprintln("parseClass(): Enter", DebugType.WARNING);

View File

@ -193,6 +193,11 @@ public SymbolType getSymbolType(Token tokenIn)
{
return SymbolType.PUBLIC;
}
/* protected keyword */
else if(cmp(token, "protected") == 0)
{
return SymbolType.PROTECTED;
}
/* return keyword */
else if(cmp(token, "return") == 0)
{

View File

@ -4,9 +4,12 @@ module bababoioey;
int x;
ubyte y;
ubyte k = 1;
public ubyte k = 1;
private ubyte k = 1;
protected ubyte k = 1;
class clazz1
public class clazz1
{
print("Hello world");
}
@ -15,13 +18,13 @@ class clazz_2_1 : bruh
{
class clazz_2_2
{
class clazz_2_2_1 : bruh, bruh2
private class clazz_2_2_1 : bruh, bruh2
{
}
}
class clazz_2_3
protected class clazz_2_3
{
class clazz_2_3_1
{
@ -89,7 +92,7 @@ class clazz_2_1 : bruh
}
void main(int hello, byte d)
public void main(int hello, byte d)
{
void bruh()