From b8d5dd56730f7f8465e418a39a1c31d1fa67daac Mon Sep 17 00:00:00 2001 From: Ruben Dahl Date: Fri, 13 Jan 2023 20:21:15 +0100 Subject: [PATCH] Started work on the CeeV language. --- .gitignore | 78 +++++++++++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 52 ++++++++++++++++++++++++++++++ README.md | 3 ++ ceevConfig.cmake.in | 6 ++++ ex/CMakeLists.txt | 14 ++++++++ ex/src/test.cc | 6 ++++ ex/src/test.h | 4 +++ examples/test.cv | 4 +++ src/colors.cc | 37 +++++++++++++++++++++ src/colors.h | 39 +++++++++++++++++++++++ src/lang.cc | 21 ++++++++++++ src/lang.h | 14 ++++++++ 12 files changed, 278 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 README.md create mode 100644 ceevConfig.cmake.in create mode 100644 ex/CMakeLists.txt create mode 100644 ex/src/test.cc create mode 100644 ex/src/test.h create mode 100644 examples/test.cv create mode 100644 src/colors.cc create mode 100644 src/colors.h create mode 100644 src/lang.cc create mode 100644 src/lang.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae9b79b --- /dev/null +++ b/.gitignore @@ -0,0 +1,78 @@ +# Created by https://www.toptal.com/developers/gitignore/api/cmake,c++,visualstudiocode +# Edit at https://www.toptal.com/developers/gitignore?templates=cmake,c++,visualstudiocode + +### C++ ### +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +### CMake ### +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +### CMake Patch ### +# External projects +*-prefix/ + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +# End of https://www.toptal.com/developers/gitignore/api/cmake,c++,visualstudiocode + +build/ +.ccls +.ccls-cache/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..33ee728 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,52 @@ +cmake_minimum_required(VERSION 3.7) + +project(ceev VERSION 0.1.0 DESCRIPTION "The language of the CeeV project") + +execute_process( + COMMAND git rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE) + +execute_process( + COMMAND git log -1 --pretty=%B + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_MSG + OUTPUT_STRIP_TRAILING_WHITESPACE) + +set(CMAKE_CXX_STANDARD 17) + +add_library(${PROJECT_NAME} SHARED src/lang.cc src/lang.h src/colors.cc + src/colors.h) +set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER + "src/lang.h;src/colors.h") + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/ceevConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/ceevConfig.cmake + @ONLY +) + +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/ceevConfig.cmake + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/ceev +) + +install(TARGETS ${PROJECT_NAME} + LIBRARY DESTINATION /usr/local/lib/ + PUBLIC_HEADER DESTINATION /usr/local/include/ceev +) + +# install(TARGETS ${PROJECT_NAME} +# LIBRARY DESTINATION /usr/lib +# PUBLIC_HEADER DESTINATION /usr/include/ceev) + +# install(TARGETS ${PROJECT_NAME} LIBRARY) + +target_compile_definitions(${PROJECT_NAME} PRIVATE + "-DGIT_COMMIT_HASH=\"${GIT_COMMIT_HASH}\"") + +string(REPLACE "\n" "\\n" GIT_COMMIT_MSG "${GIT_COMMIT_MSG}") + +target_compile_definitions(${PROJECT_NAME} PRIVATE + "-DGIT_COMMIT_MSG=\"${GIT_COMMIT_MSG}\"") diff --git a/README.md b/README.md new file mode 100644 index 0000000..a079265 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Ceev Lang +This is a supplementary to the CeeV project. +More to come. diff --git a/ceevConfig.cmake.in b/ceevConfig.cmake.in new file mode 100644 index 0000000..d6c8575 --- /dev/null +++ b/ceevConfig.cmake.in @@ -0,0 +1,6 @@ +@PACKAGE_INIT@ + +set(ceev_INCLUDE_DIRS "@CMAKE_INSTALL_PREFIX@/include/ceev") +set(ceev_LIBRARIES "@CMAKE_INSTALL_PREFIX@/lib/libceev.so") + +# find_package(ceev) diff --git a/ex/CMakeLists.txt b/ex/CMakeLists.txt new file mode 100644 index 0000000..aee53e8 --- /dev/null +++ b/ex/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.7) + +project(ceevlang-test) + +set(CMAKE_CXX_STANDARD 17) + +find_library(CEEV NAMES ceev HINTS "/usr/local/include" REQUIRED) +include_directories(${CEEV_INCLUDE_DIRS}) + +add_executable(${PROJECT_NAME} src/test.cc src/test.h) + +target_link_libraries(${PROJECT_NAME} ${CEEV_LIBRARIES}) + +install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin) diff --git a/ex/src/test.cc b/ex/src/test.cc new file mode 100644 index 0000000..c4dea31 --- /dev/null +++ b/ex/src/test.cc @@ -0,0 +1,6 @@ +#include "test.h" + +int main() { + std::cout << bg_bright_green(red("Hello World")) << std::endl; + return 0; +} diff --git a/ex/src/test.h b/ex/src/test.h new file mode 100644 index 0000000..95e0af4 --- /dev/null +++ b/ex/src/test.h @@ -0,0 +1,4 @@ +#pragma once + +#include +#include diff --git a/examples/test.cv b/examples/test.cv new file mode 100644 index 0000000..d83dd12 --- /dev/null +++ b/examples/test.cv @@ -0,0 +1,4 @@ +let test = Character("Test") +test "Hello World" + +unlet test diff --git a/src/colors.cc b/src/colors.cc new file mode 100644 index 0000000..14616db --- /dev/null +++ b/src/colors.cc @@ -0,0 +1,37 @@ +#include "colors.h" + +std::string black(std::string input) {return "\x1b[30m" + input + "\x1b[0m";} +std::string red(std::string input) {return "\x1b[31m" + input + "\x1b[0m";} +std::string green(std::string input) {return "\x1b[32m" + input + "\x1b[0m";} +std::string yellow(std::string input) {return "\x1b[33m" + input + "\x1b[0m";} +std::string blue(std::string input) {return "\x1b[34m" + input + "\x1b[0m";} +std::string magenta(std::string input) {return "\x1b[35m" + input + "\x1b[0m";} +std::string cyan(std::string input) {return "\x1b[36m" + input + "\x1b[0m";} +std::string white(std::string input) {return "\x1b[37m" + input + "\x1b[0m";} +std::string bright_black(std::string input) {return "\x1b[90m" + input + "\x1b[0m";} +std::string bright_red(std::string input) {return "\x1b[91m" + input + "\x1b[0m";} +std::string bright_green(std::string input) {return "\x1b[92m" + input + "\x1b[0m";} +std::string bright_yellow(std::string input) {return "\x1b[93m" + input + "\x1b[0m";} +std::string bright_blue(std::string input) {return "\x1b[94m" + input + "\x1b[0m";} +std::string bright_magenta(std::string input) {return "\x1b[95m" + input + "\x1b[0m";} +std::string bright_cyan(std::string input) {return "\x1b[96m" + input + "\x1b[0m";} +std::string bright_white(std::string input) {return "\x1b[97m" + input + "\x1b[0m";} +std::string bg_black(std::string input) {return "\x1b[40m" + input + "\x1b[0m";} +std::string bg_red(std::string input) {return "\x1b[41m" + input + "\x1b[0m";} +std::string bg_green(std::string input) {return "\x1b[42m" + input + "\x1b[0m";} +std::string bg_yellow(std::string input) {return "\x1b[43m" + input + "\x1b[0m";} +std::string bg_blue(std::string input) {return "\x1b[44m" + input + "\x1b[0m";} +std::string bg_magenta(std::string input) {return "\x1b[45m" + input + "\x1b[0m";} +std::string bg_cyan(std::string input) {return "\x1b[46m" + input + "\x1b[0m";} +std::string bg_white(std::string input) {return "\x1b[47m" + input + "\x1b[0m";} +std::string bg_bright_black(std::string input) {return "\x1b[100m" + input + "\x1b[0m";} +std::string bg_bright_red(std::string input) {return "\x1b[101m" + input + "\x1b[0m";} +std::string bg_bright_green(std::string input) {return "\x1b[102m" + input + "\x1b[0m";} +std::string bg_bright_yellow(std::string input) {return "\x1b[103m" + input + "\x1b[0m";} +std::string bg_bright_blue(std::string input) {return "\x1b[104m" + input + "\x1b[0m";} +std::string bg_bright_magenta(std::string input) {return "\x1b[105m" + input + "\x1b[0m";} +std::string bg_bright_cyan(std::string input) {return "\x1b[106m" + input + "\x1b[0m";} +std::string bg_bright_white(std::string input) {return "\x1b[107m" + input + "\x1b[0m";} +std::string bold(std::string input) {return "\x1b[1m" + input + "\x1b[0m";} +std::string underline(std::string input) {return "\x1b[4m" + input + "\x1b[0m";} +std::string reverse(std::string input) {return "\x1b[7m" + input + "\x1b[0m";} \ No newline at end of file diff --git a/src/colors.h b/src/colors.h new file mode 100644 index 0000000..d177240 --- /dev/null +++ b/src/colors.h @@ -0,0 +1,39 @@ +#pragma once + +#include + +std::string black(std::string input); +std::string red(std::string input); +std::string green(std::string input); +std::string yellow(std::string input); +std::string blue(std::string input); +std::string magenta(std::string input); +std::string cyan(std::string input); +std::string white(std::string input); +std::string bright_black(std::string input); +std::string bright_red(std::string input); +std::string bright_green(std::string input); +std::string bright_yellow(std::string input); +std::string bright_blue(std::string input); +std::string bright_magenta(std::string input); +std::string bright_cyan(std::string input); +std::string bright_white(std::string input); +std::string bg_black(std::string input); +std::string bg_red(std::string input); +std::string bg_green(std::string input); +std::string bg_yellow(std::string input); +std::string bg_blue(std::string input); +std::string bg_magenta(std::string input); +std::string bg_cyan(std::string input); +std::string bg_white(std::string input); +std::string bg_bright_black(std::string input); +std::string bg_bright_red(std::string input); +std::string bg_bright_green(std::string input); +std::string bg_bright_yellow(std::string input); +std::string bg_bright_blue(std::string input); +std::string bg_bright_magenta(std::string input); +std::string bg_bright_cyan(std::string input); +std::string bg_bright_white(std::string input); +std::string bold(std::string input); +std::string underline(std::string input); +std::string reverse(std::string input); \ No newline at end of file diff --git a/src/lang.cc b/src/lang.cc new file mode 100644 index 0000000..c7d64e5 --- /dev/null +++ b/src/lang.cc @@ -0,0 +1,21 @@ +#include "lang.h" + +int read_file(std::deque args) { + if (args.empty()) { + std::cout << bg_red(bold("ERROR")) << ": No file input" << std::endl; + return 1; + } + fs::path filename = args[0]; + args.pop_front(); + std::ifstream file(filename); + if (!file) { + std::cout << bg_red(bold("ERROR")) << ": Could not find file" << std::endl; + return 1; + } + std::string line; + while (std::getline(file, line)) { + std::istringstream stream(line); + } + return 0; +} + diff --git a/src/lang.h b/src/lang.h new file mode 100644 index 0000000..6548e7b --- /dev/null +++ b/src/lang.h @@ -0,0 +1,14 @@ +#pragma once + +#include "colors.h" +#include +#include +#include +#include +#include +#include +#include + +namespace fs = std::filesystem; + +int read_file(std::deque args);