Added support for accessors to nested classes, classes and variables
Updated test case respectivelydevelop_before_lexer_parser_merge_parseName
parent
7adf0aad12
commit
8fe1737433
|
@ -15,7 +15,7 @@ import misc.exceptions : TError;
|
||||||
|
|
||||||
public enum AccessorType
|
public enum AccessorType
|
||||||
{
|
{
|
||||||
PUBLIC, PRIVATE, PROTECTED
|
PUBLIC, PRIVATE, PROTECTED, UNKNOWN
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum FunctionType
|
public enum FunctionType
|
||||||
|
@ -239,6 +239,11 @@ public final class Parser
|
||||||
/* Might be a function, might be a variable */
|
/* Might be a function, might be a variable */
|
||||||
parseTypedDeclaration();
|
parseTypedDeclaration();
|
||||||
}
|
}
|
||||||
|
/* If it is an accessor */
|
||||||
|
else if (isAccessor(tok))
|
||||||
|
{
|
||||||
|
parseAccessor();
|
||||||
|
}
|
||||||
/* If it is a branch */
|
/* If it is a branch */
|
||||||
else if (symbol == SymbolType.IF)
|
else if (symbol == SymbolType.IF)
|
||||||
{
|
{
|
||||||
|
@ -286,11 +291,31 @@ public final class Parser
|
||||||
gprintln("parseBody(): Leave", DebugType.WARNING);
|
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 */
|
/* STATUS: Not being used yet */
|
||||||
private void parseAccessor()
|
private void parseAccessor()
|
||||||
{
|
{
|
||||||
/* Save and consume the accessor */
|
/* Save and consume the accessor */
|
||||||
string accessor = getCurrentToken().getToken();
|
AccessorType accessorType = getAccessorType(getCurrentToken());
|
||||||
nextToken();
|
nextToken();
|
||||||
|
|
||||||
/* TODO: Only allow, private, public, protected */
|
/* TODO: Only allow, private, public, protected */
|
||||||
|
@ -299,18 +324,15 @@ public final class Parser
|
||||||
/* Get the current token's symbol type */
|
/* Get the current token's symbol type */
|
||||||
SymbolType symbolType = getSymbolType(getCurrentToken());
|
SymbolType symbolType = getSymbolType(getCurrentToken());
|
||||||
|
|
||||||
/* Before calling any, consume the token (accessor) */
|
|
||||||
nextToken();
|
|
||||||
|
|
||||||
/* If class */
|
/* If class */
|
||||||
if(symbolType == SymbolType.CLASS)
|
if(symbolType == SymbolType.CLASS)
|
||||||
{
|
{
|
||||||
|
parseClass(accessorType);
|
||||||
}
|
}
|
||||||
/* If typed-definition (function or variable) */
|
/* If typed-definition (function or variable) */
|
||||||
else if(symbolType == SymbolType.TYPE)
|
else if(symbolType == SymbolType.TYPE)
|
||||||
{
|
{
|
||||||
/* TODO: Call parseClass with parseClass(View=) */
|
parseTypedDeclaration(accessorType);
|
||||||
}
|
}
|
||||||
/* Error out */
|
/* Error out */
|
||||||
else
|
else
|
||||||
|
@ -497,7 +519,7 @@ public final class Parser
|
||||||
gprintln("parseExpression(): Leave", DebugType.WARNING);
|
gprintln("parseExpression(): Leave", DebugType.WARNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseTypedDeclaration()
|
private void parseTypedDeclaration(AccessorType accessorType = AccessorType.PUBLIC)
|
||||||
{
|
{
|
||||||
gprintln("parseTypedDeclaration(): Enter", DebugType.WARNING);
|
gprintln("parseTypedDeclaration(): Enter", DebugType.WARNING);
|
||||||
|
|
||||||
|
@ -563,7 +585,7 @@ public final class Parser
|
||||||
* This is called when there is an occurrence of
|
* This is called when there is an occurrence of
|
||||||
* a token `class`
|
* a token `class`
|
||||||
*/
|
*/
|
||||||
private void parseClass()
|
private void parseClass(AccessorType accessorType = AccessorType.PUBLIC)
|
||||||
{
|
{
|
||||||
gprintln("parseClass(): Enter", DebugType.WARNING);
|
gprintln("parseClass(): Enter", DebugType.WARNING);
|
||||||
|
|
||||||
|
|
|
@ -193,6 +193,11 @@ public SymbolType getSymbolType(Token tokenIn)
|
||||||
{
|
{
|
||||||
return SymbolType.PUBLIC;
|
return SymbolType.PUBLIC;
|
||||||
}
|
}
|
||||||
|
/* protected keyword */
|
||||||
|
else if(cmp(token, "protected") == 0)
|
||||||
|
{
|
||||||
|
return SymbolType.PROTECTED;
|
||||||
|
}
|
||||||
/* return keyword */
|
/* return keyword */
|
||||||
else if(cmp(token, "return") == 0)
|
else if(cmp(token, "return") == 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,9 +4,12 @@ module bababoioey;
|
||||||
int x;
|
int x;
|
||||||
ubyte y;
|
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");
|
print("Hello world");
|
||||||
}
|
}
|
||||||
|
@ -15,13 +18,13 @@ class clazz_2_1 : bruh
|
||||||
{
|
{
|
||||||
class clazz_2_2
|
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
|
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()
|
void bruh()
|
||||||
|
|
Loading…
Reference in New Issue