Skip to content

Commit

Permalink
lib: add escaping errors
Browse files Browse the repository at this point in the history
# hyprlang noerror true

fixes #39
  • Loading branch information
vaxerski committed Apr 14, 2024
1 parent c140261 commit de5ca2f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <sstream>
#include <cstring>

#include "VarList.hpp"

using namespace Hyprlang;

#ifdef __APPLE__
Expand Down Expand Up @@ -510,15 +512,29 @@ CParseResult CConfig::parseVariable(const std::string& lhs, const std::string& r
return result;
}

void CConfigImpl::parseComment(const std::string& comment) {
const auto COMMENT = removeBeginEndSpacesTabs(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";
}

CParseResult CConfig::parseLine(std::string line, bool dynamic) {
CParseResult result;

line = removeBeginEndSpacesTabs(line);

auto commentPos = line.find('#');

if (commentPos == 0)
if (commentPos == 0) {
impl->parseComment(line.substr(1));
return result;
}

size_t lastHashPos = 0;

Expand Down Expand Up @@ -737,7 +753,7 @@ CParseResult CConfig::parseFile(const char* file) {

const auto RET = parseLine(line);

if (RET.error && (impl->parseError.empty() || impl->configOptions.throwAllErrors)) {
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);
Expand Down
6 changes: 6 additions & 0 deletions src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,10 @@ class CConfigImpl {
std::string parseError = "";

Hyprlang::SConfigOptions configOptions;

void parseComment(const std::string& comment);

struct {
bool noError = false;
} currentFlags;
};
6 changes: 6 additions & 0 deletions tests/config/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ customType = abc

testStringColon = ee:ee:ee

# hyprlang noerror true

errorVariable = true

# hyprlang noerror false

testCategory {
testValueInt = 123456
testValueHex = 0xF
Expand Down

0 comments on commit de5ca2f

Please sign in to comment.