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
2 changes: 0 additions & 2 deletions .clangd

This file was deleted.

3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "TreeSitterBraneScript"]
path = TreeSitterBraneScript
url = https://github.com/WireWhiz/TreeSitterBraneScript
20 changes: 11 additions & 9 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"type": "gdb",
"request": "launch",
"name": "Cli-Debug",
"preLaunchTask": "cmake-build-debug",
"preLaunchTask": "cmake-install-debug",
"expressions": "native",
"program": "./build/Debug/executables/BraneScriptCli",
"program": "./build/Debug/cli/BraneScriptCli",
"console": "integratedTerminal",
"args": [
"test.bscript"
"exampleScripts/test.bscript"
]
},
{
"type": "lldb",
"type": "gdb",
"request": "launch",
"name": "Cli-Release",
"preLaunchTask": "cmake-build-release",
"preLaunchTask": "cmake-install-release",
"expressions": "native",
"program": "./build/Release/executables/BraneScriptCli",
"console": "integratedTerminal"

"program": "./build/Release/cli/BraneScriptCli",
"console": "integratedTerminal",
"args": [
"exampleScripts/test.bscript"
]
}
]
}
69 changes: 56 additions & 13 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
"version": "2.0.0",
"showOutput": "always",
"tasks": [

{
"taskName": "cmake-configure-debug",
"label": "cmake-configure-debug",
"type": "shell",
"options": {
"cwd": "${workspaceRoot}"
},
"command": "cmake -S. -B./build/Debug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=\"${env:VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake\" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBS_BUILD_TESTS=ON",
"command": "cmake -S. -B./build/Debug -G Ninja -DCMAKE_MAKE_PROGRAM=ninja -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DVCPKG_TARGET_TRIPLET=x64-mingw-static -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=\"${env:VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake\" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBS_BUILD_TESTS=ON",
"presentation": "always"
},
{
Expand All @@ -23,44 +22,88 @@
"options": {
"cwd": "${workspaceRoot}"
},
"command": "cmake --build ./build/Debug --target BraneScriptCli",
"command": "cmake --build ./build/Debug",
"presentation": "always"
},
{
"taskName": "cmake-configure-release",
"label": "cmake-configure-release",
"label": "cmake-configure-release",
"type": "shell",
"options": {
"cwd": "${workspaceRoot}"
},
"command": "cmake -S. -B./build/Release -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=\"${env:VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake\" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBS_BUILD_TESTS=ON",
"command": "cmake -S. -B./build/Release -G Ninja -DCMAKE_MAKE_PROGRAM=ninja -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DVCPKG_TARGET_TRIPLET=x64-mingw-static -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=\"${env:VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake\" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBS_BUILD_TESTS=ON -DTREESITTER_BRANESCRIPT_DIR=../TreeSitterBraneScript",
"presentation": "always"
},
{
"taskName": "cmake-build-release",
"label": "cmake-build-release",
"type": "shell",
"dependsOn":[
"dependsOn": [
"cmake-configure-release"
],
"options": {
"cwd": "${workspaceRoot}"
},
"command": "cmake --build ./build/Release --target BraneScriptCli"
"command": "cmake --build ./build/Release"
},
{
"taskName": "cmake-configure",
"label": "cmake-configure",
"taskName": "build-db-debug",
"label": "build-db-debug",
"type": "shell",
"dependsOn": [
"cmake-configure-debug"
],
"options": {
"cwd": "${workspaceRoot}"
},
"windows": {
"command": "mv ./build/Debug/compile_commands.json ./build/ -Force"
},
"linux": {
"command": "mv ./build/Debug/compile_commands.json ./build/ -f"
}
},
{
"taskName": "build-db-release",
"label": "build-db-release",
"type": "shell",
"dependsOn": [
"cmake-configure-release",
"cmake-configure-debug"
"cmake-configure-release"
],
"options": {
"cwd": "${workspaceRoot}"
},
"windows": {
"command": "mv ./build/Release/compile_commands.json ./build/ -Force"
},
"linux": {
"command": "mv ./build/Release/compile_commands.json ./build/ -f"
}
},
{
"taskName": "cmake-install-debug",
"label": "cmake-install-debug",
"type": "shell",
"dependsOn": [
"cmake-build-debug"
],
"options": {
"cwd": "${workspaceRoot}/build/Debug"
},
"command": "cmake --install . --component cli --prefix ./cli"
},
{
"taskName": "cmake-install-cli-release",
"label": "cmake-install-cli-release",
"type": "shell",
"dependsOn": [
"cmake-build-release"
],
"command": "cmake -S. -B./build/Unix -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=\"${env:VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake\" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -G \"Unix Makefiles\" -DBS_BUILD_TESTS=ON"
"options": {
"cwd": "${workspaceRoot}/build/Release"
},
"command": "cmake --install . --component cli --prefix ./cli"
}
]
}

54 changes: 34 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,40 +1,60 @@
cmake_minimum_required(VERSION 3.23)
include(FetchContent)

project(BraneScript
VERSION "0.2.0"
DESCRIPTION "BraneScript"
HOMEPAGE_URL "https://github.com/wirewhiz/branescript"
LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(BS_BUILD_TESTS "Build tests" ON)
option(TreeSitterBS_DIR "Set a manual path to use for the TreeSitterBraneScript repo")


set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/executables/$<0:>)
# Fetch and run our parser generator
set(TSBS_REPO https://github.com/BraneReality/TreeSitterBraneScript.git)
if(TSBS_DIR)
FetchContent_Declare(
TreeSitterBraneScript
GIT_REPOSITORY ${TSBS_REPO}
GIT_TAG main
SOURCE_DIR ${TSBS_DIR}
)
else()
FetchContent_Declare(
TreeSitterBraneScript
GIT_REPOSITORY ${TSBS_REPO}
GIT_TAG main
)
endif()
FetchContent_MakeAvailable(TreeSitterBraneScript)

set(GRAMMAR_DIR ${treesitterbranescript_SOURCE_DIR})

set(GRAMMAR_DIR ${CMAKE_SOURCE_DIR}/TreeSitterBraneScript)
set(GRAMMAR_FILE ${CMAKE_SOURCE_DIR}/TreeSitterBraneScript/grammar.js)
message("Grammar at ${GRAMMAR_DIR}")
set(GRAMMAR_FILE "${GRAMMAR_DIR}/grammar.js")
set(GRAMMAR_BUILD_DIR ${CMAKE_BINARY_DIR}/ts-branescript)
set(GENERATE_PARSER_CMD tree-sitter generate -b ${GRAMMAR_FILE})
set(PARSER_LIB_NAME parser${CMAKE_SHARED_LIBRARY_SUFFIX})
set(BUILD_PARSER_CMD tree-sitter build -o ${GRAMMAR_BUILD_DIR}/${PARSER_LIB_NAME})

file(MAKE_DIRECTORY ${GRAMMAR_BUILD_DIR})
if(MINGW)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -static -static-libgcc -static-libstdc++")
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g2")
endif()
endif(MINGW)

#[[file(MAKE_DIRECTORY ${GRAMMAR_BUILD_DIR})
message("Watching grammar at ${GRAMMAR_FILE}")
add_custom_command(
OUTPUT ${GRAMMAR_BUILD_DIR}/ts-build-command.stamp
COMMAND echo ${GENERATE_PARSER_CMD}
COMMAND ${GENERATE_PARSER_CMD}
COMMAND echo ${BUILD_PARSER_CMD}
COMMAND ${BUILD_PARSER_CMD}
COMMAND
${CMAKE_COMMAND} -E rm -f
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PARSER_LIB_NAME}
COMMAND
${CMAKE_COMMAND} -E copy
${GRAMMAR_BUILD_DIR}/${PARSER_LIB_NAME}
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PARSER_LIB_NAME}

WORKING_DIRECTORY ${GRAMMAR_BUILD_DIR}
DEPENDS ${GRAMMAR_FILE}
Expand All @@ -44,13 +64,7 @@ add_custom_target(
tree_sitter_bs_parser
DEPENDS
${GRAMMAR_BUILD_DIR}/ts-build-command.stamp
)

add_library(TreeSitterBraneScript INTERFACE)
add_dependencies(TreeSitterBraneScript tree_sitter_bs_parser)

target_link_libraries(TreeSitterBraneScript INTERFACE ${GRAMMAR_BUILD_DIR}/parser${CMAKE_STATIC_LIBRARY_SUFFIX})
target_include_directories(TreeSitterBraneScript INTERFACE ${GRAMMAR_DIR}/bindings/c)
)]]

add_subdirectory(src)

Expand Down
1 change: 0 additions & 1 deletion TreeSitterBraneScript
Submodule TreeSitterBraneScript deleted from f6623a
File renamed without changes.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(ir)
add_subdirectory(cli)
add_subdirectory(parser)
add_subdirectory(compiler)
#add_subdirectory(compiler)
add_subdirectory(types)

21 changes: 20 additions & 1 deletion src/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,26 @@ llvm_map_components_to_libnames(llvm_libs Support Core IRReader ...)
# Link against LLVM libraries
target_link_libraries(main PRIVATE ${llvm_libs})]]


add_executable(BraneScriptCli main.cpp)
target_link_libraries(BraneScriptCli PRIVATE parser)

install(TARGETS BraneScriptCli
RUNTIME_DEPENDENCIES
PRE_EXCLUDE_REGEXES
".*tree-sitter-branescript.*"
"api-ms-.*" "ext-ms-.*" # Windows system DLLs
"^/lib.*" # Linux system libraries
"^/usr/lib.*"
POST_EXCLUDE_REGEXES
".*system32/.*\\.dll" # Windows system directory
"^/lib64/.*" # Linux system directories
"^/usr/lib64/.*"
DESTINATION .
COMPONENT cli)

install(FILES ${treesitterbranescript_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}tree-sitter-branescript${CMAKE_SHARED_LIBRARY_SUFFIX}
DESTINATION .
COMPONENT cli)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/exampleScripts
DESTINATION .
COMPONENT cli)
3 changes: 2 additions & 1 deletion src/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// Created by WireWhiz on 10/22/2024.
//

#include <cstring>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <string>
#include "parser/documentParser.h"
#include "parser/tree_sitter_branescript.h"
#include <string_view>

#include "../parser/tree_sitter_branescript.h"
#include "tree_sitter/api.h"

// #include "TSBindings.h"
Expand Down
8 changes: 4 additions & 4 deletions src/parser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@


find_package(unofficial-tree-sitter CONFIG REQUIRED)
#find_package(TreeSitterBraneScript REQUIRED)

add_library(parser STATIC
documentParser.cpp
documentContext.cpp
documentParser.cpp
documentContext.cpp
)
target_link_libraries(parser PUBLIC unofficial::tree-sitter::tree-sitter TreeSitterBraneScript types)
target_link_libraries(parser PUBLIC unofficial::tree-sitter::tree-sitter tree-sitter-branescript types)
8 changes: 5 additions & 3 deletions src/parser/documentParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
#include <cassert>
#include <charconv>
#include <expected>
#include <format>
#include <functional>
#include <iostream>
#include <list>
#include <memory>
#include <stack>
#include "parser/documentContext.h"
Expand Down Expand Up @@ -354,10 +356,10 @@ namespace BraneScript
}
}

std::string message = std::vformat("Found \"{}\", but was expecting one of the following:\n",
std::make_format_args(nodeText(node)));
std::string message =
std::format("Found \"{}\", but was expecting one of the following:\n", nodeText(node));
for(auto t : types)
message += std::vformat("{}\n", std::make_format_args(typeToName(t)));
message += std::format("{}\n", typeToName(t));
errorMessage(node, message);
return false;
}
Expand Down
Loading
Loading