Skip to content
Open
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
16 changes: 9 additions & 7 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
bitwise/documentation
console/documentation
hash/documentation
http/documentation
http/bulk_req.py
json/documentation
random/documentation
src/bitwise/documentation
src/console/documentation
src/hash/documentation
src/http/documentation
src/http/bulk_req.py

draft/database/documentation
draft/json/documentation
draft/re/documentation
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
build/
cmake-build-*/
__pycache__/
__arkscript__/
cformat.ps1

.idea/

cmake-build-*/
build/
*.o
*.out
*.dll
Expand All @@ -15,4 +13,3 @@ build/
*.so

draft/playground

6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@
[submodule "submodules/termcolor"]
path = submodules/termcolor
url = https://github.com/ikalnytskyi/termcolor
[submodule "submodules/abseil"]
path = submodules/abseil
url = https://github.com/abseil/abseil-cpp.git
[submodule "submodules/re2"]
path = submodules/re2
url = https://github.com/google/re2.git
14 changes: 3 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@ cmake_minimum_required(VERSION 3.16)

project(Modules)

set(ARK_MOD_ALL Off CACHE BOOL "Build all the modules")
set(ARK_MOD_DRAFT Off CACHE BOOL "Build all draft modules")
set(ARK_REQUESTED_MODULES "" CACHE STRING "List of module names to build")

if (ARK_MOD_ALL)
message(STATUS "Building modules in modules/src")
add_subdirectory(src)
endif ()

if (ARK_MOD_DRAFT)
message(STATUS "Building modules in modules/draft")
add_subdirectory(draft)
endif ()
add_subdirectory(src)
add_subdirectory(draft)
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ Main repository: **[ArkScript](https://github.com/ArkScript-lang/Ark)**

### Terminal related

* `console` to change text color when using `print`
* `console` to change text colour when using `print`

### Generic utilities

* `bitwise` for bitwise operations
* `bitwise` for bitwise operations (**deprecated**: now built-in)
* `hash` to compute md5 and sha256 hashes
* `re` to use regex

### Data related

Expand Down
11 changes: 9 additions & 2 deletions draft/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
add_subdirectory(database)
add_subdirectory(json)
if (${ARK_REQUESTED_MODULES} MATCHES "(^\\*$|database,)")
add_subdirectory(database)
endif ()
if (${ARK_REQUESTED_MODULES} MATCHES "(^\\*$|json,)")
add_subdirectory(json)
endif ()
if (${ARK_REQUESTED_MODULES} MATCHES "(^\\*$|re,)")
add_subdirectory(re)
endif ()
2 changes: 1 addition & 1 deletion draft/database/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"$<TARGET_FILE:${PROJECT_NAME}>" ${ark_SOURCE_DIR}/lib/${PROJECT_NAME}.arkm)
"$<TARGET_FILE:${PROJECT_NAME}>" ${ark_SOURCE_DIR}/lib/std/${PROJECT_NAME}.arkm)
2 changes: 1 addition & 1 deletion draft/json/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"$<TARGET_FILE:${PROJECT_NAME}>" ${PROJECT_SOURCE_DIR}/../../../${PROJECT_NAME}.arkm)
"$<TARGET_FILE:${PROJECT_NAME}>" ${ark_SOURCE_DIR}/lib/std/${PROJECT_NAME}.arkm)
27 changes: 27 additions & 0 deletions draft/re/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 3.16)

project(re)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

set(ABSL_ENABLE_INSTALL ON)
set(ABSL_PROPAGATE_CXX_STD ON)
add_subdirectory(${Modules_SOURCE_DIR}/submodules/abseil abseil EXCLUDE_FROM_ALL SYSTEM)
add_subdirectory(${Modules_SOURCE_DIR}/submodules/re2 re2 EXCLUDE_FROM_ALL SYSTEM)

include_directories(${PROJECT_SOURCE_DIR}/include)
file(GLOB_RECURSE SOURCE_FILES
${PROJECT_SOURCE_DIR}/src/*.cpp
${ark_SOURCE_DIR}/thirdparties/fmt/src/format.cc)

add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})

target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${ark_SOURCE_DIR}/include)
target_link_libraries(${PROJECT_NAME} PRIVATE ArkReactor re2::re2)

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)

add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"$<TARGET_FILE:${PROJECT_NAME}>" ${ark_SOURCE_DIR}/lib/std/${PROJECT_NAME}.arkm)
Empty file added draft/re/README.md
Empty file.
696 changes: 696 additions & 0 deletions draft/re/documentation/README.md

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions draft/re/include/module.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef RE_REGEX_HPP
#define RE_REGEX_HPP

#include <Ark/Module.hpp>

namespace Regex
{
using namespace Ark;

Value search(std::vector<Value>& args, VM* vm);
Value match(std::vector<Value>& args, VM* vm);
Value full_match(std::vector<Value>& args, VM* vm);
Value find_all(std::vector<Value>& args, VM* vm);
Value sub(std::vector<Value>& args, VM* vm);
Value split(std::vector<Value>& args, VM* vm);
Value escape(std::vector<Value>& args, VM* vm);
}

#endif // RE_REGEX_HPP
63 changes: 63 additions & 0 deletions draft/re/include/utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#ifndef RE_UTILS_HPP
#define RE_UTILS_HPP

#include <vector>
#include <string>

#include <re2/re2.h>
#include <absl/strings/string_view.h>

namespace Regex
{
struct Span
{
long start;
std::size_t size;
bool empty;
};

struct Match
{
std::vector<Span> spans;

[[nodiscard]] inline long start() const
{
return spans.front().start;
}

[[nodiscard]] inline std::size_t end() const
{
return spans.front().start + spans.front().size;
}

[[nodiscard]] inline std::size_t size() const
{
return spans.front().size;
}
};

struct MatchImpl_t
{
std::string text;
std::vector<Match> matches;
bool empty;
bool expect_many;
};

inline Span asSpan(const absl::string_view& sv, const std::string& text)
{
return Span { .start = static_cast<long>(sv.data() - text.data()), .size = sv.size(), .empty = false };
}

inline Span getFirstSpan(const std::vector<absl::string_view>& groups, const std::string& text)
{
if (const auto& it = groups.front(); it.data() == nullptr)
return Span { .start = 0, .size = 0, .empty = true };
else
return asSpan(it, text);
}

MatchImpl_t matchImpl(RE2::Anchor anchor, const std::string& regex, const std::string& text, bool stop_at_first);
}

#endif // RE_UTILS_HPP
Loading
Loading