mirror of
https://github.com/hyprwm/hyprlang.git
synced 2025-05-13 05:40:42 +01:00
Compare commits
54 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
557241780c | ||
![]() |
a59e86a3da | ||
![]() |
a15e7ba78a | ||
![]() |
e863ebcee9 | ||
![]() |
6726cfd54b | ||
![]() |
397600c42b | ||
![]() |
f1000c54d2 | ||
![]() |
72df3861f1 | ||
![]() |
1d7d96a278 | ||
![]() |
a7334904d5 | ||
![]() |
7a59f2de3f | ||
![]() |
f41271d35c | ||
![]() |
55608efdaa | ||
![]() |
0404833ea1 | ||
![]() |
16e59c1eb1 | ||
![]() |
9441266c89 | ||
![]() |
f7acd5dabb | ||
![]() |
1b0c595731 | ||
![]() |
058fcf84c9 | ||
![]() |
f054f2e44d | ||
![]() |
dfeb5811dd | ||
![]() |
5b175c9704 | ||
![]() |
c12ab785ce | ||
![]() |
16e5c9465f | ||
![]() |
adbefbf496 | ||
![]() |
651c8d02cc | ||
![]() |
c0704455ee | ||
![]() |
5df0174fd0 | ||
![]() |
095f54b910 | ||
![]() |
db8c528aac | ||
![]() |
ec6938c662 | ||
![]() |
87d5d98410 | ||
![]() |
c7c2d29831 | ||
![]() |
554c95a846 | ||
![]() |
969cb076e5 | ||
![]() |
073678282e | ||
![]() |
19ec261528 | ||
![]() |
78fcaa27ae | ||
![]() |
748fb531ca | ||
![]() |
c140261214 | ||
![]() |
95471ec86f | ||
![]() |
b3e430f81f | ||
![]() |
a2f3942114 | ||
![]() |
a685493fdb | ||
![]() |
84170ba0e5 | ||
![]() |
bba5daeaf9 | ||
![]() |
2e2a1992c8 | ||
![]() |
9995f54edd | ||
![]() |
66c099e097 | ||
![]() |
f1db1a7e1f | ||
![]() |
221714841a | ||
![]() |
7edc9a664e | ||
![]() |
6cb791c18c | ||
![]() |
3cc06e1687 |
21 changed files with 1138 additions and 957 deletions
101
.clang-tidy
Normal file
101
.clang-tidy
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
WarningsAsErrors: '*'
|
||||||
|
HeaderFilterRegex: '.*\.hpp'
|
||||||
|
FormatStyle: 'file'
|
||||||
|
Checks: >
|
||||||
|
-*,
|
||||||
|
bugprone-*,
|
||||||
|
-bugprone-easily-swappable-parameters,
|
||||||
|
-bugprone-forward-declaration-namespace,
|
||||||
|
-bugprone-forward-declaration-namespace,
|
||||||
|
-bugprone-macro-parentheses,
|
||||||
|
-bugprone-narrowing-conversions,
|
||||||
|
-bugprone-branch-clone,
|
||||||
|
-bugprone-assignment-in-if-condition,
|
||||||
|
concurrency-*,
|
||||||
|
-concurrency-mt-unsafe,
|
||||||
|
cppcoreguidelines-*,
|
||||||
|
-cppcoreguidelines-owning-memory,
|
||||||
|
-cppcoreguidelines-avoid-magic-numbers,
|
||||||
|
-cppcoreguidelines-pro-bounds-constant-array-index,
|
||||||
|
-cppcoreguidelines-avoid-const-or-ref-data-members,
|
||||||
|
-cppcoreguidelines-non-private-member-variables-in-classes,
|
||||||
|
-cppcoreguidelines-avoid-goto,
|
||||||
|
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
|
||||||
|
-cppcoreguidelines-avoid-do-while,
|
||||||
|
-cppcoreguidelines-avoid-non-const-global-variables,
|
||||||
|
-cppcoreguidelines-special-member-functions,
|
||||||
|
-cppcoreguidelines-explicit-virtual-functions,
|
||||||
|
-cppcoreguidelines-avoid-c-arrays,
|
||||||
|
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
|
||||||
|
-cppcoreguidelines-narrowing-conversions,
|
||||||
|
-cppcoreguidelines-pro-type-union-access,
|
||||||
|
-cppcoreguidelines-pro-type-member-init,
|
||||||
|
-cppcoreguidelines-macro-usage,
|
||||||
|
-cppcoreguidelines-macro-to-enum,
|
||||||
|
-cppcoreguidelines-init-variables,
|
||||||
|
-cppcoreguidelines-pro-type-cstyle-cast,
|
||||||
|
-cppcoreguidelines-pro-type-vararg,
|
||||||
|
-cppcoreguidelines-pro-type-reinterpret-cast,
|
||||||
|
google-global-names-in-headers,
|
||||||
|
-google-readability-casting,
|
||||||
|
google-runtime-operator,
|
||||||
|
misc-*,
|
||||||
|
-misc-unused-parameters,
|
||||||
|
-misc-no-recursion,
|
||||||
|
-misc-non-private-member-variables-in-classes,
|
||||||
|
-misc-include-cleaner,
|
||||||
|
-misc-use-anonymous-namespace,
|
||||||
|
-misc-const-correctness,
|
||||||
|
modernize-*,
|
||||||
|
-modernize-return-braced-init-list,
|
||||||
|
-modernize-use-trailing-return-type,
|
||||||
|
-modernize-use-using,
|
||||||
|
-modernize-use-override,
|
||||||
|
-modernize-avoid-c-arrays,
|
||||||
|
-modernize-macro-to-enum,
|
||||||
|
-modernize-loop-convert,
|
||||||
|
-modernize-use-nodiscard,
|
||||||
|
-modernize-pass-by-value,
|
||||||
|
-modernize-use-auto,
|
||||||
|
performance-*,
|
||||||
|
-performance-avoid-endl,
|
||||||
|
-performance-unnecessary-value-param,
|
||||||
|
portability-std-allocator-const,
|
||||||
|
readability-*,
|
||||||
|
-readability-function-cognitive-complexity,
|
||||||
|
-readability-function-size,
|
||||||
|
-readability-identifier-length,
|
||||||
|
-readability-magic-numbers,
|
||||||
|
-readability-uppercase-literal-suffix,
|
||||||
|
-readability-braces-around-statements,
|
||||||
|
-readability-redundant-access-specifiers,
|
||||||
|
-readability-else-after-return,
|
||||||
|
-readability-container-data-pointer,
|
||||||
|
-readability-implicit-bool-conversion,
|
||||||
|
-readability-avoid-nested-conditional-operator,
|
||||||
|
-readability-redundant-member-init,
|
||||||
|
-readability-redundant-string-init,
|
||||||
|
-readability-avoid-const-params-in-decls,
|
||||||
|
-readability-named-parameter,
|
||||||
|
-readability-convert-member-functions-to-static,
|
||||||
|
-readability-qualified-auto,
|
||||||
|
-readability-make-member-function-const,
|
||||||
|
-readability-isolate-declaration,
|
||||||
|
-readability-inconsistent-declaration-parameter-name,
|
||||||
|
-clang-diagnostic-error,
|
||||||
|
|
||||||
|
CheckOptions:
|
||||||
|
performance-for-range-copy.WarnOnAllAutoCopies: true
|
||||||
|
performance-inefficient-string-concatenation.StrictMode: true
|
||||||
|
readability-braces-around-statements.ShortStatementLines: 0
|
||||||
|
readability-identifier-naming.ClassCase: CamelCase
|
||||||
|
readability-identifier-naming.ClassIgnoredRegexp: I.*
|
||||||
|
readability-identifier-naming.ClassPrefix: C # We can't use regex here?!?!?!?
|
||||||
|
readability-identifier-naming.EnumCase: CamelCase
|
||||||
|
readability-identifier-naming.EnumPrefix: e
|
||||||
|
readability-identifier-naming.EnumConstantCase: UPPER_CASE
|
||||||
|
readability-identifier-naming.FunctionCase: camelBack
|
||||||
|
readability-identifier-naming.NamespaceCase: CamelCase
|
||||||
|
readability-identifier-naming.NamespacePrefix: N
|
||||||
|
readability-identifier-naming.StructPrefix: S
|
||||||
|
readability-identifier-naming.StructCase: CamelCase
|
59
.github/workflows/arch.yml
vendored
59
.github/workflows/arch.yml
vendored
|
@ -2,39 +2,6 @@ name: Build & Test (Arch)
|
||||||
|
|
||||||
on: [push, pull_request, workflow_dispatch]
|
on: [push, pull_request, workflow_dispatch]
|
||||||
jobs:
|
jobs:
|
||||||
gcc:
|
|
||||||
name: "gcc build / clang test"
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: archlinux
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository actions
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
sparse-checkout: .github/actions
|
|
||||||
|
|
||||||
- name: Get required pkgs
|
|
||||||
run: |
|
|
||||||
sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf
|
|
||||||
pacman --noconfirm --noprogressbar -Syyu
|
|
||||||
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang
|
|
||||||
|
|
||||||
- name: Build hyprlang with gcc
|
|
||||||
run: |
|
|
||||||
CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build
|
|
||||||
CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --build ./build --config Release --target hyprlang -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
|
||||||
cmake --install ./build
|
|
||||||
|
|
||||||
- name: Build tests with clang
|
|
||||||
run: |
|
|
||||||
rm -rf ./build
|
|
||||||
CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build
|
|
||||||
CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --build ./build --config Release --target tests -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
run: |
|
|
||||||
cd ./build && ctest --output-on-failure
|
|
||||||
|
|
||||||
asan:
|
asan:
|
||||||
name: "gcc build / ASan tests"
|
name: "gcc build / ASan tests"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
@ -50,7 +17,11 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf
|
sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf
|
||||||
pacman --noconfirm --noprogressbar -Syyu
|
pacman --noconfirm --noprogressbar -Syyu
|
||||||
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang
|
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang git pixman
|
||||||
|
|
||||||
|
- name: Get hyprutils-git
|
||||||
|
run: |
|
||||||
|
git clone https://github.com/hyprwm/hyprutils && cd hyprutils && cmake -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -B build && cmake --build build --target hyprutils && cmake --install build
|
||||||
|
|
||||||
- name: Build with gcc
|
- name: Build with gcc
|
||||||
run: |
|
run: |
|
||||||
|
@ -77,7 +48,11 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf
|
sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf
|
||||||
pacman --noconfirm --noprogressbar -Syyu
|
pacman --noconfirm --noprogressbar -Syyu
|
||||||
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang
|
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang git pixman
|
||||||
|
|
||||||
|
- name: Get hyprutils-git
|
||||||
|
run: |
|
||||||
|
git clone https://github.com/hyprwm/hyprutils && cd hyprutils && cmake -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -B build && cmake --build build --target hyprutils && cmake --install build
|
||||||
|
|
||||||
- name: Build with gcc
|
- name: Build with gcc
|
||||||
run: |
|
run: |
|
||||||
|
@ -104,7 +79,11 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf
|
sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf
|
||||||
pacman --noconfirm --noprogressbar -Syyu
|
pacman --noconfirm --noprogressbar -Syyu
|
||||||
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang
|
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang git pixman
|
||||||
|
|
||||||
|
- name: Get hyprutils-git
|
||||||
|
run: |
|
||||||
|
git clone https://github.com/hyprwm/hyprutils && cd hyprutils && cmake -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -B build && cmake --build build --target hyprutils && cmake --install build
|
||||||
|
|
||||||
- name: Build with gcc
|
- name: Build with gcc
|
||||||
run: |
|
run: |
|
||||||
|
@ -131,11 +110,15 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf
|
sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf
|
||||||
pacman --noconfirm --noprogressbar -Syyu
|
pacman --noconfirm --noprogressbar -Syyu
|
||||||
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang
|
pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang libc++ git pixman
|
||||||
|
|
||||||
|
- name: Get hyprutils-git
|
||||||
|
run: |
|
||||||
|
git clone https://github.com/hyprwm/hyprutils && cd hyprutils && cmake -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -B build && cmake --build build --target hyprutils && cmake --install build
|
||||||
|
|
||||||
- name: Build hyprlang with clang
|
- name: Build hyprlang with clang
|
||||||
run: |
|
run: |
|
||||||
CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build
|
CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_CXX_FLAGS="-stdlib=libc++" -S . -B ./build
|
||||||
CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --build ./build --config Release --target hyprlang -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --build ./build --config Release --target hyprlang -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
||||||
cmake --install ./build
|
cmake --install ./build
|
||||||
|
|
||||||
|
|
1
.github/workflows/nix.yml
vendored
1
.github/workflows/nix.yml
vendored
|
@ -14,7 +14,6 @@ jobs:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- uses: DeterminateSystems/nix-installer-action@main
|
- uses: DeterminateSystems/nix-installer-action@main
|
||||||
- uses: DeterminateSystems/magic-nix-cache-action@main
|
|
||||||
|
|
||||||
# not needed (yet)
|
# not needed (yet)
|
||||||
# - uses: cachix/cachix-action@v12
|
# - uses: cachix/cachix-action@v12
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -13,3 +13,4 @@ _deps
|
||||||
build/
|
build/
|
||||||
doxygen/
|
doxygen/
|
||||||
doxygen-awesome-css/
|
doxygen-awesome-css/
|
||||||
|
.cache/
|
|
@ -1,11 +1,12 @@
|
||||||
cmake_minimum_required(VERSION 3.19)
|
cmake_minimum_required(VERSION 3.19)
|
||||||
|
|
||||||
set(HYPRLANG_VERSION "0.4.1")
|
file(READ "${CMAKE_SOURCE_DIR}/VERSION" VER_RAW)
|
||||||
|
string(STRIP ${VER_RAW} HYPRLANG_VERSION)
|
||||||
|
|
||||||
project(hyprlang
|
project(
|
||||||
VERSION ${HYPRLANG_VERSION}
|
hyprlang
|
||||||
DESCRIPTION "A library to parse hypr config files"
|
VERSION ${HYPRLANG_VERSION}
|
||||||
)
|
DESCRIPTION "A library to parse hypr config files")
|
||||||
|
|
||||||
include(CTest)
|
include(CTest)
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
@ -16,43 +17,69 @@ set(LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR})
|
||||||
|
|
||||||
configure_file(hyprlang.pc.in hyprlang.pc @ONLY)
|
configure_file(hyprlang.pc.in hyprlang.pc @ONLY)
|
||||||
|
|
||||||
|
if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG)
|
||||||
|
message(STATUS "Configuring hyprlang in Debug")
|
||||||
|
add_compile_definitions(HYPRLAND_DEBUG)
|
||||||
|
else()
|
||||||
|
add_compile_options(-O3)
|
||||||
|
message(STATUS "Configuring hyprlang in Release")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_compile_definitions(HYPRLANG_INTERNAL)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 23)
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
|
add_compile_options(
|
||||||
|
-Wall
|
||||||
|
-Wextra
|
||||||
|
-Wpedantic
|
||||||
|
-Wno-unused-parameter
|
||||||
|
-Wno-missing-field-initializers)
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
|
||||||
|
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_check_modules(deps REQUIRED IMPORTED_TARGET hyprutils>=0.7.1)
|
||||||
|
|
||||||
file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp" "include/hyprlang.hpp")
|
file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp" "include/hyprlang.hpp")
|
||||||
|
|
||||||
add_library(hyprlang SHARED ${SRCFILES})
|
add_library(hyprlang SHARED ${SRCFILES})
|
||||||
target_include_directories( hyprlang
|
target_include_directories(
|
||||||
PUBLIC "./include"
|
hyprlang
|
||||||
PRIVATE "./src"
|
PUBLIC "./include"
|
||||||
)
|
PRIVATE "./src")
|
||||||
set_target_properties(hyprlang PROPERTIES
|
set_target_properties(
|
||||||
VERSION ${HYPRLANG_VERSION}
|
hyprlang
|
||||||
SOVERSION 1
|
PROPERTIES VERSION ${HYPRLANG_VERSION}
|
||||||
PUBLIC_HEADER include/hyprlang.hpp)
|
SOVERSION 2
|
||||||
|
PUBLIC_HEADER include/hyprlang.hpp)
|
||||||
|
|
||||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
target_link_libraries(hyprlang PkgConfig::deps)
|
||||||
# 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)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
add_library(hypr::hyprlang ALIAS hyprlang)
|
||||||
install(TARGETS hyprlang)
|
install(TARGETS hyprlang)
|
||||||
|
|
||||||
# tests
|
# tests
|
||||||
add_custom_target(tests)
|
add_custom_target(tests)
|
||||||
|
|
||||||
add_executable(hyprlang_test "tests/parse/main.cpp")
|
add_executable(hyprlang_test "tests/parse/main.cpp")
|
||||||
target_link_libraries(hyprlang_test PRIVATE hyprlang)
|
target_link_libraries(hyprlang_test PRIVATE hypr::hyprlang)
|
||||||
add_test(NAME "Parsing" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests COMMAND hyprlang_test "parse")
|
add_test(
|
||||||
|
NAME "Parsing"
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests
|
||||||
|
COMMAND hyprlang_test "parse")
|
||||||
add_dependencies(tests hyprlang_test)
|
add_dependencies(tests hyprlang_test)
|
||||||
|
|
||||||
add_executable(hyprlang_fuzz "tests/fuzz/main.cpp")
|
add_executable(hyprlang_fuzz "tests/fuzz/main.cpp")
|
||||||
target_link_libraries(hyprlang_fuzz PRIVATE hyprlang)
|
target_link_libraries(hyprlang_fuzz PRIVATE hypr::hyprlang)
|
||||||
add_test(NAME "Fuzz" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests COMMAND hyprlang_fuzz "fuzz")
|
add_test(
|
||||||
|
NAME "Fuzz"
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests
|
||||||
|
COMMAND hyprlang_fuzz "fuzz")
|
||||||
add_dependencies(tests hyprlang_fuzz)
|
add_dependencies(tests hyprlang_fuzz)
|
||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
install(TARGETS hyprlang
|
install(
|
||||||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
TARGETS hyprlang
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
install(FILES ${CMAKE_BINARY_DIR}/hyprlang.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||||
|
install(FILES ${CMAKE_BINARY_DIR}/hyprlang.pc
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||||
|
|
2
COPYRIGHT
Normal file
2
COPYRIGHT
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
Copyright: Copyright (C) 2023-2024 Hypr Development <vaxry@vaxry.net>
|
||||||
|
License: LGPL-3.0-Only
|
827
LICENSE
827
LICENSE
|
@ -1,674 +1,165 @@
|
||||||
GNU GENERAL PUBLIC LICENSE
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
Version 3, 29 June 2007
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
of this license document, but changing it is not allowed.
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
This version of the GNU Lesser General Public License incorporates
|
||||||
The GNU General Public License is a free, copyleft license for
|
the terms and conditions of version 3 of the GNU General Public
|
||||||
software and other kinds of works.
|
License, supplemented by the additional permissions listed below.
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
0. Additional Definitions.
|
||||||
to take away your freedom to share and change the works. By contrast,
|
|
||||||
the GNU General Public License is intended to guarantee your freedom to
|
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||||
share and change all versions of a program--to make sure it remains free
|
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||||
software for all its users. We, the Free Software Foundation, use the
|
General Public License.
|
||||||
GNU General Public License for most of our software; it applies also to
|
|
||||||
any other work released this way by its authors. You can apply it to
|
"The Library" refers to a covered work governed by this License,
|
||||||
your programs, too.
|
other than an Application or a Combined Work as defined below.
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
An "Application" is any work that makes use of an interface provided
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
by the Library, but which is not otherwise based on the Library.
|
||||||
have the freedom to distribute copies of free software (and charge for
|
Defining a subclass of a class defined by the Library is deemed a mode
|
||||||
them if you wish), that you receive source code or can get it if you
|
of using an interface provided by the Library.
|
||||||
want it, that you can change the software or use pieces of it in new
|
|
||||||
free programs, and that you know you can do these things.
|
A "Combined Work" is a work produced by combining or linking an
|
||||||
|
Application with the Library. The particular version of the Library
|
||||||
To protect your rights, we need to prevent others from denying you
|
with which the Combined Work was made is also called the "Linked
|
||||||
these rights or asking you to surrender the rights. Therefore, you have
|
Version".
|
||||||
certain responsibilities if you distribute copies of the software, or if
|
|
||||||
you modify it: responsibilities to respect the freedom of others.
|
The "Minimal Corresponding Source" for a Combined Work means the
|
||||||
|
Corresponding Source for the Combined Work, excluding any source code
|
||||||
For example, if you distribute copies of such a program, whether
|
for portions of the Combined Work that, considered in isolation, are
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
based on the Application, and not on the Linked Version.
|
||||||
freedoms that you received. You must make sure that they, too, receive
|
|
||||||
or can get the source code. And you must show them these terms so they
|
The "Corresponding Application Code" for a Combined Work means the
|
||||||
know their rights.
|
object code and/or source code for the Application, including any data
|
||||||
|
and utility programs needed for reproducing the Combined Work from the
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
Application, but excluding the System Libraries of the Combined Work.
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
1. Exception to Section 3 of the GNU GPL.
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
You may convey a covered work under sections 3 and 4 of this License
|
||||||
that there is no warranty for this free software. For both users' and
|
without being bound by section 3 of the GNU GPL.
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
|
||||||
changed, so that their problems will not be attributed erroneously to
|
2. Conveying Modified Versions.
|
||||||
authors of previous versions.
|
|
||||||
|
If you modify a copy of the Library, and, in your modifications, a
|
||||||
Some devices are designed to deny users access to install or run
|
facility refers to a function or data to be supplied by an Application
|
||||||
modified versions of the software inside them, although the manufacturer
|
that uses the facility (other than as an argument passed when the
|
||||||
can do so. This is fundamentally incompatible with the aim of
|
facility is invoked), then you may convey a copy of the modified
|
||||||
protecting users' freedom to change the software. The systematic
|
version:
|
||||||
pattern of such abuse occurs in the area of products for individuals to
|
|
||||||
use, which is precisely where it is most unacceptable. Therefore, we
|
a) under this License, provided that you make a good faith effort to
|
||||||
have designed this version of the GPL to prohibit the practice for those
|
ensure that, in the event an Application does not supply the
|
||||||
products. If such problems arise substantially in other domains, we
|
function or data, the facility still operates, and performs
|
||||||
stand ready to extend this provision to those domains in future versions
|
whatever part of its purpose remains meaningful, or
|
||||||
of the GPL, as needed to protect the freedom of users.
|
|
||||||
|
b) under the GNU GPL, with none of the additional permissions of
|
||||||
Finally, every program is threatened constantly by software patents.
|
this License applicable to that copy.
|
||||||
States should not allow patents to restrict development and use of
|
|
||||||
software on general-purpose computers, but in those that do, we wish to
|
3. Object Code Incorporating Material from Library Header Files.
|
||||||
avoid the special danger that patents applied to a free program could
|
|
||||||
make it effectively proprietary. To prevent this, the GPL assures that
|
The object code form of an Application may incorporate material from
|
||||||
patents cannot be used to render the program non-free.
|
a header file that is part of the Library. You may convey such object
|
||||||
|
code under terms of your choice, provided that, if the incorporated
|
||||||
The precise terms and conditions for copying, distribution and
|
material is not limited to numerical parameters, data structure
|
||||||
modification follow.
|
layouts and accessors, or small macros, inline functions and templates
|
||||||
|
(ten or fewer lines in length), you do both of the following:
|
||||||
TERMS AND CONDITIONS
|
|
||||||
|
a) Give prominent notice with each copy of the object code that the
|
||||||
0. Definitions.
|
Library is used in it and that the Library and its use are
|
||||||
|
covered by this License.
|
||||||
"This License" refers to version 3 of the GNU General Public License.
|
|
||||||
|
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
document.
|
||||||
works, such as semiconductor masks.
|
|
||||||
|
4. Combined Works.
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
You may convey a Combined Work under terms of your choice that,
|
||||||
"recipients" may be individuals or organizations.
|
taken together, effectively do not restrict modification of the
|
||||||
|
portions of the Library contained in the Combined Work and reverse
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
engineering for debugging such modifications, if you also do each of
|
||||||
in a fashion requiring copyright permission, other than the making of an
|
the following:
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
|
||||||
earlier work or a work "based on" the earlier work.
|
a) Give prominent notice with each copy of the Combined Work that
|
||||||
|
the Library is used in it and that the Library and its use are
|
||||||
A "covered work" means either the unmodified Program or a work based
|
covered by this License.
|
||||||
on the Program.
|
|
||||||
|
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||||
To "propagate" a work means to do anything with it that, without
|
document.
|
||||||
permission, would make you directly or secondarily liable for
|
|
||||||
infringement under applicable copyright law, except executing it on a
|
c) For a Combined Work that displays copyright notices during
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
execution, include the copyright notice for the Library among
|
||||||
distribution (with or without modification), making available to the
|
these notices, as well as a reference directing the user to the
|
||||||
public, and in some countries other activities as well.
|
copies of the GNU GPL and this license document.
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
d) Do one of the following:
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
0) Convey the Minimal Corresponding Source under the terms of this
|
||||||
|
License, and the Corresponding Application Code in a form
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
suitable for, and under terms that permit, the user to
|
||||||
to the extent that it includes a convenient and prominently visible
|
recombine or relink the Application with a modified version of
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
the Linked Version to produce a modified Combined Work, in the
|
||||||
tells the user that there is no warranty for the work (except to the
|
manner specified by section 6 of the GNU GPL for conveying
|
||||||
extent that warranties are provided), that licensees may convey the
|
Corresponding Source.
|
||||||
work under this License, and how to view a copy of this License. If
|
|
||||||
the interface presents a list of user commands or options, such as a
|
1) Use a suitable shared library mechanism for linking with the
|
||||||
menu, a prominent item in the list meets this criterion.
|
Library. A suitable mechanism is one that (a) uses at run time
|
||||||
|
a copy of the Library already present on the user's computer
|
||||||
1. Source Code.
|
system, and (b) will operate properly with a modified version
|
||||||
|
of the Library that is interface-compatible with the Linked
|
||||||
The "source code" for a work means the preferred form of the work
|
Version.
|
||||||
for making modifications to it. "Object code" means any non-source
|
|
||||||
form of a work.
|
e) Provide Installation Information, but only if you would otherwise
|
||||||
|
be required to provide such information under section 6 of the
|
||||||
A "Standard Interface" means an interface that either is an official
|
GNU GPL, and only to the extent that such information is
|
||||||
standard defined by a recognized standards body, or, in the case of
|
necessary to install and execute a modified version of the
|
||||||
interfaces specified for a particular programming language, one that
|
Combined Work produced by recombining or relinking the
|
||||||
is widely used among developers working in that language.
|
Application with a modified version of the Linked Version. (If
|
||||||
|
you use option 4d0, the Installation Information must accompany
|
||||||
The "System Libraries" of an executable work include anything, other
|
the Minimal Corresponding Source and Corresponding Application
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
Code. If you use option 4d1, you must provide the Installation
|
||||||
packaging a Major Component, but which is not part of that Major
|
Information in the manner specified by section 6 of the GNU GPL
|
||||||
Component, and (b) serves only to enable use of the work with that
|
for conveying Corresponding Source.)
|
||||||
Major Component, or to implement a Standard Interface for which an
|
|
||||||
implementation is available to the public in source code form. A
|
5. Combined Libraries.
|
||||||
"Major Component", in this context, means a major essential component
|
|
||||||
(kernel, window system, and so on) of the specific operating system
|
You may place library facilities that are a work based on the
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
Library side by side in a single library together with other library
|
||||||
produce the work, or an object code interpreter used to run it.
|
facilities that are not Applications and are not covered by this
|
||||||
|
License, and convey such a combined library under terms of your
|
||||||
The "Corresponding Source" for a work in object code form means all
|
choice, if you do both of the following:
|
||||||
the source code needed to generate, install, and (for an executable
|
|
||||||
work) run the object code and to modify the work, including scripts to
|
a) Accompany the combined library with a copy of the same work based
|
||||||
control those activities. However, it does not include the work's
|
on the Library, uncombined with any other library facilities,
|
||||||
System Libraries, or general-purpose tools or generally available free
|
conveyed under the terms of this License.
|
||||||
programs which are used unmodified in performing those activities but
|
|
||||||
which are not part of the work. For example, Corresponding Source
|
b) Give prominent notice with the combined library that part of it
|
||||||
includes interface definition files associated with source files for
|
is a work based on the Library, and explaining where to find the
|
||||||
the work, and the source code for shared libraries and dynamically
|
accompanying uncombined form of the same work.
|
||||||
linked subprograms that the work is specifically designed to require,
|
|
||||||
such as by intimate data communication or control flow between those
|
6. Revised Versions of the GNU Lesser General Public License.
|
||||||
subprograms and other parts of the work.
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions
|
||||||
The Corresponding Source need not include anything that users
|
of the GNU Lesser General Public License from time to time. Such new
|
||||||
can regenerate automatically from other parts of the Corresponding
|
versions will be similar in spirit to the present version, but may
|
||||||
Source.
|
differ in detail to address new problems or concerns.
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that
|
Each version is given a distinguishing version number. If the
|
||||||
same work.
|
Library as you received it specifies that a certain numbered version
|
||||||
|
of the GNU Lesser General Public License "or any later version"
|
||||||
2. Basic Permissions.
|
applies to it, you have the option of following the terms and
|
||||||
|
conditions either of that published version or of any later version
|
||||||
All rights granted under this License are granted for the term of
|
published by the Free Software Foundation. If the Library as you
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
received it does not specify a version number of the GNU Lesser
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
General Public License, you may choose any version of the GNU Lesser
|
||||||
permission to run the unmodified Program. The output from running a
|
General Public License ever published by the Free Software Foundation.
|
||||||
covered work is covered by this License only if the output, given its
|
|
||||||
content, constitutes a covered work. This License acknowledges your
|
If the Library as you received it specifies that a proxy can decide
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
whether future versions of the GNU Lesser General Public License shall
|
||||||
|
apply, that proxy's public statement of acceptance of any version is
|
||||||
You may make, run and propagate covered works that you do not
|
permanent authorization for you to choose that version for the
|
||||||
convey, without conditions so long as your license otherwise remains
|
Library.
|
||||||
in force. You may convey covered works to others for the sole purpose
|
|
||||||
of having them make modifications exclusively for you, or provide you
|
|
||||||
with facilities for running those works, provided that you comply with
|
|
||||||
the terms of this License in conveying all material for which you do
|
|
||||||
not control copyright. Those thus making or running the covered works
|
|
||||||
for you must do so exclusively on your behalf, under your direction
|
|
||||||
and control, on terms that prohibit them from making any copies of
|
|
||||||
your copyrighted material outside their relationship with you.
|
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under
|
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
|
||||||
makes it unnecessary.
|
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
|
||||||
measure under any applicable law fulfilling obligations under article
|
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
||||||
similar laws prohibiting or restricting circumvention of such
|
|
||||||
measures.
|
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
|
||||||
circumvention of technological measures to the extent such circumvention
|
|
||||||
is effected by exercising rights under this License with respect to
|
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
|
||||||
modification of the work as a means of enforcing, against the work's
|
|
||||||
users, your or third parties' legal rights to forbid circumvention of
|
|
||||||
technological measures.
|
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
|
||||||
receive it, in any medium, provided that you conspicuously and
|
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
|
||||||
keep intact all notices stating that this License and any
|
|
||||||
non-permissive terms added in accord with section 7 apply to the code;
|
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
|
||||||
recipients a copy of this License along with the Program.
|
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
|
||||||
and you may offer support or warranty protection for a fee.
|
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
|
||||||
produce it from the Program, in the form of source code under the
|
|
||||||
terms of section 4, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified
|
|
||||||
it, and giving a relevant date.
|
|
||||||
|
|
||||||
b) The work must carry prominent notices stating that it is
|
|
||||||
released under this License and any conditions added under section
|
|
||||||
7. This requirement modifies the requirement in section 4 to
|
|
||||||
"keep intact all notices".
|
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this
|
|
||||||
License to anyone who comes into possession of a copy. This
|
|
||||||
License will therefore apply, along with any applicable section 7
|
|
||||||
additional terms, to the whole of the work, and all its parts,
|
|
||||||
regardless of how they are packaged. This License gives no
|
|
||||||
permission to license the work in any other way, but it does not
|
|
||||||
invalidate such permission if you have separately received it.
|
|
||||||
|
|
||||||
d) If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
|
||||||
work need not make them do so.
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
|
||||||
works, which are not by their nature extensions of the covered work,
|
|
||||||
and which are not combined with it such as to form a larger program,
|
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
|
||||||
"aggregate" if the compilation and its resulting copyright are not
|
|
||||||
used to limit the access or legal rights of the compilation's users
|
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
|
||||||
in an aggregate does not cause this License to apply to the other
|
|
||||||
parts of the aggregate.
|
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
|
||||||
of sections 4 and 5, provided that you also convey the
|
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
|
||||||
in one of these ways:
|
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by the
|
|
||||||
Corresponding Source fixed on a durable physical medium
|
|
||||||
customarily used for software interchange.
|
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a
|
|
||||||
written offer, valid for at least three years and valid for as
|
|
||||||
long as you offer spare parts or customer support for that product
|
|
||||||
model, to give anyone who possesses the object code either (1) a
|
|
||||||
copy of the Corresponding Source for all the software in the
|
|
||||||
product that is covered by this License, on a durable physical
|
|
||||||
medium customarily used for software interchange, for a price no
|
|
||||||
more than your reasonable cost of physically performing this
|
|
||||||
conveying of source, or (2) access to copy the
|
|
||||||
Corresponding Source from a network server at no charge.
|
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the
|
|
||||||
written offer to provide the Corresponding Source. This
|
|
||||||
alternative is allowed only occasionally and noncommercially, and
|
|
||||||
only if you received the object code with such an offer, in accord
|
|
||||||
with subsection 6b.
|
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated
|
|
||||||
place (gratis or for a charge), and offer equivalent access to the
|
|
||||||
Corresponding Source in the same way through the same place at no
|
|
||||||
further charge. You need not require recipients to copy the
|
|
||||||
Corresponding Source along with the object code. If the place to
|
|
||||||
copy the object code is a network server, the Corresponding Source
|
|
||||||
may be on a different server (operated by you or a third party)
|
|
||||||
that supports equivalent copying facilities, provided you maintain
|
|
||||||
clear directions next to the object code saying where to find the
|
|
||||||
Corresponding Source. Regardless of what server hosts the
|
|
||||||
Corresponding Source, you remain obligated to ensure that it is
|
|
||||||
available for as long as needed to satisfy these requirements.
|
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided
|
|
||||||
you inform other peers where the object code and Corresponding
|
|
||||||
Source of the work are being offered to the general public at no
|
|
||||||
charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
|
||||||
included in conveying the object code work.
|
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
|
||||||
tangible personal property which is normally used for personal, family,
|
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
|
||||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
|
||||||
product received by a particular user, "normally used" refers to a
|
|
||||||
typical or common use of that class of product, regardless of the status
|
|
||||||
of the particular user or of the way in which the particular user
|
|
||||||
actually uses, or expects or is expected to use, the product. A product
|
|
||||||
is a consumer product regardless of whether the product has substantial
|
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
|
||||||
the only significant mode of use of the product.
|
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
|
||||||
procedures, authorization keys, or other information required to install
|
|
||||||
and execute modified versions of a covered work in that User Product from
|
|
||||||
a modified version of its Corresponding Source. The information must
|
|
||||||
suffice to ensure that the continued functioning of the modified object
|
|
||||||
code is in no case prevented or interfered with solely because
|
|
||||||
modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
|
||||||
part of a transaction in which the right of possession and use of the
|
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
|
||||||
by the Installation Information. But this requirement does not apply
|
|
||||||
if neither you nor any third party retains the ability to install
|
|
||||||
modified object code on the User Product (for example, the work has
|
|
||||||
been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
|
||||||
requirement to continue to provide support service, warranty, or updates
|
|
||||||
for a work that has been modified or installed by the recipient, or for
|
|
||||||
the User Product in which it has been modified or installed. Access to a
|
|
||||||
network may be denied when the modification itself materially and
|
|
||||||
adversely affects the operation of the network or violates the rules and
|
|
||||||
protocols for communication across the network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
|
||||||
in accord with this section must be in a format that is publicly
|
|
||||||
documented (and with an implementation available to the public in
|
|
||||||
source code form), and must require no special password or key for
|
|
||||||
unpacking, reading or copying.
|
|
||||||
|
|
||||||
7. Additional Terms.
|
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
|
||||||
License by making exceptions from one or more of its conditions.
|
|
||||||
Additional permissions that are applicable to the entire Program shall
|
|
||||||
be treated as though they were included in this License, to the extent
|
|
||||||
that they are valid under applicable law. If additional permissions
|
|
||||||
apply only to part of the Program, that part may be used separately
|
|
||||||
under those permissions, but the entire Program remains governed by
|
|
||||||
this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
|
||||||
remove any additional permissions from that copy, or from any part of
|
|
||||||
it. (Additional permissions may be written to require their own
|
|
||||||
removal in certain cases when you modify the work.) You may place
|
|
||||||
additional permissions on material, added by you to a covered work,
|
|
||||||
for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
|
||||||
that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the
|
|
||||||
terms of sections 15 and 16 of this License; or
|
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or
|
|
||||||
author attributions in that material or in the Appropriate Legal
|
|
||||||
Notices displayed by works containing it; or
|
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or
|
|
||||||
requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or
|
|
||||||
authors of the material; or
|
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some
|
|
||||||
trade names, trademarks, or service marks; or
|
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that
|
|
||||||
material by anyone who conveys the material (or modified versions of
|
|
||||||
it) with contractual assumptions of liability to the recipient, for
|
|
||||||
any liability that these contractual assumptions directly impose on
|
|
||||||
those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
|
||||||
received it, or any part of it, contains a notice stating that it is
|
|
||||||
governed by this License along with a term that is a further
|
|
||||||
restriction, you may remove that term. If a license document contains
|
|
||||||
a further restriction but permits relicensing or conveying under this
|
|
||||||
License, you may add to a covered work material governed by the terms
|
|
||||||
of that license document, provided that the further restriction does
|
|
||||||
not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
|
||||||
must place, in the relevant source files, a statement of the
|
|
||||||
additional terms that apply to those files, or a notice indicating
|
|
||||||
where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
|
||||||
form of a separately written license, or stated as exceptions;
|
|
||||||
the above requirements apply either way.
|
|
||||||
|
|
||||||
8. Termination.
|
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
|
||||||
modify it is void, and will automatically terminate your rights under
|
|
||||||
this License (including any patent licenses granted under the third
|
|
||||||
paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
|
||||||
license from a particular copyright holder is reinstated (a)
|
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
|
||||||
holder fails to notify you of the violation by some reasonable means
|
|
||||||
prior to 60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
|
||||||
violation by some reasonable means, this is the first time you have
|
|
||||||
received notice of violation of this License (for any work) from that
|
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
|
||||||
your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
|
||||||
licenses of parties who have received copies or rights from you under
|
|
||||||
this License. If your rights have been terminated and not permanently
|
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
|
||||||
material under section 10.
|
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
|
||||||
run a copy of the Program. Ancillary propagation of a covered work
|
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
|
||||||
to receive a copy likewise does not require acceptance. However,
|
|
||||||
nothing other than this License grants you permission to propagate or
|
|
||||||
modify any covered work. These actions infringe copyright if you do
|
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
|
||||||
receives a license from the original licensors, to run, modify and
|
|
||||||
propagate that work, subject to this License. You are not responsible
|
|
||||||
for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
|
||||||
organization, or substantially all assets of one, or subdividing an
|
|
||||||
organization, or merging organizations. If propagation of a covered
|
|
||||||
work results from an entity transaction, each party to that
|
|
||||||
transaction who receives a copy of the work also receives whatever
|
|
||||||
licenses to the work the party's predecessor in interest had or could
|
|
||||||
give under the previous paragraph, plus a right to possession of the
|
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
|
||||||
rights granted or affirmed under this License. For example, you may
|
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
|
||||||
rights granted under this License, and you may not initiate litigation
|
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
|
||||||
sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
11. Patents.
|
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
|
||||||
License of the Program or a work on which the Program is based. The
|
|
||||||
work thus licensed is called the contributor's "contributor version".
|
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
|
||||||
owned or controlled by the contributor, whether already acquired or
|
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
|
||||||
by this License, of making, using, or selling its contributor version,
|
|
||||||
but do not include claims that would be infringed only as a
|
|
||||||
consequence of further modification of the contributor version. For
|
|
||||||
purposes of this definition, "control" includes the right to grant
|
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
|
||||||
this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
patent license under the contributor's essential patent claims, to
|
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
|
||||||
propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
|
||||||
(such as an express permission to practice a patent or covenant not to
|
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
|
||||||
party means to make such an agreement or commitment not to enforce a
|
|
||||||
patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
|
||||||
and the Corresponding Source of the work is not available for anyone
|
|
||||||
to copy, free of charge and under the terms of this License, through a
|
|
||||||
publicly available network server or other readily accessible means,
|
|
||||||
then you must either (1) cause the Corresponding Source to be so
|
|
||||||
available, or (2) arrange to deprive yourself of the benefit of the
|
|
||||||
patent license for this particular work, or (3) arrange, in a manner
|
|
||||||
consistent with the requirements of this License, to extend the patent
|
|
||||||
license to downstream recipients. "Knowingly relying" means you have
|
|
||||||
actual knowledge that, but for the patent license, your conveying the
|
|
||||||
covered work in a country, or your recipient's use of the covered work
|
|
||||||
in a country, would infringe one or more identifiable patents in that
|
|
||||||
country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
|
||||||
covered work, and grant a patent license to some of the parties
|
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
|
||||||
or convey a specific copy of the covered work, then the patent license
|
|
||||||
you grant is automatically extended to all recipients of the covered
|
|
||||||
work and works based on it.
|
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
|
||||||
conditioned on the non-exercise of one or more of the rights that are
|
|
||||||
specifically granted under this License. You may not convey a covered
|
|
||||||
work if you are a party to an arrangement with a third party that is
|
|
||||||
in the business of distributing software, under which you make payment
|
|
||||||
to the third party based on the extent of your activity of conveying
|
|
||||||
the work, and under which the third party grants, to any of the
|
|
||||||
parties who would receive the covered work from you, a discriminatory
|
|
||||||
patent license (a) in connection with copies of the covered work
|
|
||||||
conveyed by you (or copies made from those copies), or (b) primarily
|
|
||||||
for and in connection with specific products or compilations that
|
|
||||||
contain the covered work, unless you entered into that arrangement,
|
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
|
||||||
any implied license or other defenses to infringement that may
|
|
||||||
otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you may
|
|
||||||
not convey it at all. For example, if you agree to terms that obligate you
|
|
||||||
to collect a royalty for further conveying from those to whom you convey
|
|
||||||
the Program, the only way you could satisfy both those terms and this
|
|
||||||
License would be to refrain entirely from conveying the Program.
|
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
|
||||||
under version 3 of the GNU Affero General Public License into a single
|
|
||||||
combined work, and to convey the resulting work. The terms of this
|
|
||||||
License will continue to apply to the part which is the covered work,
|
|
||||||
but the special requirements of the GNU Affero General Public License,
|
|
||||||
section 13, concerning interaction through a network will apply to the
|
|
||||||
combination as such.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
|
||||||
the GNU General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
|
||||||
Program specifies that a certain numbered version of the GNU General
|
|
||||||
Public License "or any later version" applies to it, you have the
|
|
||||||
option of following the terms and conditions either of that numbered
|
|
||||||
version or of any later version published by the Free Software
|
|
||||||
Foundation. If the Program does not specify a version number of the
|
|
||||||
GNU General Public License, you may choose any version ever published
|
|
||||||
by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
|
||||||
versions of the GNU General Public License can be used, that proxy's
|
|
||||||
public statement of acceptance of a version permanently authorizes you
|
|
||||||
to choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
|
||||||
permissions. However, no additional obligations are imposed on any
|
|
||||||
author or copyright holder as a result of your choosing to follow a
|
|
||||||
later version.
|
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
|
||||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. Limitation of Liability.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
|
||||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
|
||||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
|
||||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
|
||||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
|
||||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|
||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGES.
|
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
|
||||||
above cannot be given local legal effect according to their terms,
|
|
||||||
reviewing courts shall apply local law that most closely approximates
|
|
||||||
an absolute waiver of all civil liability in connection with the
|
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
|
||||||
copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
state the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
|
||||||
notice like this when it starts in an interactive mode:
|
|
||||||
|
|
||||||
<program> Copyright (C) <year> <name of author>
|
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, your program's commands
|
|
||||||
might be different; for a GUI interface, you would use an "about box".
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
||||||
For more information on this, and how to apply and follow the GNU GPL, see
|
|
||||||
<https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your program
|
|
||||||
into proprietary programs. If your program is a subroutine library, you
|
|
||||||
may consider it more useful to permit linking proprietary applications with
|
|
||||||
the library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License. But first, please read
|
|
||||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
|
@ -10,11 +10,11 @@ It's user-friendly, easy to grasp, and easy to implement.
|
||||||
Building is done via CMake:
|
Building is done via CMake:
|
||||||
```sh
|
```sh
|
||||||
cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build
|
cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build
|
||||||
cmake --build ./build --config Release --target hyprlang -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
|
cmake --build ./build --config Release --target hyprlang -j`nproc 2>/dev/null || getconf _NPROCESSORS_CONF`
|
||||||
```
|
```
|
||||||
Install with:
|
Install with:
|
||||||
```sh
|
```sh
|
||||||
cmake --install ./build
|
sudo cmake --install ./build
|
||||||
```
|
```
|
||||||
|
|
||||||
## Example config
|
## Example config
|
||||||
|
@ -54,4 +54,4 @@ Visit [hyprland.org/hyprlang](https://hyprland.org/hyprlang) to see the document
|
||||||
|
|
||||||
### Example implementation
|
### Example implementation
|
||||||
|
|
||||||
For an example implmentation, take a look at the `tests/` directory.
|
For an example implementation, take a look at the `tests/` directory.
|
||||||
|
|
1
VERSION
Normal file
1
VERSION
Normal file
|
@ -0,0 +1 @@
|
||||||
|
0.6.3
|
30
flake.lock
30
flake.lock
|
@ -1,12 +1,35 @@
|
||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
|
"hyprutils": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
],
|
||||||
|
"systems": [
|
||||||
|
"systems"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1746635225,
|
||||||
|
"narHash": "sha256-W9G9bb0zRYDBRseHbVez0J8qVpD5QbizX67H/vsudhM=",
|
||||||
|
"owner": "hyprwm",
|
||||||
|
"repo": "hyprutils",
|
||||||
|
"rev": "674ea57373f08b7609ce93baff131117a0dfe70d",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "hyprwm",
|
||||||
|
"repo": "hyprutils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1708475490,
|
"lastModified": 1746461020,
|
||||||
"narHash": "sha256-g1v0TsWBQPX97ziznfJdWhgMyMGtoBFs102xSYO4syU=",
|
"narHash": "sha256-7+pG1I9jvxNlmln4YgnlW4o+w0TZX24k688mibiFDUE=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "0e74ca98a74bc7270d28838369593635a5db3260",
|
"rev": "3730d8a308f94996a9ba7c7138ede69c1b9ac4ae",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -18,6 +41,7 @@
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
|
"hyprutils": "hyprutils",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"systems": "systems"
|
"systems": "systems"
|
||||||
}
|
}
|
||||||
|
|
28
flake.nix
28
flake.nix
|
@ -4,13 +4,20 @@
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
systems.url = "github:nix-systems/default-linux";
|
systems.url = "github:nix-systems/default-linux";
|
||||||
|
|
||||||
|
hyprutils = {
|
||||||
|
url = "github:hyprwm/hyprutils";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
inputs.systems.follows = "systems";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = {
|
outputs = {
|
||||||
self,
|
self,
|
||||||
nixpkgs,
|
nixpkgs,
|
||||||
systems,
|
systems,
|
||||||
}: let
|
...
|
||||||
|
} @ inputs: let
|
||||||
inherit (nixpkgs) lib;
|
inherit (nixpkgs) lib;
|
||||||
eachSystem = lib.genAttrs (import systems);
|
eachSystem = lib.genAttrs (import systems);
|
||||||
pkgsFor = eachSystem (system:
|
pkgsFor = eachSystem (system:
|
||||||
|
@ -23,16 +30,21 @@
|
||||||
(builtins.substring 4 2 longDate)
|
(builtins.substring 4 2 longDate)
|
||||||
(builtins.substring 6 2 longDate)
|
(builtins.substring 6 2 longDate)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
version = lib.removeSuffix "\n" (builtins.readFile ./VERSION);
|
||||||
in {
|
in {
|
||||||
overlays = {
|
overlays = {
|
||||||
default = self.overlays.hyprlang;
|
default = self.overlays.hyprlang;
|
||||||
hyprlang = final: prev: {
|
hyprlang = lib.composeManyExtensions [
|
||||||
hyprlang = final.callPackage ./nix/default.nix {
|
inputs.hyprutils.overlays.default
|
||||||
stdenv = final.gcc13Stdenv;
|
(final: prev: {
|
||||||
version = "0.pre" + "+date=" + (mkDate (self.lastModifiedDate or "19700101")) + "_" + (self.shortRev or "dirty");
|
hyprlang = final.callPackage ./nix/default.nix {
|
||||||
};
|
stdenv = final.gcc14Stdenv;
|
||||||
hyprlang-with-tests = final.hyprlang.override {doCheck = true;};
|
version = version + "+date=" + (mkDate (self.lastModifiedDate or "19700101")) + "_" + (self.shortRev or "dirty");
|
||||||
};
|
};
|
||||||
|
hyprlang-with-tests = final.hyprlang.override {doCheck = true;};
|
||||||
|
})
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
packages = eachSystem (system: {
|
packages = eachSystem (system: {
|
||||||
|
|
|
@ -3,16 +3,20 @@
|
||||||
#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>
|
||||||
|
|
||||||
class CConfigImpl;
|
class CConfigImpl;
|
||||||
struct SConfigDefaultValue;
|
struct SConfigDefaultValue;
|
||||||
struct SSpecialCategory;
|
struct SSpecialCategory;
|
||||||
|
|
||||||
|
#define HYPRLANG_END_MAGIC 0x1337BEEF
|
||||||
|
|
||||||
namespace Hyprlang {
|
namespace Hyprlang {
|
||||||
|
|
||||||
struct SVector2D;
|
struct SVector2D;
|
||||||
|
@ -94,26 +98,42 @@ namespace Hyprlang {
|
||||||
/*!
|
/*!
|
||||||
Don't throw errors on missing values.
|
Don't throw errors on missing values.
|
||||||
*/
|
*/
|
||||||
bool verifyOnly = false;
|
int verifyOnly = false;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Return all errors instead of just the first
|
Return all errors instead of just the first
|
||||||
*/
|
*/
|
||||||
bool throwAllErrors = false;
|
int throwAllErrors = false;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\since 0.2.0
|
\since 0.2.0
|
||||||
|
|
||||||
Don't throw on a missing config file. Carry on as if nothing happened.
|
Don't throw on a missing config file. Carry on as if nothing happened.
|
||||||
*/
|
*/
|
||||||
bool allowMissingConfig = false;
|
int allowMissingConfig = false;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\since 0.4.2
|
||||||
|
|
||||||
|
Treat configPath as a raw config stream.
|
||||||
|
*/
|
||||||
|
int pathIsStream = false;
|
||||||
|
|
||||||
|
// INTERNAL: DO NOT MODIFY
|
||||||
|
int __internal_struct_end = HYPRLANG_END_MAGIC;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Generic struct for options for handlers
|
Generic struct for options for handlers
|
||||||
*/
|
*/
|
||||||
struct SHandlerOptions {
|
struct SHandlerOptions {
|
||||||
|
/*!
|
||||||
|
Allow flags for this handler
|
||||||
|
*/
|
||||||
bool allowFlags = false;
|
bool allowFlags = false;
|
||||||
|
|
||||||
|
// INTERNAL: DO NOT MODIFY
|
||||||
|
int __internal_struct_end = HYPRLANG_END_MAGIC;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -130,7 +150,7 @@ namespace Hyprlang {
|
||||||
/*!
|
/*!
|
||||||
don't pop up an error if the config value is missing
|
don't pop up an error if the config value is missing
|
||||||
*/
|
*/
|
||||||
bool ignoreMissing = false;
|
int ignoreMissing = false;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Make this category an anonymous special one.
|
Make this category an anonymous special one.
|
||||||
|
@ -141,7 +161,10 @@ namespace Hyprlang {
|
||||||
|
|
||||||
\since 0.4.0
|
\since 0.4.0
|
||||||
*/
|
*/
|
||||||
bool anonymousKeyBased = false;
|
int anonymousKeyBased = false;
|
||||||
|
|
||||||
|
// INTERNAL: DO NOT MODIFY
|
||||||
|
int __internal_struct_end = HYPRLANG_END_MAGIC;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -231,7 +254,7 @@ namespace Hyprlang {
|
||||||
/*!
|
/*!
|
||||||
Get the contained value as an std::any.
|
Get the contained value as an std::any.
|
||||||
For strings, this is a const char*.
|
For strings, this is a const char*.
|
||||||
For custom data types, this is a CConfigCustomValueType*.
|
For custom data types, this is a void* representing the data ptr stored by it.
|
||||||
*/
|
*/
|
||||||
std::any getValue() const {
|
std::any getValue() const {
|
||||||
switch (m_eType) {
|
switch (m_eType) {
|
||||||
|
@ -429,6 +452,93 @@ namespace Hyprlang {
|
||||||
void clearState();
|
void clearState();
|
||||||
void applyDefaultsToCat(SSpecialCategory& cat);
|
void applyDefaultsToCat(SSpecialCategory& cat);
|
||||||
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);
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
/*!
|
||||||
|
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
|
||||||
|
#undef HYPRLANG_END_MAGIC
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -2,6 +2,8 @@
|
||||||
lib,
|
lib,
|
||||||
stdenv,
|
stdenv,
|
||||||
cmake,
|
cmake,
|
||||||
|
hyprutils,
|
||||||
|
pkg-config,
|
||||||
version ? "git",
|
version ? "git",
|
||||||
doCheck ? false,
|
doCheck ? false,
|
||||||
}:
|
}:
|
||||||
|
@ -10,14 +12,19 @@ stdenv.mkDerivation {
|
||||||
inherit version doCheck;
|
inherit version doCheck;
|
||||||
src = ../.;
|
src = ../.;
|
||||||
|
|
||||||
nativeBuildInputs = [cmake];
|
nativeBuildInputs = [
|
||||||
|
cmake
|
||||||
|
pkg-config
|
||||||
|
];
|
||||||
|
|
||||||
|
buildInputs = [hyprutils];
|
||||||
|
|
||||||
outputs = ["out" "dev"];
|
outputs = ["out" "dev"];
|
||||||
|
|
||||||
meta = with lib; {
|
meta = with lib; {
|
||||||
homepage = "https://github.com/hyprwm/hyprlang";
|
homepage = "https://github.com/hyprwm/hyprlang";
|
||||||
description = "The official implementation library for the hypr config language";
|
description = "The official implementation library for the hypr config language";
|
||||||
license = licenses.gpl3Plus;
|
license = licenses.lgpl3Only;
|
||||||
platforms = platforms.linux;
|
platforms = platforms.linux;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "public.hpp"
|
#include "public.hpp"
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include <string.h>
|
#include <cstring>
|
||||||
|
|
||||||
using namespace Hyprlang;
|
using namespace Hyprlang;
|
||||||
|
|
||||||
|
@ -30,38 +30,28 @@ CConfigValue::~CConfigValue() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CConfigValue::CConfigValue(const int64_t value) {
|
CConfigValue::CConfigValue(const int64_t value) : m_eType(CONFIGDATATYPE_INT), m_pData(new int64_t) {
|
||||||
m_pData = new int64_t;
|
|
||||||
*reinterpret_cast<int64_t*>(m_pData) = value;
|
*reinterpret_cast<int64_t*>(m_pData) = value;
|
||||||
m_eType = CONFIGDATATYPE_INT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CConfigValue::CConfigValue(const float value) {
|
CConfigValue::CConfigValue(const float value) : m_eType(CONFIGDATATYPE_FLOAT), m_pData(new float) {
|
||||||
m_pData = new float;
|
|
||||||
*reinterpret_cast<float*>(m_pData) = value;
|
*reinterpret_cast<float*>(m_pData) = value;
|
||||||
m_eType = CONFIGDATATYPE_FLOAT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CConfigValue::CConfigValue(const SVector2D value) {
|
CConfigValue::CConfigValue(const SVector2D value) : m_eType(CONFIGDATATYPE_VEC2), m_pData(new SVector2D) {
|
||||||
m_pData = new SVector2D;
|
|
||||||
*reinterpret_cast<SVector2D*>(m_pData) = value;
|
*reinterpret_cast<SVector2D*>(m_pData) = value;
|
||||||
m_eType = CONFIGDATATYPE_VEC2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CConfigValue::CConfigValue(const char* value) {
|
CConfigValue::CConfigValue(const char* value) : m_eType(CONFIGDATATYPE_STR), m_pData(new char[strlen(value) + 1]) {
|
||||||
m_pData = new char[strlen(value) + 1];
|
|
||||||
strncpy((char*)m_pData, value, strlen(value));
|
strncpy((char*)m_pData, value, strlen(value));
|
||||||
((char*)m_pData)[strlen(value)] = '\0';
|
((char*)m_pData)[strlen(value)] = '\0';
|
||||||
m_eType = CONFIGDATATYPE_STR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CConfigValue::CConfigValue(CConfigCustomValueType&& value) {
|
CConfigValue::CConfigValue(CConfigCustomValueType&& value) : m_eType(CONFIGDATATYPE_CUSTOM), m_pData(new CConfigCustomValueType(value)) {
|
||||||
m_pData = new CConfigCustomValueType(value);
|
;
|
||||||
m_eType = CONFIGDATATYPE_CUSTOM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CConfigValue::CConfigValue(const CConfigValue& other) {
|
CConfigValue::CConfigValue(const CConfigValue& other) : m_eType(other.m_eType) {
|
||||||
m_eType = other.m_eType;
|
|
||||||
setFrom(&other);
|
setFrom(&other);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,11 +67,9 @@ void* const* CConfigValue::getDataStaticPtr() const {
|
||||||
return &m_pData;
|
return &m_pData;
|
||||||
}
|
}
|
||||||
|
|
||||||
CConfigCustomValueType::CConfigCustomValueType(PCONFIGCUSTOMVALUEHANDLERFUNC handler_, PCONFIGCUSTOMVALUEDESTRUCTOR dtor_, const char* def) {
|
CConfigCustomValueType::CConfigCustomValueType(PCONFIGCUSTOMVALUEHANDLERFUNC handler_, PCONFIGCUSTOMVALUEDESTRUCTOR dtor_, const char* def) :
|
||||||
handler = handler_;
|
handler(handler_), dtor(dtor_), defaultVal(def), lastVal(def) {
|
||||||
dtor = dtor_;
|
;
|
||||||
defaultVal = def;
|
|
||||||
lastVal = def;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CConfigCustomValueType::~CConfigCustomValueType() {
|
CConfigCustomValueType::~CConfigCustomValueType() {
|
||||||
|
|
517
src/config.cpp
517
src/config.cpp
|
@ -1,43 +1,77 @@
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
|
#include <exception>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <expected>
|
#include <expected>
|
||||||
|
#include <sstream>
|
||||||
|
#include <cstring>
|
||||||
|
#include <hyprutils/string/VarList.hpp>
|
||||||
|
#include <hyprutils/string/String.hpp>
|
||||||
|
#include <hyprutils/string/ConstVarList.hpp>
|
||||||
|
|
||||||
using namespace Hyprlang;
|
using namespace Hyprlang;
|
||||||
|
using namespace Hyprutils::String;
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <crt_externs.h>
|
||||||
|
#define environ (*_NSGetEnviron())
|
||||||
|
#else
|
||||||
|
// NOLINTNEXTLINE
|
||||||
extern "C" char** environ;
|
extern "C" char** environ;
|
||||||
|
#endif
|
||||||
|
|
||||||
// defines
|
// defines
|
||||||
inline constexpr const char* ANONYMOUS_KEY = "__hyprlang_internal_anonymous_key";
|
inline constexpr const char* ANONYMOUS_KEY = "__hyprlang_internal_anonymous_key";
|
||||||
|
inline constexpr const char* MULTILINE_SPACE_CHARSET = " \t";
|
||||||
//
|
//
|
||||||
|
|
||||||
static std::string removeBeginEndSpacesTabs(std::string str) {
|
static size_t seekABIStructSize(const void* begin, size_t startOffset, size_t maxSize) {
|
||||||
if (str.empty())
|
for (size_t off = startOffset; off < maxSize; off += 4) {
|
||||||
return str;
|
if (*(int*)((unsigned char*)begin + off) == HYPRLANG_END_MAGIC)
|
||||||
|
return off;
|
||||||
int countBefore = 0;
|
|
||||||
while (str[countBefore] == ' ' || str[countBefore] == '\t') {
|
|
||||||
countBefore++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int countAfter = 0;
|
return 0;
|
||||||
while ((int)str.length() - countAfter - 1 >= 0 && (str[str.length() - countAfter - 1] == ' ' || str[str.length() - 1 - countAfter] == '\t')) {
|
|
||||||
countAfter++;
|
|
||||||
}
|
|
||||||
|
|
||||||
str = str.substr(countBefore, str.length() - countBefore - countAfter);
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CConfig::CConfig(const char* path, const Hyprlang::SConfigOptions& options) {
|
static std::expected<std::string, eGetNextLineFailure> getNextLine(std::istream& str, int& rawLineNum, int& lineNum) {
|
||||||
impl = new CConfigImpl;
|
std::string line = "";
|
||||||
impl->path = path;
|
std::string nextLine = "";
|
||||||
|
|
||||||
if (!std::filesystem::exists(impl->path)) {
|
if (!std::getline(str, line))
|
||||||
|
return std::unexpected(GETNEXTLINEFAILURE_EOF);
|
||||||
|
|
||||||
|
lineNum = ++rawLineNum;
|
||||||
|
|
||||||
|
while (line.length() > 0 && line.at(line.length() - 1) == '\\') {
|
||||||
|
const auto lastNonSpace = line.length() < 2 ? -1 : line.find_last_not_of(MULTILINE_SPACE_CHARSET, line.length() - 2);
|
||||||
|
line = line.substr(0, lastNonSpace + 1);
|
||||||
|
|
||||||
|
if (!std::getline(str, nextLine))
|
||||||
|
return std::unexpected(GETNEXTLINEFAILURE_BACKSLASH);
|
||||||
|
|
||||||
|
++rawLineNum;
|
||||||
|
line += nextLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
CConfig::CConfig(const char* path, const Hyprlang::SConfigOptions& options_) : impl(new CConfigImpl) {
|
||||||
|
SConfigOptions options;
|
||||||
|
std::memcpy(&options, &options_, seekABIStructSize(&options_, 16, sizeof(SConfigOptions)));
|
||||||
|
|
||||||
|
if (options.pathIsStream)
|
||||||
|
impl->rawConfigString = path;
|
||||||
|
else
|
||||||
|
impl->path = path;
|
||||||
|
|
||||||
|
if (!options.pathIsStream && !std::filesystem::exists(impl->path)) {
|
||||||
if (!options.allowMissingConfig)
|
if (!options.allowMissingConfig)
|
||||||
throw "File does not exist";
|
throw "File does not exist";
|
||||||
}
|
}
|
||||||
|
@ -50,7 +84,7 @@ CConfig::CConfig(const char* path, const Hyprlang::SConfigOptions& options) {
|
||||||
impl->envVariables.push_back({VARIABLE, VALUE});
|
impl->envVariables.push_back({VARIABLE, VALUE});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort(impl->envVariables.begin(), impl->envVariables.end(), [&](const auto& a, const auto& b) { return a.name.length() > b.name.length(); });
|
std::ranges::sort(impl->envVariables, [&](const auto& a, const auto& b) { return a.name.length() > b.name.length(); });
|
||||||
|
|
||||||
impl->configOptions = options;
|
impl->configOptions = options;
|
||||||
}
|
}
|
||||||
|
@ -64,40 +98,42 @@ void CConfig::addConfigValue(const char* name, const CConfigValue& value) {
|
||||||
throw "Cannot addConfigValue after commence()";
|
throw "Cannot addConfigValue after commence()";
|
||||||
|
|
||||||
if ((eDataType)value.m_eType != CONFIGDATATYPE_CUSTOM && (eDataType)value.m_eType != CONFIGDATATYPE_STR)
|
if ((eDataType)value.m_eType != CONFIGDATATYPE_CUSTOM && (eDataType)value.m_eType != CONFIGDATATYPE_STR)
|
||||||
impl->defaultValues.emplace(name, SConfigDefaultValue{value.getValue(), (eDataType)value.m_eType});
|
impl->defaultValues.emplace(name, SConfigDefaultValue{.data = value.getValue(), .type = (eDataType)value.m_eType});
|
||||||
else if ((eDataType)value.m_eType == CONFIGDATATYPE_STR)
|
else if ((eDataType)value.m_eType == CONFIGDATATYPE_STR)
|
||||||
impl->defaultValues.emplace(name, SConfigDefaultValue{std::string{std::any_cast<const char*>(value.getValue())}, (eDataType)value.m_eType});
|
impl->defaultValues.emplace(name, SConfigDefaultValue{.data = std::string{std::any_cast<const char*>(value.getValue())}, .type = (eDataType)value.m_eType});
|
||||||
else
|
else
|
||||||
impl->defaultValues.emplace(name,
|
impl->defaultValues.emplace(name,
|
||||||
SConfigDefaultValue{reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->defaultVal, (eDataType)value.m_eType,
|
SConfigDefaultValue{.data = reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->defaultVal,
|
||||||
reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->handler,
|
.type = (eDataType)value.m_eType,
|
||||||
reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->dtor});
|
.handler = reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->handler,
|
||||||
|
.dtor = reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->dtor});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfig::addSpecialConfigValue(const char* cat, const char* name, const CConfigValue& value) {
|
void CConfig::addSpecialConfigValue(const char* cat, const char* name, const CConfigValue& value) {
|
||||||
const auto IT = std::find_if(impl->specialCategoryDescriptors.begin(), impl->specialCategoryDescriptors.end(), [&](const auto& other) { return other->name == cat; });
|
const auto IT = std::ranges::find_if(impl->specialCategoryDescriptors, [&](const auto& other) { return other->name == cat; });
|
||||||
|
|
||||||
if (IT == impl->specialCategoryDescriptors.end())
|
if (IT == impl->specialCategoryDescriptors.end())
|
||||||
throw "No such category";
|
throw "No such category";
|
||||||
|
|
||||||
if ((eDataType)value.m_eType != CONFIGDATATYPE_CUSTOM && (eDataType)value.m_eType != CONFIGDATATYPE_STR)
|
if ((eDataType)value.m_eType != CONFIGDATATYPE_CUSTOM && (eDataType)value.m_eType != CONFIGDATATYPE_STR)
|
||||||
IT->get()->defaultValues.emplace(name, SConfigDefaultValue{value.getValue(), (eDataType)value.m_eType});
|
IT->get()->defaultValues.emplace(name, SConfigDefaultValue{.data = value.getValue(), .type = (eDataType)value.m_eType});
|
||||||
else if ((eDataType)value.m_eType == CONFIGDATATYPE_STR)
|
else if ((eDataType)value.m_eType == CONFIGDATATYPE_STR)
|
||||||
IT->get()->defaultValues.emplace(name, SConfigDefaultValue{std::string{std::any_cast<const char*>(value.getValue())}, (eDataType)value.m_eType});
|
IT->get()->defaultValues.emplace(name, SConfigDefaultValue{.data = std::string{std::any_cast<const char*>(value.getValue())}, .type = (eDataType)value.m_eType});
|
||||||
else
|
else
|
||||||
IT->get()->defaultValues.emplace(name,
|
IT->get()->defaultValues.emplace(name,
|
||||||
SConfigDefaultValue{reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->defaultVal, (eDataType)value.m_eType,
|
SConfigDefaultValue{.data = reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->defaultVal,
|
||||||
reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->handler,
|
.type = (eDataType)value.m_eType,
|
||||||
reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->dtor});
|
.handler = reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->handler,
|
||||||
|
.dtor = reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->dtor});
|
||||||
|
|
||||||
const auto CAT = std::find_if(impl->specialCategories.begin(), impl->specialCategories.end(), [cat, name](const auto& other) { return other->name == cat && other->isStatic; });
|
const auto CAT = std::ranges::find_if(impl->specialCategories, [cat](const auto& other) { return other->name == cat && other->isStatic; });
|
||||||
|
|
||||||
if (CAT != impl->specialCategories.end())
|
if (CAT != impl->specialCategories.end())
|
||||||
CAT->get()->values[name].defaultFrom(IT->get()->defaultValues[name]);
|
CAT->get()->values[name].defaultFrom(IT->get()->defaultValues[name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfig::removeSpecialConfigValue(const char* cat, const char* name) {
|
void CConfig::removeSpecialConfigValue(const char* cat, const char* name) {
|
||||||
const auto IT = std::find_if(impl->specialCategoryDescriptors.begin(), impl->specialCategoryDescriptors.end(), [&](const auto& other) { return other->name == cat; });
|
const auto IT = std::ranges::find_if(impl->specialCategoryDescriptors, [&](const auto& other) { return other->name == cat; });
|
||||||
|
|
||||||
if (IT == impl->specialCategoryDescriptors.end())
|
if (IT == impl->specialCategoryDescriptors.end())
|
||||||
throw "No such category";
|
throw "No such category";
|
||||||
|
@ -105,7 +141,10 @@ void CConfig::removeSpecialConfigValue(const char* cat, const char* name) {
|
||||||
std::erase_if(IT->get()->defaultValues, [name](const auto& other) { return other.first == name; });
|
std::erase_if(IT->get()->defaultValues, [name](const auto& other) { return other.first == name; });
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfig::addSpecialCategory(const char* name, SSpecialCategoryOptions options) {
|
void CConfig::addSpecialCategory(const char* name, SSpecialCategoryOptions options_) {
|
||||||
|
SSpecialCategoryOptions options;
|
||||||
|
std::memcpy(&options, &options_, seekABIStructSize(&options_, 8, sizeof(SSpecialCategoryOptions)));
|
||||||
|
|
||||||
const auto PDESC = impl->specialCategoryDescriptors.emplace_back(std::make_unique<SSpecialCategoryDescriptor>()).get();
|
const auto PDESC = impl->specialCategoryDescriptors.emplace_back(std::make_unique<SSpecialCategoryDescriptor>()).get();
|
||||||
PDESC->name = name;
|
PDESC->name = name;
|
||||||
PDESC->key = options.key ? options.key : "";
|
PDESC->key = options.key ? options.key : "";
|
||||||
|
@ -125,9 +164,8 @@ void CConfig::addSpecialCategory(const char* name, SSpecialCategoryOptions optio
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort longest to shortest
|
// sort longest to shortest
|
||||||
std::sort(impl->specialCategories.begin(), impl->specialCategories.end(), [](const auto& a, const auto& b) -> int { return a->name.length() > b->name.length(); });
|
std::ranges::sort(impl->specialCategories, [](const auto& a, const auto& b) -> int { return a->name.length() > b->name.length(); });
|
||||||
std::sort(impl->specialCategoryDescriptors.begin(), impl->specialCategoryDescriptors.end(),
|
std::ranges::sort(impl->specialCategoryDescriptors, [](const auto& a, const auto& b) -> int { return a->name.length() > b->name.length(); });
|
||||||
[](const auto& a, const auto& b) -> int { return a->name.length() > b->name.length(); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfig::removeSpecialCategory(const char* name) {
|
void CConfig::removeSpecialCategory(const char* name) {
|
||||||
|
@ -148,98 +186,77 @@ void CConfig::commence() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isNumber(const std::string& str, bool allowfloat) {
|
|
||||||
|
|
||||||
std::string copy = str;
|
|
||||||
if (*copy.begin() == '-')
|
|
||||||
copy = copy.substr(1);
|
|
||||||
|
|
||||||
if (copy.empty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
bool point = !allowfloat;
|
|
||||||
for (auto& c : copy) {
|
|
||||||
if (c == '.') {
|
|
||||||
if (point)
|
|
||||||
return false;
|
|
||||||
point = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!std::isdigit(c))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void replaceAll(std::string& str, const std::string& from, const std::string& to) {
|
|
||||||
if (from.empty())
|
|
||||||
return;
|
|
||||||
size_t pos = 0;
|
|
||||||
while ((pos = str.find(from, pos)) != std::string::npos) {
|
|
||||||
str.replace(pos, from.length(), to);
|
|
||||||
pos += to.length();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::expected<int64_t, std::string> configStringToInt(const std::string& VALUE) {
|
static std::expected<int64_t, std::string> configStringToInt(const std::string& VALUE) {
|
||||||
|
auto parseHex = [](const std::string& value) -> std::expected<int64_t, std::string> {
|
||||||
|
try {
|
||||||
|
size_t position;
|
||||||
|
auto result = stoll(value, &position, 16);
|
||||||
|
if (position == value.size())
|
||||||
|
return result;
|
||||||
|
} catch (const std::exception&) {}
|
||||||
|
return std::unexpected("invalid hex " + value);
|
||||||
|
};
|
||||||
if (VALUE.starts_with("0x")) {
|
if (VALUE.starts_with("0x")) {
|
||||||
// Values with 0x are hex
|
// Values with 0x are hex
|
||||||
const auto VALUEWITHOUTHEX = VALUE.substr(2);
|
return parseHex(VALUE);
|
||||||
return stoll(VALUEWITHOUTHEX, nullptr, 16);
|
|
||||||
} else if (VALUE.starts_with("rgba(") && VALUE.ends_with(')')) {
|
} else if (VALUE.starts_with("rgba(") && VALUE.ends_with(')')) {
|
||||||
const auto VALUEWITHOUTFUNC = removeBeginEndSpacesTabs(VALUE.substr(5, VALUE.length() - 6));
|
const auto VALUEWITHOUTFUNC = trim(VALUE.substr(5, VALUE.length() - 6));
|
||||||
|
|
||||||
// try doing it the comma way first
|
// try doing it the comma way first
|
||||||
if (std::count(VALUEWITHOUTFUNC.begin(), VALUEWITHOUTFUNC.end(), ',') == 3) {
|
if (std::count(VALUEWITHOUTFUNC.begin(), VALUEWITHOUTFUNC.end(), ',') == 3) {
|
||||||
// cool
|
// cool
|
||||||
std::string rolling = VALUEWITHOUTFUNC;
|
std::string rolling = VALUEWITHOUTFUNC;
|
||||||
auto r = configStringToInt(removeBeginEndSpacesTabs(rolling.substr(0, rolling.find(','))));
|
auto r = configStringToInt(trim(rolling.substr(0, rolling.find(','))));
|
||||||
rolling = rolling.substr(rolling.find(',') + 1);
|
rolling = rolling.substr(rolling.find(',') + 1);
|
||||||
auto g = configStringToInt(removeBeginEndSpacesTabs(rolling.substr(0, rolling.find(','))));
|
auto g = configStringToInt(trim(rolling.substr(0, rolling.find(','))));
|
||||||
rolling = rolling.substr(rolling.find(',') + 1);
|
rolling = rolling.substr(rolling.find(',') + 1);
|
||||||
auto b = configStringToInt(removeBeginEndSpacesTabs(rolling.substr(0, rolling.find(','))));
|
auto b = configStringToInt(trim(rolling.substr(0, rolling.find(','))));
|
||||||
rolling = rolling.substr(rolling.find(',') + 1);
|
rolling = rolling.substr(rolling.find(',') + 1);
|
||||||
uint8_t a = 0;
|
uint8_t a = 0;
|
||||||
try {
|
try {
|
||||||
a = std::round(std::stof(removeBeginEndSpacesTabs(rolling.substr(0, rolling.find(',')))) * 255.f);
|
a = std::round(std::stof(trim(rolling.substr(0, rolling.find(',')))) * 255.f);
|
||||||
} catch (std::exception& e) { return std::unexpected("failed parsing " + VALUEWITHOUTFUNC); }
|
} catch (std::exception& e) { return std::unexpected("failed parsing " + VALUEWITHOUTFUNC); }
|
||||||
|
|
||||||
if (!r.has_value() || !g.has_value() || !b.has_value())
|
if (!r.has_value() || !g.has_value() || !b.has_value())
|
||||||
return std::unexpected("failed parsing " + VALUEWITHOUTFUNC);
|
return std::unexpected("failed parsing " + VALUEWITHOUTFUNC);
|
||||||
|
|
||||||
return a * (Hyprlang::INT)0x1000000 + r.value() * (Hyprlang::INT)0x10000 + g.value() * (Hyprlang::INT)0x100 + b.value();
|
return (a * (Hyprlang::INT)0x1000000) + (r.value() * (Hyprlang::INT)0x10000) + (g.value() * (Hyprlang::INT)0x100) + b.value();
|
||||||
} else if (VALUEWITHOUTFUNC.length() == 8) {
|
} else if (VALUEWITHOUTFUNC.length() == 8) {
|
||||||
const auto RGBA = std::stoll(VALUEWITHOUTFUNC, nullptr, 16);
|
const auto RGBA = parseHex(VALUEWITHOUTFUNC);
|
||||||
|
|
||||||
|
if (!RGBA.has_value())
|
||||||
|
return RGBA;
|
||||||
|
|
||||||
// now we need to RGBA -> ARGB. The config holds ARGB only.
|
// now we need to RGBA -> ARGB. The config holds ARGB only.
|
||||||
return (RGBA >> 8) + 0x1000000 * (RGBA & 0xFF);
|
return (RGBA.value() >> 8) + (0x1000000 * (RGBA.value() & 0xFF));
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::unexpected("rgba() expects length of 8 characters (4 bytes) or 4 comma separated values");
|
return std::unexpected("rgba() expects length of 8 characters (4 bytes) or 4 comma separated values");
|
||||||
|
|
||||||
} else if (VALUE.starts_with("rgb(") && VALUE.ends_with(')')) {
|
} else if (VALUE.starts_with("rgb(") && VALUE.ends_with(')')) {
|
||||||
const auto VALUEWITHOUTFUNC = removeBeginEndSpacesTabs(VALUE.substr(4, VALUE.length() - 5));
|
const auto VALUEWITHOUTFUNC = trim(VALUE.substr(4, VALUE.length() - 5));
|
||||||
|
|
||||||
// try doing it the comma way first
|
// try doing it the comma way first
|
||||||
if (std::count(VALUEWITHOUTFUNC.begin(), VALUEWITHOUTFUNC.end(), ',') == 2) {
|
if (std::count(VALUEWITHOUTFUNC.begin(), VALUEWITHOUTFUNC.end(), ',') == 2) {
|
||||||
// cool
|
// cool
|
||||||
std::string rolling = VALUEWITHOUTFUNC;
|
std::string rolling = VALUEWITHOUTFUNC;
|
||||||
auto r = configStringToInt(removeBeginEndSpacesTabs(rolling.substr(0, rolling.find(','))));
|
auto r = configStringToInt(trim(rolling.substr(0, rolling.find(','))));
|
||||||
rolling = rolling.substr(rolling.find(',') + 1);
|
rolling = rolling.substr(rolling.find(',') + 1);
|
||||||
auto g = configStringToInt(removeBeginEndSpacesTabs(rolling.substr(0, rolling.find(','))));
|
auto g = configStringToInt(trim(rolling.substr(0, rolling.find(','))));
|
||||||
rolling = rolling.substr(rolling.find(',') + 1);
|
rolling = rolling.substr(rolling.find(',') + 1);
|
||||||
auto b = configStringToInt(removeBeginEndSpacesTabs(rolling.substr(0, rolling.find(','))));
|
auto b = configStringToInt(trim(rolling.substr(0, rolling.find(','))));
|
||||||
|
|
||||||
if (!r.has_value() || !g.has_value() || !b.has_value())
|
if (!r.has_value() || !g.has_value() || !b.has_value())
|
||||||
return std::unexpected("failed parsing " + VALUEWITHOUTFUNC);
|
return std::unexpected("failed parsing " + VALUEWITHOUTFUNC);
|
||||||
|
|
||||||
return (Hyprlang::INT)0xFF000000 + r.value() * (Hyprlang::INT)0x10000 + g.value() * (Hyprlang::INT)0x100 + b.value();
|
return (Hyprlang::INT)0xFF000000 + (r.value() * (Hyprlang::INT)0x10000) + (g.value() * (Hyprlang::INT)0x100) + b.value();
|
||||||
} else if (VALUEWITHOUTFUNC.length() == 6) {
|
} else if (VALUEWITHOUTFUNC.length() == 6) {
|
||||||
const auto RGB = std::stoll(VALUEWITHOUTFUNC, nullptr, 16);
|
const auto RGB = parseHex(VALUEWITHOUTFUNC);
|
||||||
|
|
||||||
return RGB + 0xFF000000;
|
if (!RGB.has_value())
|
||||||
|
return RGB;
|
||||||
|
|
||||||
|
return RGB.value() + 0xFF000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::unexpected("rgb() expects length of 6 characters (3 bytes) or 3 comma separated values");
|
return std::unexpected("rgb() expects length of 6 characters (3 bytes) or 3 comma separated values");
|
||||||
|
@ -264,15 +281,47 @@ CParseResult CConfig::configSetValueSafe(const std::string& command, const std::
|
||||||
CParseResult result;
|
CParseResult result;
|
||||||
|
|
||||||
std::string valueName;
|
std::string valueName;
|
||||||
|
std::string catPrefix;
|
||||||
for (auto& c : impl->categories) {
|
for (auto& c : impl->categories) {
|
||||||
valueName += c + ':';
|
valueName += c + ':';
|
||||||
|
catPrefix += c + ':';
|
||||||
}
|
}
|
||||||
|
|
||||||
valueName += command;
|
valueName += command;
|
||||||
|
|
||||||
const auto VALUEONLYNAME = valueName.contains(":") ? valueName.substr(valueName.find_last_of(':') + 1) : valueName;
|
const auto VALUEONLYNAME = command.starts_with(catPrefix) ? command.substr(catPrefix.length()) : command;
|
||||||
|
|
||||||
auto VALUEIT = impl->values.find(valueName);
|
// FIXME: this will bug with nested.
|
||||||
|
if (valueName.contains('[') && valueName.contains(']')) {
|
||||||
|
const auto L = valueName.find_first_of('[');
|
||||||
|
const auto R = valueName.find_last_of(']');
|
||||||
|
|
||||||
|
if (L < R) {
|
||||||
|
const auto CATKEY = valueName.substr(L + 1, R - L - 1);
|
||||||
|
impl->currentSpecialKey = CATKEY;
|
||||||
|
|
||||||
|
valueName = valueName.substr(0, L) + valueName.substr(R + 1);
|
||||||
|
|
||||||
|
// if it doesn't exist, make it
|
||||||
|
for (auto& sc : impl->specialCategoryDescriptors) {
|
||||||
|
if (sc->key.empty() || !valueName.starts_with(sc->name))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// bingo
|
||||||
|
const auto PCAT = impl->specialCategories.emplace_back(std::make_unique<SSpecialCategory>()).get();
|
||||||
|
PCAT->descriptor = sc.get();
|
||||||
|
PCAT->name = sc->name;
|
||||||
|
PCAT->key = sc->key;
|
||||||
|
addSpecialConfigValue(sc->name.c_str(), sc->key.c_str(), CConfigValue(CATKEY.c_str()));
|
||||||
|
|
||||||
|
applyDefaultsToCat(*PCAT);
|
||||||
|
|
||||||
|
PCAT->values[sc->key].setFrom(CATKEY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto VALUEIT = impl->values.find(valueName);
|
||||||
if (VALUEIT == impl->values.end()) {
|
if (VALUEIT == impl->values.end()) {
|
||||||
// it might be in a special category
|
// it might be in a special category
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
@ -333,8 +382,7 @@ CParseResult CConfig::configSetValueSafe(const std::string& command, const std::
|
||||||
// find suitable key
|
// find suitable key
|
||||||
size_t biggest = 0;
|
size_t biggest = 0;
|
||||||
for (auto& catt : impl->specialCategories) {
|
for (auto& catt : impl->specialCategories) {
|
||||||
if (catt->anonymousID > biggest)
|
biggest = std::max(catt->anonymousID, biggest);
|
||||||
biggest = catt->anonymousID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
biggest++;
|
biggest++;
|
||||||
|
@ -393,7 +441,7 @@ CParseResult CConfig::configSetValueSafe(const std::string& command, const std::
|
||||||
if (LHS.contains(" ") || RHS.contains(" "))
|
if (LHS.contains(" ") || RHS.contains(" "))
|
||||||
throw std::runtime_error("too many args");
|
throw std::runtime_error("too many args");
|
||||||
|
|
||||||
VALUEIT->second.setFrom(SVector2D{std::stof(LHS), std::stof(RHS)});
|
VALUEIT->second.setFrom(SVector2D{.x = std::stof(LHS), .y = std::stof(RHS)});
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
result.setError(std::format("failed parsing a vec2: {}", e.what()));
|
result.setError(std::format("failed parsing a vec2: {}", e.what()));
|
||||||
return result;
|
return result;
|
||||||
|
@ -427,14 +475,14 @@ CParseResult CConfig::configSetValueSafe(const std::string& command, const std::
|
||||||
}
|
}
|
||||||
|
|
||||||
CParseResult CConfig::parseVariable(const std::string& lhs, const std::string& rhs, bool dynamic) {
|
CParseResult CConfig::parseVariable(const std::string& lhs, const std::string& rhs, bool dynamic) {
|
||||||
auto IT = std::find_if(impl->variables.begin(), impl->variables.end(), [&](const auto& v) { return v.name == lhs.substr(1); });
|
auto IT = std::ranges::find_if(impl->variables, [&](const auto& v) { return v.name == lhs.substr(1); });
|
||||||
|
|
||||||
if (IT != impl->variables.end())
|
if (IT != impl->variables.end())
|
||||||
IT->value = rhs;
|
IT->value = rhs;
|
||||||
else {
|
else {
|
||||||
impl->variables.push_back({lhs.substr(1), rhs});
|
impl->variables.push_back({lhs.substr(1), rhs});
|
||||||
std::sort(impl->variables.begin(), impl->variables.end(), [](const auto& lhs, const auto& rhs) { return lhs.name.length() > rhs.name.length(); });
|
std::ranges::sort(impl->variables, [](const auto& lhs, const auto& rhs) { return lhs.name.length() > rhs.name.length(); });
|
||||||
IT = std::find_if(impl->variables.begin(), impl->variables.end(), [&](const auto& v) { return v.name == lhs.substr(1); });
|
IT = std::ranges::find_if(impl->variables, [&](const auto& v) { return v.name == lhs.substr(1); });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dynamic) {
|
if (dynamic) {
|
||||||
|
@ -451,11 +499,81 @@ CParseResult CConfig::parseVariable(const std::string& lhs, const std::string& r
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CConfigImpl::parseComment(const std::string& comment) {
|
||||||
|
const auto COMMENT = trim(comment);
|
||||||
|
|
||||||
|
if (!COMMENT.starts_with("hyprlang"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
CVarList args(COMMENT, 0, 's', true);
|
||||||
|
|
||||||
|
if (args[1] == "noerror")
|
||||||
|
currentFlags.noError = args[2] == "true" || args[2] == "yes" || args[2] == "enable" || args[2] == "enabled" || args[2] == "set";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::expected<float, std::string> CConfigImpl::parseExpression(const std::string& s) {
|
||||||
|
// for now, we only support very basic expressions.
|
||||||
|
// + - * / and only one per $()
|
||||||
|
// TODO: something better
|
||||||
|
|
||||||
|
if (s.empty())
|
||||||
|
return std::unexpected("Expression is empty");
|
||||||
|
|
||||||
|
CConstVarList args(s, 0, 's', true);
|
||||||
|
|
||||||
|
if (args[1] != "+" && args[1] != "-" && args[1] != "*" && args[1] != "/")
|
||||||
|
return std::unexpected("Invalid expression type: supported +, -, *, /");
|
||||||
|
|
||||||
|
auto LHS_VAR = std::ranges::find_if(variables, [&](const auto& v) { return v.name == args[0]; });
|
||||||
|
auto RHS_VAR = std::ranges::find_if(variables, [&](const auto& v) { return v.name == args[2]; });
|
||||||
|
|
||||||
|
float left = 0;
|
||||||
|
float right = 0;
|
||||||
|
|
||||||
|
if (LHS_VAR != variables.end()) {
|
||||||
|
try {
|
||||||
|
left = std::stof(LHS_VAR->value);
|
||||||
|
} catch (...) { return std::unexpected("Failed to parse expression: value 1 holds a variable that does not look like a number"); }
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
left = std::stof(std::string{args[0]});
|
||||||
|
} catch (...) { return std::unexpected("Failed to parse expression: value 1 does not look like a number or the variable doesn't exist"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RHS_VAR != variables.end()) {
|
||||||
|
try {
|
||||||
|
right = std::stof(RHS_VAR->value);
|
||||||
|
} catch (...) { return std::unexpected("Failed to parse expression: value 1 holds a variable that does not look like a number"); }
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
right = std::stof(std::string{args[2]});
|
||||||
|
} catch (...) { return std::unexpected("Failed to parse expression: value 1 does not look like a number or the variable doesn't exist"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (args[1][0]) {
|
||||||
|
case '+': return left + right;
|
||||||
|
case '-': return left - right;
|
||||||
|
case '*': return left * right;
|
||||||
|
case '/': return left / right;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::unexpected("Unknown error while parsing expression");
|
||||||
|
}
|
||||||
|
|
||||||
CParseResult CConfig::parseLine(std::string line, bool dynamic) {
|
CParseResult CConfig::parseLine(std::string line, bool dynamic) {
|
||||||
CParseResult result;
|
CParseResult result;
|
||||||
|
|
||||||
auto commentPos = line.find('#');
|
line = trim(line);
|
||||||
size_t lastHashPos = 0;
|
|
||||||
|
auto commentPos = line.find('#');
|
||||||
|
|
||||||
|
if (commentPos == 0) {
|
||||||
|
impl->parseComment(line.substr(1));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t lastHashPos = 0;
|
||||||
|
|
||||||
while (commentPos != std::string::npos) {
|
while (commentPos != std::string::npos) {
|
||||||
bool escaped = false;
|
bool escaped = false;
|
||||||
|
@ -475,11 +593,14 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
line = removeBeginEndSpacesTabs(line);
|
line = trim(line);
|
||||||
|
|
||||||
|
if (line.empty())
|
||||||
|
return result;
|
||||||
|
|
||||||
auto equalsPos = line.find('=');
|
auto equalsPos = line.find('=');
|
||||||
|
|
||||||
if (equalsPos == std::string::npos && !line.ends_with("{") && line != "}" && !line.empty()) {
|
if (equalsPos == std::string::npos && !line.ends_with("{") && line != "}") {
|
||||||
// invalid line
|
// invalid line
|
||||||
result.setError("Invalid config line");
|
result.setError("Invalid config line");
|
||||||
return result;
|
return result;
|
||||||
|
@ -488,37 +609,57 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) {
|
||||||
if (equalsPos != std::string::npos) {
|
if (equalsPos != std::string::npos) {
|
||||||
// set value or call handler
|
// set value or call handler
|
||||||
CParseResult ret;
|
CParseResult ret;
|
||||||
auto LHS = removeBeginEndSpacesTabs(line.substr(0, equalsPos));
|
auto LHS = trim(line.substr(0, equalsPos));
|
||||||
auto RHS = removeBeginEndSpacesTabs(line.substr(equalsPos + 1));
|
auto RHS = trim(line.substr(equalsPos + 1));
|
||||||
|
|
||||||
if (LHS.empty()) {
|
if (LHS.empty()) {
|
||||||
result.setError("Empty lhs.");
|
result.setError("Empty lhs.");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*LHS.begin() == '$')
|
const bool ISVARIABLE = *LHS.begin() == '$';
|
||||||
return parseVariable(LHS, RHS, dynamic);
|
|
||||||
|
|
||||||
// limit unwrapping iterations to 100. if exceeds, raise error
|
// limit unwrapping iterations to 100. if exceeds, raise error
|
||||||
for (size_t i = 0; i < 100; ++i) {
|
for (size_t i = 0; i < 100; ++i) {
|
||||||
bool anyMatch = false;
|
bool anyMatch = false;
|
||||||
|
|
||||||
|
// parse variables
|
||||||
for (auto& var : impl->variables) {
|
for (auto& var : impl->variables) {
|
||||||
const auto LHSIT = LHS.find("$" + var.name);
|
// don't parse LHS variables if this is a variable...
|
||||||
|
const auto LHSIT = ISVARIABLE ? std::string::npos : LHS.find("$" + var.name);
|
||||||
const auto RHSIT = RHS.find("$" + var.name);
|
const auto RHSIT = RHS.find("$" + var.name);
|
||||||
|
|
||||||
if (LHSIT != std::string::npos)
|
if (LHSIT != std::string::npos)
|
||||||
replaceAll(LHS, "$" + var.name, var.value);
|
replaceInString(LHS, "$" + var.name, var.value);
|
||||||
if (RHSIT != std::string::npos)
|
if (RHSIT != std::string::npos)
|
||||||
replaceAll(RHS, "$" + var.name, var.value);
|
replaceInString(RHS, "$" + var.name, var.value);
|
||||||
|
|
||||||
if (RHSIT == std::string::npos && LHSIT == std::string::npos)
|
if (RHSIT == std::string::npos && LHSIT == std::string::npos)
|
||||||
continue;
|
continue;
|
||||||
else
|
else if (!dynamic)
|
||||||
var.linesContainingVar.push_back({line, impl->categories, impl->currentSpecialCategory});
|
var.linesContainingVar.push_back({line, impl->categories, impl->currentSpecialCategory});
|
||||||
|
|
||||||
anyMatch = true;
|
anyMatch = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parse expressions $(somevar + 2)
|
||||||
|
// We only support single expressions for now
|
||||||
|
while (RHS.contains("{{")) {
|
||||||
|
const auto BEGIN_EXPR = RHS.find("{{");
|
||||||
|
const auto END_EXPR = RHS.find("}}", BEGIN_EXPR + 2);
|
||||||
|
if (END_EXPR != std::string::npos) {
|
||||||
|
// try to parse the expression
|
||||||
|
const auto RESULT = impl->parseExpression(RHS.substr(BEGIN_EXPR + 2, END_EXPR - BEGIN_EXPR - 2));
|
||||||
|
if (!RESULT.has_value()) {
|
||||||
|
result.setError(RESULT.error());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
RHS = RHS.substr(0, BEGIN_EXPR) + std::format("{}", RESULT.value()) + RHS.substr(END_EXPR + 2);
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (!anyMatch)
|
if (!anyMatch)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -528,12 +669,42 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ISVARIABLE)
|
||||||
|
return parseVariable(LHS, RHS, dynamic);
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
for (auto& h : impl->handlers) {
|
for (auto& h : impl->handlers) {
|
||||||
if (!h.options.allowFlags && h.name != LHS)
|
// we want to handle potentially nested keywords and ensure
|
||||||
|
// we only call the handler if they are scoped correctly,
|
||||||
|
// unless the keyword is not scoped itself
|
||||||
|
|
||||||
|
const bool UNSCOPED = !h.name.contains(":");
|
||||||
|
const auto HANDLERNAME = !h.name.empty() && h.name.at(0) == ':' ? h.name.substr(1) : h.name;
|
||||||
|
|
||||||
|
if (!h.options.allowFlags && !UNSCOPED) {
|
||||||
|
size_t colon = 0;
|
||||||
|
size_t idx = 0;
|
||||||
|
size_t depth = 0;
|
||||||
|
|
||||||
|
while ((colon = HANDLERNAME.find(':', idx)) != std::string::npos && impl->categories.size() > depth) {
|
||||||
|
auto actual = HANDLERNAME.substr(idx, colon - idx);
|
||||||
|
|
||||||
|
if (actual != impl->categories[depth])
|
||||||
|
break;
|
||||||
|
|
||||||
|
idx = colon + 1;
|
||||||
|
++depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (depth != impl->categories.size() || HANDLERNAME.substr(idx) != LHS)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (UNSCOPED && HANDLERNAME != LHS && !h.options.allowFlags)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (h.options.allowFlags && !LHS.starts_with(h.name))
|
if (h.options.allowFlags && (!LHS.starts_with(HANDLERNAME) || LHS.contains(':') /* avoid cases where a category is called the same as a handler */))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ret = h.func(LHS.c_str(), RHS.c_str());
|
ret = h.func(LHS.c_str(), RHS.c_str());
|
||||||
|
@ -545,7 +716,7 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) {
|
||||||
|
|
||||||
if (ret.error)
|
if (ret.error)
|
||||||
return ret;
|
return ret;
|
||||||
} else if (!line.empty()) {
|
} else {
|
||||||
// has to be a set
|
// has to be a set
|
||||||
if (line.contains("}")) {
|
if (line.contains("}")) {
|
||||||
// easiest. } or invalid.
|
// easiest. } or invalid.
|
||||||
|
@ -570,7 +741,7 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) {
|
||||||
}
|
}
|
||||||
|
|
||||||
line.pop_back();
|
line.pop_back();
|
||||||
line = removeBeginEndSpacesTabs(line);
|
line = trim(line);
|
||||||
impl->categories.push_back(line);
|
impl->categories.push_back(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -591,24 +762,78 @@ CParseResult CConfig::parse() {
|
||||||
applyDefaultsToCat(*sc);
|
applyDefaultsToCat(*sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fileExists = std::filesystem::exists(impl->path);
|
CParseResult fileParseResult;
|
||||||
|
|
||||||
// implies options.allowMissingConfig
|
if (impl->rawConfigString.empty()) {
|
||||||
if (impl->configOptions.allowMissingConfig && !fileExists)
|
bool fileExists = std::filesystem::exists(impl->path);
|
||||||
return CParseResult{};
|
|
||||||
else if (!fileExists) {
|
// implies options.allowMissingConfig
|
||||||
CParseResult res;
|
if (impl->configOptions.allowMissingConfig && !fileExists)
|
||||||
res.setError("Config file is missing");
|
return CParseResult{};
|
||||||
return res;
|
else if (!fileExists) {
|
||||||
|
CParseResult res;
|
||||||
|
res.setError("Config file is missing");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string canonical = std::filesystem::canonical(impl->path);
|
||||||
|
|
||||||
|
fileParseResult = parseFile(canonical.c_str());
|
||||||
|
} else {
|
||||||
|
fileParseResult = parseRawStream(impl->rawConfigString);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string canonical = std::filesystem::canonical(impl->path);
|
|
||||||
|
|
||||||
CParseResult fileParseResult = parseFile(canonical.c_str());
|
|
||||||
|
|
||||||
return fileParseResult;
|
return fileParseResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CParseResult CConfig::parseRawStream(const std::string& stream) {
|
||||||
|
CParseResult result;
|
||||||
|
|
||||||
|
int rawLineNum = 0;
|
||||||
|
int lineNum = 0;
|
||||||
|
|
||||||
|
std::stringstream str(stream);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
const auto line = getNextLine(str, rawLineNum, lineNum);
|
||||||
|
|
||||||
|
if (!line) {
|
||||||
|
switch (line.error()) {
|
||||||
|
case GETNEXTLINEFAILURE_EOF: break;
|
||||||
|
case GETNEXTLINEFAILURE_BACKSLASH:
|
||||||
|
if (!impl->parseError.empty())
|
||||||
|
impl->parseError += "\n";
|
||||||
|
impl->parseError += std::format("Config error: Last line ends with backslash");
|
||||||
|
result.setError(impl->parseError);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto RET = parseLine(line.value());
|
||||||
|
|
||||||
|
if (RET.error && (impl->parseError.empty() || impl->configOptions.throwAllErrors)) {
|
||||||
|
if (!impl->parseError.empty())
|
||||||
|
impl->parseError += "\n";
|
||||||
|
impl->parseError += std::format("Config error at line {}: {}", lineNum, RET.errorStdString);
|
||||||
|
result.setError(impl->parseError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!impl->categories.empty()) {
|
||||||
|
if (impl->parseError.empty() || impl->configOptions.throwAllErrors) {
|
||||||
|
if (!impl->parseError.empty())
|
||||||
|
impl->parseError += "\n";
|
||||||
|
impl->parseError += std::format("Config error: Unclosed category at EOF");
|
||||||
|
result.setError(impl->parseError);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl->categories.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
CParseResult CConfig::parseFile(const char* file) {
|
CParseResult CConfig::parseFile(const char* file) {
|
||||||
CParseResult result;
|
CParseResult result;
|
||||||
|
|
||||||
|
@ -618,21 +843,33 @@ CParseResult CConfig::parseFile(const char* file) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string line = "";
|
int rawLineNum = 0;
|
||||||
int linenum = 1;
|
int lineNum = 0;
|
||||||
|
|
||||||
while (std::getline(iffile, line)) {
|
while (true) {
|
||||||
|
const auto line = getNextLine(iffile, rawLineNum, lineNum);
|
||||||
|
|
||||||
const auto RET = parseLine(line);
|
if (!line) {
|
||||||
|
switch (line.error()) {
|
||||||
if (RET.error && (impl->parseError.empty() || impl->configOptions.throwAllErrors)) {
|
case GETNEXTLINEFAILURE_EOF: break;
|
||||||
if (!impl->parseError.empty())
|
case GETNEXTLINEFAILURE_BACKSLASH:
|
||||||
impl->parseError += "\n";
|
if (!impl->parseError.empty())
|
||||||
impl->parseError += std::format("Config error in file {} at line {}: {}", file, linenum, RET.errorStdString);
|
impl->parseError += "\n";
|
||||||
result.setError(impl->parseError);
|
impl->parseError += std::format("Config error in file {}: Last line ends with backslash", file);
|
||||||
|
result.setError(impl->parseError);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
++linenum;
|
const auto RET = parseLine(line.value());
|
||||||
|
|
||||||
|
if (!impl->currentFlags.noError && RET.error && (impl->parseError.empty() || impl->configOptions.throwAllErrors)) {
|
||||||
|
if (!impl->parseError.empty())
|
||||||
|
impl->parseError += "\n";
|
||||||
|
impl->parseError += std::format("Config error in file {} at line {}: {}", file, lineNum, RET.errorStdString);
|
||||||
|
result.setError(impl->parseError);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
iffile.close();
|
iffile.close();
|
||||||
|
@ -690,8 +927,10 @@ CConfigValue* CConfig::getSpecialConfigValuePtr(const char* category, const char
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfig::registerHandler(PCONFIGHANDLERFUNC func, const char* name, SHandlerOptions options) {
|
void CConfig::registerHandler(PCONFIGHANDLERFUNC func, const char* name, SHandlerOptions options_) {
|
||||||
impl->handlers.push_back(SHandler{name, options, func});
|
SHandlerOptions options;
|
||||||
|
std::memcpy(&options, &options_, seekABIStructSize(&options_, 0, sizeof(SHandlerOptions)));
|
||||||
|
impl->handlers.push_back(SHandler{.name = name, .options = options, .func = func});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfig::unregisterHandler(const char* name) {
|
void CConfig::unregisterHandler(const char* name) {
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
#include <expected>
|
||||||
|
|
||||||
struct SHandler {
|
struct SHandler {
|
||||||
std::string name = "";
|
std::string name = "";
|
||||||
|
@ -64,10 +66,18 @@ struct SSpecialCategory {
|
||||||
size_t anonymousID = 0;
|
size_t anonymousID = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum eGetNextLineFailure : uint8_t {
|
||||||
|
GETNEXTLINEFAILURE_EOF = 0,
|
||||||
|
GETNEXTLINEFAILURE_BACKSLASH,
|
||||||
|
};
|
||||||
|
|
||||||
class CConfigImpl {
|
class CConfigImpl {
|
||||||
public:
|
public:
|
||||||
std::string path = "";
|
std::string path = "";
|
||||||
std::string originalPath = "";
|
std::string originalPath = "";
|
||||||
|
|
||||||
|
// if not-empty, used instead of path
|
||||||
|
std::string rawConfigString = "";
|
||||||
|
|
||||||
std::unordered_map<std::string, Hyprlang::CConfigValue> values;
|
std::unordered_map<std::string, Hyprlang::CConfigValue> values;
|
||||||
std::unordered_map<std::string, SConfigDefaultValue> defaultValues;
|
std::unordered_map<std::string, SConfigDefaultValue> defaultValues;
|
||||||
|
@ -84,4 +94,11 @@ class CConfigImpl {
|
||||||
std::string parseError = "";
|
std::string parseError = "";
|
||||||
|
|
||||||
Hyprlang::SConfigOptions configOptions;
|
Hyprlang::SConfigOptions configOptions;
|
||||||
|
|
||||||
|
void parseComment(const std::string& comment);
|
||||||
|
std::expected<float, std::string> parseExpression(const std::string& s);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
bool noError = false;
|
||||||
|
} currentFlags;
|
||||||
};
|
};
|
|
@ -1,5 +1,10 @@
|
||||||
|
|
||||||
# Test comment
|
# Test comment
|
||||||
|
## This is also a comment
|
||||||
|
## This is a comment with space as a first character
|
||||||
|
## This is a comment with tab as a first character
|
||||||
|
## This is a comment with leading spaces and tabs
|
||||||
|
##### Comment with more hash tags
|
||||||
|
|
||||||
testInt = 123
|
testInt = 123
|
||||||
testFloat = 123.456
|
testFloat = 123.456
|
||||||
|
@ -9,12 +14,26 @@ $MY_VAR = 1337
|
||||||
$MY_VAR_2 = $MY_VAR
|
$MY_VAR_2 = $MY_VAR
|
||||||
testVar = $MY_VAR$MY_VAR_2
|
testVar = $MY_VAR$MY_VAR_2
|
||||||
|
|
||||||
|
$EXPR_VAR = {{MY_VAR + 2}}
|
||||||
|
testExpr = {{EXPR_VAR - 4}}
|
||||||
|
|
||||||
testEnv = $SHELL
|
testEnv = $SHELL
|
||||||
|
|
||||||
source = ./colors.conf
|
source = ./colors.conf
|
||||||
|
|
||||||
customType = abc
|
customType = abc
|
||||||
|
|
||||||
|
testStringColon = ee:ee:ee
|
||||||
|
|
||||||
|
# hyprlang noerror true
|
||||||
|
|
||||||
|
errorVariable = true
|
||||||
|
|
||||||
|
# hyprlang noerror false
|
||||||
|
|
||||||
|
categoryKeyword = oops, this one shouldn't call the handler, not fun
|
||||||
|
testUseKeyword = yes
|
||||||
|
|
||||||
testCategory {
|
testCategory {
|
||||||
testValueInt = 123456
|
testValueInt = 123456
|
||||||
testValueHex = 0xF
|
testValueHex = 0xF
|
||||||
|
@ -23,12 +42,20 @@ testCategory {
|
||||||
testColor2 = rgba(0, 0, 0, 1.0)
|
testColor2 = rgba(0, 0, 0, 1.0)
|
||||||
testColor3 = rgba(ffeeff22)
|
testColor3 = rgba(ffeeff22)
|
||||||
|
|
||||||
|
testIgnoreKeyword = aaa
|
||||||
|
testUseKeyword = no
|
||||||
|
|
||||||
nested1 {
|
nested1 {
|
||||||
testValueNest = 1
|
testValueNest = 1
|
||||||
nested2 {
|
nested2 {
|
||||||
testValueNest = 1
|
testValueNest = 1
|
||||||
}
|
}
|
||||||
|
categoryKeyword = this one should not either
|
||||||
}
|
}
|
||||||
|
|
||||||
|
categoryKeyword = we are having fun
|
||||||
|
categoryKeyword = so much fun
|
||||||
|
categoryKeyword = im the fun one at parties
|
||||||
}
|
}
|
||||||
|
|
||||||
$SPECIALVAL1 = 1
|
$SPECIALVAL1 = 1
|
||||||
|
@ -38,8 +65,7 @@ special {
|
||||||
value = $SPECIALVAL1
|
value = $SPECIALVAL1
|
||||||
}
|
}
|
||||||
|
|
||||||
special {
|
special[b] {
|
||||||
key = b
|
|
||||||
value = 2
|
value = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,8 +89,21 @@ specialAnonymous {
|
||||||
value = 3
|
value = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flagsStuff {
|
||||||
|
value = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
multiline = \
|
||||||
|
very \
|
||||||
|
long \
|
||||||
|
command
|
||||||
|
|
||||||
testCategory:testValueHex = 0xFFfFaAbB
|
testCategory:testValueHex = 0xFFfFaAbB
|
||||||
|
|
||||||
|
$RECURSIVE1 = a
|
||||||
|
$RECURSIVE2 = $RECURSIVE1b
|
||||||
|
testStringRecursive = $RECURSIVE2c
|
||||||
|
|
||||||
testStringQuotes = "Hello World!"
|
testStringQuotes = "Hello World!"
|
||||||
#testDefault = 123
|
#testDefault = 123
|
||||||
|
|
||||||
|
@ -72,4 +111,3 @@ doABarrelRoll = woohoo, some, params # Funny!
|
||||||
flagsabc = test
|
flagsabc = test
|
||||||
#doSomethingFunny = 1, 2, 3, 4 # Funnier!
|
#doSomethingFunny = 1, 2, 3, 4 # Funnier!
|
||||||
#testSpaces = abc , def # many spaces, should be trimmed
|
#testSpaces = abc , def # many spaces, should be trimmed
|
||||||
|
|
||||||
|
|
15
tests/config/invalid-numbers.conf
Normal file
15
tests/config/invalid-numbers.conf
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
# Every number/color in this file is invalid
|
||||||
|
|
||||||
|
invalidHex = 0x1Q
|
||||||
|
emptyHex = 0x
|
||||||
|
hugeHex = 0xFFFFFFFFFFFFFFFF
|
||||||
|
|
||||||
|
invalidInt = 1A
|
||||||
|
emptyInt =
|
||||||
|
|
||||||
|
invalidColor = rgb(ABCDEQ)
|
||||||
|
invalidFirstCharColor = rgb(QABCDE)
|
||||||
|
|
||||||
|
invalidColorAlpha = rgba(9ABCDEFQ)
|
||||||
|
invalidFirstCharColorAlpha = rgba(Q9ABCDEF)
|
||||||
|
|
20
tests/config/multiline-errors.conf
Normal file
20
tests/config/multiline-errors.conf
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# Careful when modifying this file. Line numbers are part of the test.
|
||||||
|
|
||||||
|
multiline = \
|
||||||
|
one \
|
||||||
|
two \
|
||||||
|
three
|
||||||
|
|
||||||
|
# Line numbers reported in errors should match the actual line numbers of the source file
|
||||||
|
# even after multi-line configs. Any errors reported should use the line number of the
|
||||||
|
# first line of any multi-line config.
|
||||||
|
|
||||||
|
this \
|
||||||
|
should \
|
||||||
|
cause \
|
||||||
|
error \
|
||||||
|
on \
|
||||||
|
line \
|
||||||
|
12
|
||||||
|
|
||||||
|
# A config file cannot end with a bashslash because we are expecting another line! Even in a comment! \
|
|
@ -11,7 +11,7 @@ std::string garbage() {
|
||||||
|
|
||||||
std::string chars;
|
std::string chars;
|
||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
chars += rand() % 254 + 1;
|
chars += std::to_string((rand() % 254) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return chars;
|
return chars;
|
||||||
|
|
|
@ -23,12 +23,15 @@ namespace Colors {
|
||||||
}
|
}
|
||||||
|
|
||||||
// globals for testing
|
// globals for testing
|
||||||
bool barrelRoll = false;
|
bool barrelRoll = false;
|
||||||
std::string flagsFound = "";
|
std::string flagsFound = "";
|
||||||
Hyprlang::CConfig* pConfig = nullptr;
|
Hyprlang::CConfig* pConfig = nullptr;
|
||||||
std::string currentPath = "";
|
std::string currentPath = "";
|
||||||
|
std::string ignoreKeyword = "";
|
||||||
|
std::string useKeyword = "";
|
||||||
|
static std::vector<std::string> categoryKeywordActualValues;
|
||||||
|
|
||||||
static Hyprlang::CParseResult handleDoABarrelRoll(const char* COMMAND, const char* VALUE) {
|
static Hyprlang::CParseResult handleDoABarrelRoll(const char* COMMAND, const char* VALUE) {
|
||||||
if (std::string(VALUE) == "woohoo, some, params")
|
if (std::string(VALUE) == "woohoo, some, params")
|
||||||
barrelRoll = true;
|
barrelRoll = true;
|
||||||
|
|
||||||
|
@ -44,6 +47,28 @@ static Hyprlang::CParseResult handleFlagsTest(const char* COMMAND, const char* V
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Hyprlang::CParseResult handleCategoryKeyword(const char* COMMAND, const char* VALUE) {
|
||||||
|
categoryKeywordActualValues.emplace_back(VALUE);
|
||||||
|
|
||||||
|
return Hyprlang::CParseResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Hyprlang::CParseResult handleTestIgnoreKeyword(const char* COMMAND, const char* VALUE) {
|
||||||
|
ignoreKeyword = VALUE;
|
||||||
|
|
||||||
|
return Hyprlang::CParseResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Hyprlang::CParseResult handleTestUseKeyword(const char* COMMAND, const char* VALUE) {
|
||||||
|
useKeyword = VALUE;
|
||||||
|
|
||||||
|
return Hyprlang::CParseResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Hyprlang::CParseResult handleNoop(const char* COMMAND, const char* VALUE) {
|
||||||
|
return Hyprlang::CParseResult();
|
||||||
|
}
|
||||||
|
|
||||||
static Hyprlang::CParseResult handleSource(const char* COMMAND, const char* VALUE) {
|
static Hyprlang::CParseResult handleSource(const char* COMMAND, const char* VALUE) {
|
||||||
std::string PATH = std::filesystem::canonical(currentPath + "/" + VALUE);
|
std::string PATH = std::filesystem::canonical(currentPath + "/" + VALUE);
|
||||||
return pConfig->parseFile(PATH.c_str());
|
return pConfig->parseFile(PATH.c_str());
|
||||||
|
@ -82,40 +107,52 @@ int main(int argc, char** argv, char** envp) {
|
||||||
|
|
||||||
// setup config
|
// setup config
|
||||||
config.addConfigValue("testInt", (Hyprlang::INT)0);
|
config.addConfigValue("testInt", (Hyprlang::INT)0);
|
||||||
|
config.addConfigValue("testExpr", (Hyprlang::INT)0);
|
||||||
config.addConfigValue("testFloat", 0.F);
|
config.addConfigValue("testFloat", 0.F);
|
||||||
config.addConfigValue("testVec", Hyprlang::SVector2D{69, 420});
|
config.addConfigValue("testVec", Hyprlang::SVector2D{.x = 69, .y = 420});
|
||||||
config.addConfigValue("testString", "");
|
config.addConfigValue("testString", "");
|
||||||
|
config.addConfigValue("testStringColon", "");
|
||||||
config.addConfigValue("testEnv", "");
|
config.addConfigValue("testEnv", "");
|
||||||
config.addConfigValue("testVar", (Hyprlang::INT)0);
|
config.addConfigValue("testVar", (Hyprlang::INT)0);
|
||||||
|
config.addConfigValue("categoryKeyword", (Hyprlang::STRING) "");
|
||||||
config.addConfigValue("testStringQuotes", "");
|
config.addConfigValue("testStringQuotes", "");
|
||||||
|
config.addConfigValue("testStringRecursive", "");
|
||||||
config.addConfigValue("testCategory:testValueInt", (Hyprlang::INT)0);
|
config.addConfigValue("testCategory:testValueInt", (Hyprlang::INT)0);
|
||||||
config.addConfigValue("testCategory:testValueHex", (Hyprlang::INT)0xA);
|
config.addConfigValue("testCategory:testValueHex", (Hyprlang::INT)0xA);
|
||||||
config.addConfigValue("testCategory:nested1:testValueNest", (Hyprlang::INT)0);
|
config.addConfigValue("testCategory:nested1:testValueNest", (Hyprlang::INT)0);
|
||||||
config.addConfigValue("testCategory:nested1:nested2:testValueNest", (Hyprlang::INT)0);
|
config.addConfigValue("testCategory:nested1:nested2:testValueNest", (Hyprlang::INT)0);
|
||||||
|
config.addConfigValue("testCategory:nested1:categoryKeyword", (Hyprlang::STRING) "");
|
||||||
config.addConfigValue("testDefault", (Hyprlang::INT)123);
|
config.addConfigValue("testDefault", (Hyprlang::INT)123);
|
||||||
config.addConfigValue("testCategory:testColor1", (Hyprlang::INT)0);
|
config.addConfigValue("testCategory:testColor1", (Hyprlang::INT)0);
|
||||||
config.addConfigValue("testCategory:testColor2", (Hyprlang::INT)0);
|
config.addConfigValue("testCategory:testColor2", (Hyprlang::INT)0);
|
||||||
config.addConfigValue("testCategory:testColor3", (Hyprlang::INT)0);
|
config.addConfigValue("testCategory:testColor3", (Hyprlang::INT)0);
|
||||||
|
config.addConfigValue("flagsStuff:value", (Hyprlang::INT)0);
|
||||||
config.addConfigValue("myColors:pink", (Hyprlang::INT)0);
|
config.addConfigValue("myColors:pink", (Hyprlang::INT)0);
|
||||||
config.addConfigValue("myColors:green", (Hyprlang::INT)0);
|
config.addConfigValue("myColors:green", (Hyprlang::INT)0);
|
||||||
config.addConfigValue("myColors:random", (Hyprlang::INT)0);
|
config.addConfigValue("myColors:random", (Hyprlang::INT)0);
|
||||||
config.addConfigValue("customType", {Hyprlang::CConfigCustomValueType{&handleCustomValueSet, &handleCustomValueDestroy, "def"}});
|
config.addConfigValue("customType", {Hyprlang::CConfigCustomValueType{&handleCustomValueSet, &handleCustomValueDestroy, "def"}});
|
||||||
|
|
||||||
config.registerHandler(&handleDoABarrelRoll, "doABarrelRoll", {false});
|
config.registerHandler(&handleDoABarrelRoll, "doABarrelRoll", {.allowFlags = false});
|
||||||
config.registerHandler(&handleFlagsTest, "flags", {true});
|
config.registerHandler(&handleFlagsTest, "flags", {.allowFlags = true});
|
||||||
config.registerHandler(&handleSource, "source", {false});
|
config.registerHandler(&handleSource, "source", {.allowFlags = false});
|
||||||
|
config.registerHandler(&handleTestIgnoreKeyword, "testIgnoreKeyword", {.allowFlags = false});
|
||||||
|
config.registerHandler(&handleTestUseKeyword, ":testUseKeyword", {.allowFlags = false});
|
||||||
|
config.registerHandler(&handleNoop, "testCategory:testUseKeyword", {.allowFlags = false});
|
||||||
|
config.registerHandler(&handleCategoryKeyword, "testCategory:categoryKeyword", {.allowFlags = false});
|
||||||
|
|
||||||
config.addSpecialCategory("special", {"key"});
|
config.addSpecialCategory("special", {.key = "key"});
|
||||||
config.addSpecialConfigValue("special", "value", (Hyprlang::INT)0);
|
config.addSpecialConfigValue("special", "value", (Hyprlang::INT)0);
|
||||||
|
|
||||||
config.addSpecialCategory("specialAnonymous", {nullptr, false, true});
|
config.addSpecialCategory("specialAnonymous", {.key = nullptr, .ignoreMissing = false, .anonymousKeyBased = true});
|
||||||
config.addSpecialConfigValue("specialAnonymous", "value", (Hyprlang::INT)0);
|
config.addSpecialConfigValue("specialAnonymous", "value", (Hyprlang::INT)0);
|
||||||
|
|
||||||
|
config.addConfigValue("multiline", "");
|
||||||
|
|
||||||
config.commence();
|
config.commence();
|
||||||
|
|
||||||
config.addSpecialCategory("specialGeneric:one", {nullptr, true});
|
config.addSpecialCategory("specialGeneric:one", {.key = nullptr, .ignoreMissing = true});
|
||||||
config.addSpecialConfigValue("specialGeneric:one", "value", (Hyprlang::INT)0);
|
config.addSpecialConfigValue("specialGeneric:one", "value", (Hyprlang::INT)0);
|
||||||
config.addSpecialCategory("specialGeneric:two", {nullptr, true});
|
config.addSpecialCategory("specialGeneric:two", {.key = nullptr, .ignoreMissing = true});
|
||||||
config.addSpecialConfigValue("specialGeneric:two", "value", (Hyprlang::INT)0);
|
config.addSpecialConfigValue("specialGeneric:two", "value", (Hyprlang::INT)0);
|
||||||
|
|
||||||
const Hyprlang::CConfigValue copyTest = {(Hyprlang::INT)1};
|
const Hyprlang::CConfigValue copyTest = {(Hyprlang::INT)1};
|
||||||
|
@ -133,7 +170,7 @@ int main(int argc, char** argv, char** envp) {
|
||||||
std::cout << " → Testing values\n";
|
std::cout << " → Testing values\n";
|
||||||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testInt")), 123);
|
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testInt")), 123);
|
||||||
EXPECT(std::any_cast<float>(config.getConfigValue("testFloat")), 123.456f);
|
EXPECT(std::any_cast<float>(config.getConfigValue("testFloat")), 123.456f);
|
||||||
auto EXP = Hyprlang::SVector2D{69, 420};
|
auto EXP = Hyprlang::SVector2D{.x = 69, .y = 420};
|
||||||
EXPECT(std::any_cast<Hyprlang::SVector2D>(config.getConfigValue("testVec")), EXP);
|
EXPECT(std::any_cast<Hyprlang::SVector2D>(config.getConfigValue("testVec")), EXP);
|
||||||
EXPECT(std::any_cast<const char*>(config.getConfigValue("testString")), std::string{"Hello World! # This is not a comment!"});
|
EXPECT(std::any_cast<const char*>(config.getConfigValue("testString")), std::string{"Hello World! # This is not a comment!"});
|
||||||
EXPECT(std::any_cast<const char*>(config.getConfigValue("testStringQuotes")), std::string{"\"Hello World!\""});
|
EXPECT(std::any_cast<const char*>(config.getConfigValue("testStringQuotes")), std::string{"\"Hello World!\""});
|
||||||
|
@ -145,6 +182,25 @@ int main(int argc, char** argv, char** envp) {
|
||||||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testCategory:testColor1")), (Hyprlang::INT)0xFFFFFFFF);
|
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testCategory:testColor1")), (Hyprlang::INT)0xFFFFFFFF);
|
||||||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testCategory:testColor2")), (Hyprlang::INT)0xFF000000);
|
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testCategory:testColor2")), (Hyprlang::INT)0xFF000000);
|
||||||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testCategory:testColor3")), (Hyprlang::INT)0x22ffeeff);
|
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testCategory:testColor3")), (Hyprlang::INT)0x22ffeeff);
|
||||||
|
EXPECT(std::any_cast<const char*>(config.getConfigValue("testStringColon")), std::string{"ee:ee:ee"});
|
||||||
|
EXPECT(std::any_cast<const char*>(config.getConfigValue("categoryKeyword")), std::string{"oops, this one shouldn't call the handler, not fun"});
|
||||||
|
EXPECT(std::any_cast<const char*>(config.getConfigValue("testCategory:nested1:categoryKeyword")), std::string{"this one should not either"});
|
||||||
|
EXPECT(ignoreKeyword, "aaa");
|
||||||
|
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 expressions
|
||||||
|
std::cout << " → Testing expressions\n";
|
||||||
|
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testExpr")), 1335);
|
||||||
|
|
||||||
// test static values
|
// test static values
|
||||||
std::cout << " → Testing static values\n";
|
std::cout << " → Testing static values\n";
|
||||||
|
@ -158,6 +214,10 @@ int main(int argc, char** argv, char** envp) {
|
||||||
EXPECT(barrelRoll, true);
|
EXPECT(barrelRoll, true);
|
||||||
EXPECT(flagsFound, std::string{"abc"});
|
EXPECT(flagsFound, std::string{"abc"});
|
||||||
|
|
||||||
|
EXPECT(categoryKeywordActualValues.at(0), "we are having fun");
|
||||||
|
EXPECT(categoryKeywordActualValues.at(1), "so much fun");
|
||||||
|
EXPECT(categoryKeywordActualValues.at(2), "im the fun one at parties");
|
||||||
|
|
||||||
// test dynamic
|
// test dynamic
|
||||||
std::cout << " → Testing dynamic\n";
|
std::cout << " → Testing dynamic\n";
|
||||||
barrelRoll = false;
|
barrelRoll = false;
|
||||||
|
@ -165,6 +225,10 @@ int main(int argc, char** argv, char** envp) {
|
||||||
EXPECT(barrelRoll, true);
|
EXPECT(barrelRoll, true);
|
||||||
EXPECT(config.parseDynamic("testCategory:testValueHex", "0xaabbccdd").error, false);
|
EXPECT(config.parseDynamic("testCategory:testValueHex", "0xaabbccdd").error, false);
|
||||||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testCategory:testValueHex")), (Hyprlang::INT)0xAABBCCDD);
|
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testCategory:testValueHex")), (Hyprlang::INT)0xAABBCCDD);
|
||||||
|
EXPECT(config.parseDynamic("testStringColon", "1:3:3:7").error, false);
|
||||||
|
EXPECT(std::any_cast<const char*>(config.getConfigValue("testStringColon")), std::string{"1:3:3:7"});
|
||||||
|
EXPECT(config.parseDynamic("flagsStuff:value = 69").error, false);
|
||||||
|
EXPECT(std::any_cast<int64_t>(config.getConfigValue("flagsStuff:value")), (Hyprlang::INT)69);
|
||||||
|
|
||||||
// test dynamic special
|
// test dynamic special
|
||||||
config.addSpecialConfigValue("specialGeneric:one", "boom", (Hyprlang::INT)0);
|
config.addSpecialConfigValue("specialGeneric:one", "boom", (Hyprlang::INT)0);
|
||||||
|
@ -174,12 +238,20 @@ int main(int argc, char** argv, char** envp) {
|
||||||
// test variables
|
// test variables
|
||||||
std::cout << " → Testing variables\n";
|
std::cout << " → Testing variables\n";
|
||||||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testVar")), 13371337);
|
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testVar")), 13371337);
|
||||||
|
EXPECT(std::any_cast<const char*>(config.getConfigValue("testStringRecursive")), std::string{"abc"});
|
||||||
|
|
||||||
// test dynamic variables
|
// test dynamic variables
|
||||||
std::cout << " → Testing dynamic variables\n";
|
std::cout << " → Testing dynamic variables\n";
|
||||||
EXPECT(config.parseDynamic("$MY_VAR_2 = 420").error, false);
|
EXPECT(config.parseDynamic("$MY_VAR_2 = 420").error, false);
|
||||||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testVar")), 1337420);
|
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testVar")), 1337420);
|
||||||
|
|
||||||
|
EXPECT(config.parseDynamic("$RECURSIVE1 = d").error, false);
|
||||||
|
EXPECT(std::any_cast<const char*>(config.getConfigValue("testStringRecursive")), std::string{"dbc"});
|
||||||
|
|
||||||
|
// test dynamic exprs
|
||||||
|
EXPECT(config.parseDynamic("testExpr = {{EXPR_VAR * 2}}").error, false);
|
||||||
|
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testExpr")), 1339L * 2);
|
||||||
|
|
||||||
// test env variables
|
// test env variables
|
||||||
std::cout << " → Testing env variables\n";
|
std::cout << " → Testing env variables\n";
|
||||||
EXPECT(std::any_cast<const char*>(config.getConfigValue("testEnv")), std::string{getenv("SHELL")});
|
EXPECT(std::any_cast<const char*>(config.getConfigValue("testEnv")), std::string{getenv("SHELL")});
|
||||||
|
@ -190,6 +262,8 @@ int main(int argc, char** argv, char** envp) {
|
||||||
EXPECT(std::any_cast<int64_t>(config.getSpecialConfigValue("special", "value", "b")), 2);
|
EXPECT(std::any_cast<int64_t>(config.getSpecialConfigValue("special", "value", "b")), 2);
|
||||||
EXPECT(std::any_cast<int64_t>(config.getSpecialConfigValue("specialGeneric:one", "value")), 1);
|
EXPECT(std::any_cast<int64_t>(config.getSpecialConfigValue("specialGeneric:one", "value")), 1);
|
||||||
EXPECT(std::any_cast<int64_t>(config.getSpecialConfigValue("specialGeneric:two", "value")), 2);
|
EXPECT(std::any_cast<int64_t>(config.getSpecialConfigValue("specialGeneric:two", "value")), 2);
|
||||||
|
EXPECT(config.parseDynamic("special[b]:value = 3").error, false);
|
||||||
|
EXPECT(std::any_cast<int64_t>(config.getSpecialConfigValue("special", "value", "b")), 3);
|
||||||
|
|
||||||
// test dynamic special variable
|
// test dynamic special variable
|
||||||
EXPECT(config.parseDynamic("$SPECIALVAL1 = 2").error, false);
|
EXPECT(config.parseDynamic("$SPECIALVAL1 = 2").error, false);
|
||||||
|
@ -216,6 +290,9 @@ int main(int argc, char** argv, char** envp) {
|
||||||
std::cout << " → Testing custom types\n";
|
std::cout << " → Testing custom types\n";
|
||||||
EXPECT(*reinterpret_cast<int64_t*>(std::any_cast<void*>(config.getConfigValue("customType"))), (Hyprlang::INT)1);
|
EXPECT(*reinterpret_cast<int64_t*>(std::any_cast<void*>(config.getConfigValue("customType"))), (Hyprlang::INT)1);
|
||||||
|
|
||||||
|
// test multiline config
|
||||||
|
EXPECT(std::any_cast<const char*>(config.getConfigValue("multiline")), std::string{"very long command"});
|
||||||
|
|
||||||
std::cout << " → Testing error.conf\n";
|
std::cout << " → Testing error.conf\n";
|
||||||
Hyprlang::CConfig errorConfig("./config/error.conf", {.verifyOnly = true, .throwAllErrors = true});
|
Hyprlang::CConfig errorConfig("./config/error.conf", {.verifyOnly = true, .throwAllErrors = true});
|
||||||
|
|
||||||
|
@ -226,6 +303,35 @@ int main(int argc, char** argv, char** envp) {
|
||||||
const auto ERRORSTR = std::string{ERRORS.getError()};
|
const auto ERRORSTR = std::string{ERRORS.getError()};
|
||||||
EXPECT(std::count(ERRORSTR.begin(), ERRORSTR.end(), '\n'), 1);
|
EXPECT(std::count(ERRORSTR.begin(), ERRORSTR.end(), '\n'), 1);
|
||||||
|
|
||||||
|
std::cout << " → Testing invalid-numbers.conf\n";
|
||||||
|
Hyprlang::CConfig invalidNumbersConfig("./config/invalid-numbers.conf", {.throwAllErrors = true});
|
||||||
|
invalidNumbersConfig.addConfigValue("invalidHex", (Hyprlang::INT)0);
|
||||||
|
invalidNumbersConfig.addConfigValue("emptyHex", (Hyprlang::INT)0);
|
||||||
|
invalidNumbersConfig.addConfigValue("hugeHex", (Hyprlang::INT)0);
|
||||||
|
invalidNumbersConfig.addConfigValue("invalidInt", (Hyprlang::INT)0);
|
||||||
|
invalidNumbersConfig.addConfigValue("emptyInt", (Hyprlang::INT)0);
|
||||||
|
invalidNumbersConfig.addConfigValue("invalidColor", (Hyprlang::INT)0);
|
||||||
|
invalidNumbersConfig.addConfigValue("invalidFirstCharColor", (Hyprlang::INT)0);
|
||||||
|
invalidNumbersConfig.addConfigValue("invalidColorAlpha", (Hyprlang::INT)0);
|
||||||
|
invalidNumbersConfig.addConfigValue("invalidFirstCharColorAlpha", (Hyprlang::INT)0);
|
||||||
|
|
||||||
|
invalidNumbersConfig.commence();
|
||||||
|
const auto ERRORS2 = invalidNumbersConfig.parse();
|
||||||
|
|
||||||
|
EXPECT(ERRORS2.error, true);
|
||||||
|
const auto ERRORSTR2 = std::string{ERRORS2.getError()};
|
||||||
|
EXPECT(std::count(ERRORSTR2.begin(), ERRORSTR2.end(), '\n'), 9 - 1);
|
||||||
|
|
||||||
|
Hyprlang::CConfig multilineErrorConfig("./config/multiline-errors.conf", {.verifyOnly = true, .throwAllErrors = true});
|
||||||
|
multilineErrorConfig.commence();
|
||||||
|
const auto ERRORS3 = multilineErrorConfig.parse();
|
||||||
|
EXPECT(ERRORS3.error, true);
|
||||||
|
const auto ERRORSTR3 = std::string{ERRORS3.getError()};
|
||||||
|
|
||||||
|
// Error on line 12
|
||||||
|
EXPECT(ERRORSTR3.contains("12"), true);
|
||||||
|
// Backslash at end of file
|
||||||
|
EXPECT(ERRORSTR3.contains("backslash"), true);
|
||||||
} catch (const char* e) {
|
} catch (const char* e) {
|
||||||
std::cout << Colors::RED << "Error: " << Colors::RESET << e << "\n";
|
std::cout << Colors::RED << "Error: " << Colors::RESET << e << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in a new issue