diff --git a/src/Syntax.cpp b/src/Syntax.cpp index 3a2f666..e3aab1c 100644 --- a/src/Syntax.cpp +++ b/src/Syntax.cpp @@ -46,10 +46,40 @@ void Syntax::loadSyntaxRules(const YAML::Node &config) // Iterate through each rule in the category for (const auto &rule : rules) { - QString regex = QString::fromStdString(rule["regex"].as()); - QColor color(QString::fromStdString(rule["color"].as())); + + QString regex; + try + { + std::string regexStr = rule["regex"].as(); //will throw exception if the key does not exist + regex = QString::fromStdString(regexStr); + } + catch(const YAML::Exception e) + { + qWarning() << " YAML exception when parsion the regex in syntax file" << e.what(); + continue; + } + qDebug() << "regex: " << regex; + QColor color; + try + { + std::string colorStr = rule["color"].as(); + color = QColor(QString::fromStdString(colorStr)); + } + catch(const YAML::Exception e) + { + qWarning() << " YAML exception when parsion the color in syntax file" << e.what(); + continue; + } + + //checks if the color is a valid color + if(!color.isValid()) + { + qWarning() << "Invalid COlor : Skipping..."; + continue; + } + // Create a QTextCharFormat for the rule QTextCharFormat format; format.setForeground(color);