Skip to content

Commit

Permalink
TEST: Pinpoint actions workflow segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
asynchroza committed Oct 13, 2023
1 parent b32b8ca commit 6f64803
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build-repl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Build Nulascript REPL
on:
push:
paths:
- 'nulascript/**'
- 'nulascript/lexer/**'
- 'nulascript/token/**'
jobs:
build:
runs-on: ubuntu-latest
Expand Down
18 changes: 12 additions & 6 deletions nulascript/ast/ast.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <ast.h>
#include <iostream>
#include <string>
#include <token.h>

Expand All @@ -21,7 +22,8 @@ std::string Program::toString() {
}

// LetStatement
LetStatement::LetStatement(Token token) : token(token) {}
LetStatement::LetStatement(Token token)
: token(token), name(nullptr), value(nullptr) {}

std::string LetStatement::tokenLiteral() { return token.literal; }

Expand All @@ -30,6 +32,7 @@ std::string LetStatement::toString() {
representation += tokenLiteral() + " " + name->toString() + " = ";

if (value) {
std::cout << "[DEBUG] LetStatement Value is not NULL PTR" << std::endl;
representation += value->toString();
}

Expand All @@ -38,7 +41,7 @@ std::string LetStatement::toString() {
}

// Identifier
Identifier::Identifier(Token token) : token(token) {}
Identifier::Identifier(Token token) : token(token), value(token.literal) {}

std::string Identifier::tokenLiteral() { return token.literal; }

Expand All @@ -55,11 +58,14 @@ std::string ReturnStatement::tokenLiteral() { return token.literal; }
std::string ReturnStatement::toString() {
std::string representation = "";

representation += tokenLiteral() + " ";
// representation += tokenLiteral() + " ";

if (returnValue) {
representation += returnValue->toString();
}
// std::cout << "ReturnStatement toString " << returnValue << std::endl;
// return representation;

// if (returnValue) {
// representation += returnValue->toString();
// }

representation += ";";
return representation;
Expand Down
3 changes: 2 additions & 1 deletion nulascript/parser/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ LetStatement* Parser::parseLetStatement() {
}

ReturnStatement* Parser::parseReturnStatement() {
ReturnStatement* returnStatement = new ReturnStatement(currentToken);
ReturnStatement* returnStatement =
new ReturnStatement(currentToken, nullptr);

getNextToken();

Expand Down
2 changes: 1 addition & 1 deletion nulascript/tests/parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ TEST(ParserSuite, TestAstToString) {
return a;
);

std::string expectedResult = "let = ;\nreturn ;\n";
std::string expectedResult = "let a = ;\nreturn ;\n";
// clang-format on

Lexer l(input);
Expand Down

0 comments on commit 6f64803

Please sign in to comment.