From 6f64803be6039f3f2222e22a61d7999a8f1ac84e Mon Sep 17 00:00:00 2001 From: Michael Bozhilov Date: Fri, 13 Oct 2023 10:24:59 +0300 Subject: [PATCH] TEST: Pinpoint actions workflow segfault --- .github/workflows/build-repl.yaml | 3 ++- nulascript/ast/ast.cc | 18 ++++++++++++------ nulascript/parser/parser.cc | 3 ++- nulascript/tests/parser_test.cc | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-repl.yaml b/.github/workflows/build-repl.yaml index 210bcbd..d0c7c8b 100644 --- a/.github/workflows/build-repl.yaml +++ b/.github/workflows/build-repl.yaml @@ -2,7 +2,8 @@ name: Build Nulascript REPL on: push: paths: - - 'nulascript/**' + - 'nulascript/lexer/**' + - 'nulascript/token/**' jobs: build: runs-on: ubuntu-latest diff --git a/nulascript/ast/ast.cc b/nulascript/ast/ast.cc index 013c3a2..d66a2a1 100644 --- a/nulascript/ast/ast.cc +++ b/nulascript/ast/ast.cc @@ -1,4 +1,5 @@ #include +#include #include #include @@ -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; } @@ -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(); } @@ -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; } @@ -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; diff --git a/nulascript/parser/parser.cc b/nulascript/parser/parser.cc index 7fb9324..ff55df7 100644 --- a/nulascript/parser/parser.cc +++ b/nulascript/parser/parser.cc @@ -68,7 +68,8 @@ LetStatement* Parser::parseLetStatement() { } ReturnStatement* Parser::parseReturnStatement() { - ReturnStatement* returnStatement = new ReturnStatement(currentToken); + ReturnStatement* returnStatement = + new ReturnStatement(currentToken, nullptr); getNextToken(); diff --git a/nulascript/tests/parser_test.cc b/nulascript/tests/parser_test.cc index bc51757..5c21597 100644 --- a/nulascript/tests/parser_test.cc +++ b/nulascript/tests/parser_test.cc @@ -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);