Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ jobs:
run: |
choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' -y

- name: Install Node.js dependencies
shell: bash
run: npm ci

- name: Check code style
shell: bash
run: |
Expand Down Expand Up @@ -182,11 +186,15 @@ jobs:

echo "Latest files have been downloaded and extracted to $REPO_DIR."

- name: Build Node
shell: bash
run: npx cmake-js compile --CDNODE=true

- name: Build
shell: bash
run: |
mkdir build
cd build
mkdir build-parser
cd build-parser
cmake ..
cmake --build .

Expand All @@ -200,19 +208,23 @@ jobs:
if: matrix.os != 'windows-latest'
run: |
mkdir -p temp-artifacts
cp build/libsQeeZ-Parser-Lib.a temp-artifacts/
cp build/sQeeZ-Parser-Exe temp-artifacts/
cp build-parser/libsQeeZ-Parser-Lib.a temp-artifacts/
cp build-parser/sQeeZ-Parser-Exe temp-artifacts/
cp build/Release/sQeeZ-Parser-Node.node temp-artifacts/

- name: Move build artifacts to a temporary directory (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
New-Item -Path temp-artifacts -ItemType Directory -Force
if (Test-Path build/Debug/sQeeZ-Parser-Lib.lib) {
Copy-Item build/Debug/sQeeZ-Parser-Lib.lib -Destination temp-artifacts/
if (Test-Path build-parser/Debug/sQeeZ-Parser-Lib.lib) {
Copy-Item build-parser/Debug/sQeeZ-Parser-Lib.lib -Destination temp-artifacts/
}
if (Test-Path build-parser/Debug/sQeeZ-Parser-Exe.exe) {
Copy-Item build-parser/Debug/sQeeZ-Parser-Exe.exe -Destination temp-artifacts/
}
if (Test-Path build/Debug/sQeeZ-Parser-Exe.exe) {
Copy-Item build/Debug/sQeeZ-Parser-Exe.exe -Destination temp-artifacts/
if (Test-Path build/Release/sQeeZ-Parser-Node.node) {
Copy-Item build/Release/sQeeZ-Parser-Node.node -Destination temp-artifacts/
}

- name: Upload build artifacts
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/node_modules
/.vscode
/build
.DS_Store
Expand Down
34 changes: 34 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ message(STATUS "C++ Compiler Version: ${CMAKE_CXX_COMPILER_VERSION}")
# Include the header directory
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

# Include NodeJS
include(./node_modules/node-cmake/NodeJS.cmake)
nodejs_init()

# After init, we will have headers required at the following folder:
# ${CMAKE_CURRENT_BINARY_DIR}/node/${NODEJS_VERSION}/include
include_directories(
${CMAKE_JS_INC}
"${CMAKE_CURRENT_BINARY_DIR}/node/${NODEJS_VERSION}/include"
"${CMAKE_HOME_DIRECTORY}/node_modules/node-addon-api"
)

# Include Google Test
include(FetchContent)
FetchContent_Declare(
Expand All @@ -53,12 +65,14 @@ include(GoogleTest)
file(GLOB_RECURSE SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/parser/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/parser/node/*.cpp
)

# Include the header files
file(GLOB_RECURSE HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/parser/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/parser/node/*.hpp
)

# Include the Lexer
Expand Down Expand Up @@ -108,3 +122,23 @@ target_link_libraries(
sQeeZ-Lexer-Lib
)
gtest_discover_tests(parser_test)

# Create the NodeJS module
if(${NODE})
add_library(
sQeeZ-Parser-Node
SHARED
${SOURCES}
${HEADERS}
)
set_target_properties(
sQeeZ-Parser-Node
PROPERTIES PREFIX "" SUFFIX ".node"
)
target_link_libraries(
sQeeZ-Parser-Node
${CMAKE_JS_LIB}
sQeeZ-Parser-Lib
sQeeZ-Lexer-Lib
)
endif()
10 changes: 10 additions & 0 deletions include/parser/node/node_parser.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef NODE_PARSER_HPP
#define NODE_PARSER_HPP

#include <napi.h>

#include "parser/parser.hpp"

Napi::Array programToJSArray(const Napi::Env& env, const std::unique_ptr<Program>& program);

#endif // NODE_PARSER_HPP
29 changes: 29 additions & 0 deletions include/parser/node/parser_node.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef PARSER_NODE_HPP
#define PARSER_NODE_HPP

#include <napi.h>

#include <iostream>
#include <regex>

#include "parser/parser.hpp"
#include "parser/node/node_parser.hpp"

Napi::String pingParser(const Napi::CallbackInfo &args);
Napi::String info(const Napi::CallbackInfo &args);

class ParserNode : public Napi::ObjectWrap<ParserNode> {
private:
Napi::FunctionReference _require;
Napi::Env _env = Napi::Env(nullptr);

public:
explicit ParserNode(const Napi::CallbackInfo &args);

Napi::String pingInstance(const Napi::CallbackInfo &args);
Napi::Array parse(const Napi::CallbackInfo &args);

static Napi::Function GetClass(Napi::Env);
};

#endif // PARSER_NODE_HPP
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const addon = require('./build/Release/sQeeZ-Parser-Node');
const parser = new addon.ParserNode(require);

console.log(addon.pingParser());
console.log(parser.pingInstance());
console.log(addon.info());
console.log(parser.parse('log("Hello, World!");', false));
1 change: 1 addition & 0 deletions node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cmake-js compile --CDNODE=true
Loading
Loading