mirror of
https://github.com/hyprwm/hyprlang.git
synced 2024-12-22 09:59:48 +01:00
Merge branch 'main' into feat/add-multi-line-support
This commit is contained in:
commit
20ffb9d4f2
8 changed files with 106 additions and 20 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -12,4 +12,5 @@ _deps
|
||||||
.vscode
|
.vscode
|
||||||
build/
|
build/
|
||||||
doxygen/
|
doxygen/
|
||||||
doxygen-awesome-css/
|
doxygen-awesome-css/
|
||||||
|
.cache/
|
|
@ -47,15 +47,6 @@ set_target_properties(
|
||||||
|
|
||||||
target_link_libraries(hyprlang PkgConfig::deps)
|
target_link_libraries(hyprlang PkgConfig::deps)
|
||||||
|
|
||||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
||||||
# for std::expected. probably evil. Arch's clang is very outdated tho...
|
|
||||||
target_compile_options(hyprlang PUBLIC -std=gnu++2b -D__cpp_concepts=202002L
|
|
||||||
-Wno-macro-redefined)
|
|
||||||
add_compile_options(-stdlib=libc++)
|
|
||||||
add_link_options(-stdlib=libc++)
|
|
||||||
message(STATUS "Using clang++ to compile hyprlang")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_library(hypr::hyprlang ALIAS hyprlang)
|
add_library(hypr::hyprlang ALIAS hyprlang)
|
||||||
install(TARGETS hyprlang)
|
install(TARGETS hyprlang)
|
||||||
|
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
0.5.3
|
0.6.0
|
||||||
|
|
12
flake.lock
12
flake.lock
|
@ -10,11 +10,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1721324102,
|
"lastModified": 1733502241,
|
||||||
"narHash": "sha256-WAZ0X6yJW1hFG6otkHBfyJDKRpNP5stsRqdEuHrFRpk=",
|
"narHash": "sha256-KAUNC4Dgq8WQjYov5auBw/usaHixhacvb7cRDd0AG/k=",
|
||||||
"owner": "hyprwm",
|
"owner": "hyprwm",
|
||||||
"repo": "hyprutils",
|
"repo": "hyprutils",
|
||||||
"rev": "962582a090bc233c4de9d9897f46794280288989",
|
"rev": "104117aed6dd68561be38b50f218190aa47f2cd8",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -25,11 +25,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1721138476,
|
"lastModified": 1734119587,
|
||||||
"narHash": "sha256-+W5eZOhhemLQxelojLxETfbFbc19NWawsXBlapYpqIA=",
|
"narHash": "sha256-AKU6qqskl0yf2+JdRdD0cfxX4b9x3KKV5RqA6wijmPM=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "ad0b5eed1b6031efaed382844806550c3dcb4206",
|
"rev": "3566ab7246670a43abd2ffa913cc62dad9cdf7d5",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
inputs.hyprutils.overlays.default
|
inputs.hyprutils.overlays.default
|
||||||
(final: prev: {
|
(final: prev: {
|
||||||
hyprlang = final.callPackage ./nix/default.nix {
|
hyprlang = final.callPackage ./nix/default.nix {
|
||||||
stdenv = final.gcc13Stdenv;
|
stdenv = final.gcc14Stdenv;
|
||||||
version = version + "+date=" + (mkDate (self.lastModifiedDate or "19700101")) + "_" + (self.shortRev or "dirty");
|
version = version + "+date=" + (mkDate (self.lastModifiedDate or "19700101")) + "_" + (self.shortRev or "dirty");
|
||||||
};
|
};
|
||||||
hyprlang-with-tests = final.hyprlang.override {doCheck = true;};
|
hyprlang-with-tests = final.hyprlang.override {doCheck = true;};
|
||||||
|
|
|
@ -3,11 +3,13 @@
|
||||||
#ifndef HYPRLANG_HPP
|
#ifndef HYPRLANG_HPP
|
||||||
#define HYPRLANG_HPP
|
#define HYPRLANG_HPP
|
||||||
|
|
||||||
|
#include <typeindex>
|
||||||
#include <any>
|
#include <any>
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <ostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <print>
|
||||||
|
#include <cstdlib>
|
||||||
#include <expected>
|
#include <expected>
|
||||||
|
|
||||||
class CConfigImpl;
|
class CConfigImpl;
|
||||||
|
@ -459,6 +461,87 @@ namespace Hyprlang {
|
||||||
void retrieveKeysForCat(const char* category, const char*** out, size_t* len);
|
void retrieveKeysForCat(const char* category, const char*** out, size_t* len);
|
||||||
CParseResult parseRawStream(const std::string& stream);
|
CParseResult parseRawStream(const std::string& stream);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Templated wrapper for Hyprlang values. Much more straightforward to use.
|
||||||
|
|
||||||
|
\since 0.6.0
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
class CSimpleConfigValue {
|
||||||
|
public:
|
||||||
|
CSimpleConfigValue(CConfig* const pConfig, const char* val) {
|
||||||
|
const auto VAL = pConfig->getConfigValuePtr(val);
|
||||||
|
|
||||||
|
if (!VAL) {
|
||||||
|
std::println("CSimpleConfigValue: value not found");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOLINTNEXTLINE
|
||||||
|
p_ = VAL->getDataStaticPtr();
|
||||||
|
|
||||||
|
#ifdef HYPRLAND_DEBUG
|
||||||
|
// verify type
|
||||||
|
const auto ANY = VAL->getValue();
|
||||||
|
const auto TYPE = std::type_index(ANY.type());
|
||||||
|
|
||||||
|
// exceptions
|
||||||
|
const bool STRINGEX = (typeid(T) == typeid(std::string) && TYPE == typeid(Hyprlang::STRING));
|
||||||
|
const bool CUSTOMEX = (typeid(T) == typeid(Hyprlang::CUSTOMTYPE) && (TYPE == typeid(Hyprlang::CUSTOMTYPE*) || TYPE == typeid(void*) /* dunno why it does this? */));
|
||||||
|
|
||||||
|
if (typeid(T) != TYPE && !STRINGEX && !CUSTOMEX) {
|
||||||
|
std::println("CSimpleConfigValue: Mismatched type in CConfigValue<T>, got {} but has {}", typeid(T).name(), TYPE.name());
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
T* ptr() const {
|
||||||
|
return *(T* const*)p_;
|
||||||
|
}
|
||||||
|
|
||||||
|
T operator*() const {
|
||||||
|
return *ptr();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void* const* p_ = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline std::string* CSimpleConfigValue<std::string>::ptr() const {
|
||||||
|
std::print("Impossible to implement ptr() of CConfigValue<std::string>");
|
||||||
|
abort();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline std::string CSimpleConfigValue<std::string>::operator*() const {
|
||||||
|
return std::string{*(Hyprlang::STRING*)p_};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline Hyprlang::STRING* CSimpleConfigValue<Hyprlang::STRING>::ptr() const {
|
||||||
|
return (Hyprlang::STRING*)p_;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline Hyprlang::STRING CSimpleConfigValue<Hyprlang::STRING>::operator*() const {
|
||||||
|
return *(Hyprlang::STRING*)p_;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline Hyprlang::CUSTOMTYPE* CSimpleConfigValue<Hyprlang::CUSTOMTYPE>::ptr() const {
|
||||||
|
return *(Hyprlang::CUSTOMTYPE* const*)p_;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline Hyprlang::CUSTOMTYPE CSimpleConfigValue<Hyprlang::CUSTOMTYPE>::operator*() const {
|
||||||
|
std::print("Impossible to implement operator* of CConfigValue<Hyprlang::CUSTOMTYPE>, use ptr()");
|
||||||
|
abort();
|
||||||
|
return *ptr();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef HYPRLANG_INTERNAL
|
#ifndef HYPRLANG_INTERNAL
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
static const char* MULTILINE_SPACE_CHARSET = " \t";
|
static const char* MULTILINE_SPACE_CHARSET = " \t";
|
||||||
|
|
||||||
|
|
|
@ -187,6 +187,16 @@ int main(int argc, char** argv, char** envp) {
|
||||||
EXPECT(ignoreKeyword, "aaa");
|
EXPECT(ignoreKeyword, "aaa");
|
||||||
EXPECT(useKeyword, "yes");
|
EXPECT(useKeyword, "yes");
|
||||||
|
|
||||||
|
// Test templated wrapper
|
||||||
|
auto T1 = Hyprlang::CSimpleConfigValue<Hyprlang::INT>(&config, "testInt");
|
||||||
|
auto T2 = Hyprlang::CSimpleConfigValue<Hyprlang::FLOAT>(&config, "testFloat");
|
||||||
|
auto T3 = Hyprlang::CSimpleConfigValue<Hyprlang::SVector2D>(&config, "testVec");
|
||||||
|
auto T4 = Hyprlang::CSimpleConfigValue<std::string>(&config, "testString");
|
||||||
|
EXPECT(*T1, 123);
|
||||||
|
EXPECT(*T2, 123.456F);
|
||||||
|
EXPECT(*T3, EXP);
|
||||||
|
EXPECT(*T4, "Hello World! # This is not a comment!");
|
||||||
|
|
||||||
// test static values
|
// test static values
|
||||||
std::cout << " → Testing static values\n";
|
std::cout << " → Testing static values\n";
|
||||||
static auto* const PTESTINT = config.getConfigValuePtr("testInt")->getDataStaticPtr();
|
static auto* const PTESTINT = config.getConfigValuePtr("testInt")->getDataStaticPtr();
|
||||||
|
|
Loading…
Reference in a new issue