Fixed function argument parsing
parent
4e91bdf6fd
commit
8efeb9a3fb
|
@ -286,47 +286,65 @@ public final class Parser
|
||||||
/* Count for number of parameters processed */
|
/* Count for number of parameters processed */
|
||||||
ulong parameterCount;
|
ulong parameterCount;
|
||||||
|
|
||||||
|
/* Expecting more arguments */
|
||||||
|
bool moreArgs;
|
||||||
|
|
||||||
/* Get command-line arguments */
|
/* Get command-line arguments */
|
||||||
while (hasTokens())
|
while (hasTokens())
|
||||||
{
|
{
|
||||||
/* Expect a type */
|
/* Check if the first thing is a type */
|
||||||
string type = getCurrentToken().getToken();
|
if(getSymbolType(getCurrentToken()) == SymbolType.TYPE)
|
||||||
expect(SymbolType.TYPE, getCurrentToken());
|
|
||||||
nextToken();
|
|
||||||
|
|
||||||
/* Expect an identifier */
|
|
||||||
expect(SymbolType.IDENTIFIER, getCurrentToken());
|
|
||||||
string identifier = getCurrentToken().getToken();
|
|
||||||
nextToken();
|
|
||||||
|
|
||||||
parameterCount++;
|
|
||||||
|
|
||||||
/* Check if RBRACE/ `)` */
|
|
||||||
if (getSymbolType(getCurrentToken()) == SymbolType.RBRACE)
|
|
||||||
{
|
{
|
||||||
nextToken();
|
/* Get the type */
|
||||||
expect(SymbolType.OCURLY, getCurrentToken());
|
string type = getCurrentToken().getToken();
|
||||||
|
|
||||||
/* Parse the body (and it leaves ONLY when it gets the correct symbol, no expect needed) */
|
|
||||||
parseBody();
|
|
||||||
nextToken();
|
nextToken();
|
||||||
|
|
||||||
break;
|
/* Get the identifier */
|
||||||
|
expect(SymbolType.IDENTIFIER, getCurrentToken());
|
||||||
|
string identifier = getCurrentToken().getToken();
|
||||||
|
nextToken();
|
||||||
|
|
||||||
|
moreArgs = false;
|
||||||
|
|
||||||
|
parameterCount++;
|
||||||
}
|
}
|
||||||
else if (getSymbolType(getCurrentToken()) == SymbolType.COMMA)
|
/* If we get a comma */
|
||||||
|
else if(getSymbolType(getCurrentToken()) == SymbolType.COMMA)
|
||||||
{
|
{
|
||||||
|
/* Consume the `,` */
|
||||||
nextToken();
|
nextToken();
|
||||||
|
|
||||||
|
moreArgs = true;
|
||||||
}
|
}
|
||||||
|
/* Check if it is a closing brace */
|
||||||
|
else if(getSymbolType(getCurrentToken()) == SymbolType.RBRACE)
|
||||||
|
{
|
||||||
|
/* Make sure we were not expecting more arguments */
|
||||||
|
if(!moreArgs)
|
||||||
|
{
|
||||||
|
/* Consume the `)` */
|
||||||
|
nextToken();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* Error out if we were and we prematurely ended */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
expect(SymbolType.IDENTIFIER, getCurrentToken());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Error out */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* TODO: Error */
|
expect("Expected either type or )");
|
||||||
expect("Expecting either ) or , but got " ~ getCurrentToken().getToken());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gprintln("ParseFuncDef: ParameterDec: (Type: " ~ type ~ ", Identifier: " ~ identifier ~ ")",
|
|
||||||
DebugType.WARNING);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expect(SymbolType.OCURLY, getCurrentToken());
|
||||||
|
|
||||||
|
/* Parse the body (and it leaves ONLY when it gets the correct symbol, no expect needed) */
|
||||||
|
parseBody();
|
||||||
|
nextToken();
|
||||||
|
|
||||||
gprintln("ParseFuncDef: Parameter count: " ~ to!(string)(parameterCount));
|
gprintln("ParseFuncDef: Parameter count: " ~ to!(string)(parameterCount));
|
||||||
gprintln("parseFuncDef(): Leave", DebugType.WARNING);
|
gprintln("parseFuncDef(): Leave", DebugType.WARNING);
|
||||||
}
|
}
|
||||||
|
@ -543,8 +561,6 @@ public final class Parser
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Go through all classes comma seperated */
|
|
||||||
|
|
||||||
/* Parse a body */
|
/* Parse a body */
|
||||||
parseBody();
|
parseBody();
|
||||||
|
|
|
@ -126,8 +126,16 @@ void main(int hello, byte d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pdsjhfjdsf(int j)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void k(int j, int k)
|
void k(int j, int k)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ubyte thing = "Hello";
|
ubyte thing = "Hello";
|
||||||
print("Hello world");
|
print("Hello world");
|
||||||
print(1+1);
|
print(1+1);
|
||||||
|
|
Loading…
Reference in New Issue