Skip to content

Commit

Permalink
Fix optional parameter initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
mifka01 committed Nov 15, 2023
1 parent 2ff690f commit 5752cc1
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/compiler/parser/Parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ ParserResult __Parser_parseProgram(Parser *parser) {
ParserResult __Parser_parseBlock(Parser *parser, bool requireBraces) {
assertf(parser != NULL);


// Check for left brace
if(requireBraces) {
LexerResult result = Lexer_nextToken(parser->lexer);
Expand Down Expand Up @@ -221,8 +220,6 @@ ParserResult __Parser_parseTypeReference(Parser *parser) {
}

ParserResult __Parser_parseParameter(Parser *parser) {
// TODO: Add logic to output correct error messages
// TODO: Add expression parsing
assertf(parser != NULL);

bool isLabeless = false;
Expand Down Expand Up @@ -272,20 +269,21 @@ ParserResult __Parser_parseParameter(Parser *parser) {
}

// check for Type

ParserResult typeResult = __Parser_parseTypeReference(parser);
if(!typeResult.success) return typeResult;


// check for initializer
peek = Lexer_peekToken(parser->lexer, 1);
if(!peek.success) return LexerToParserError(peek);

if(peek.token->kind == TOKEN_EQUAL) {
// TODO: Add expression parsing
// : Add constructor for ExpressionASTNode
// : Expression until , or )
initializer = NULL;
// Skip the '=' token
LexerResult tmp = Lexer_nextToken(parser->lexer);
if(!tmp.success) return LexerToParserError(result);

ParserResult initializerResult = __Parser_parseExpression(parser);
if(!initializerResult.success) return initializerResult;
initializer = (ExpressionASTNode*)initializerResult.node;
}

ParameterASTNode *paramNode = new_ParameterASTNode(paramLocalId, (TypeReferenceASTNode*)typeResult.node, initializer, paramExternalId, isLabeless);
Expand Down Expand Up @@ -328,7 +326,7 @@ ParserResult __Parser_parseParameterList(Parser *parser) {

}

// skip ')'
// consume ')'
result = Lexer_nextToken(parser->lexer);
if(!result.success) return LexerToParserError(result);

Expand Down Expand Up @@ -625,7 +623,6 @@ ParserResult __Parser_parseReturnStatement(Parser *parser) {
return ParserSuccess(returnStatement);
}


ParserResult __Parser_parseVariableDeclarator(Parser *parser) {
assertf(parser != NULL);

Expand Down

0 comments on commit 5752cc1

Please sign in to comment.