File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -46,10 +46,28 @@ void Syntax::loadSyntaxRules(const YAML::Node &config)
46
46
// Iterate through each rule in the category
47
47
for (const auto &rule : rules)
48
48
{
49
- QString regex = QString::fromStdString (rule[" regex" ].as <std::string>());
50
- QColor color (QString::fromStdString (rule[" color" ].as <std::string>()));
49
+
50
+ QString regex;
51
+ try {
52
+ std::string regexStr = rule[" regex" ].as <std::string>(); // will throw exception if the key does not exist
53
+ regex = QString::fromStdString (regexStr);
54
+ }catch (const YAML::Exception e){
55
+ qWarning () << " YAML exception when parsion the regex in syntax file" << e.what ();
56
+ continue ;
57
+ }
58
+
51
59
qDebug () << " regex: " << regex;
52
60
61
+ QColor color;
62
+ try {
63
+ std::string colorStr = rule[" color" ].as <std::string>();
64
+ color = QColor (QString::fromStdString (colorStr));
65
+ }catch (const YAML::Exception e){
66
+ qWarning () << " YAML exception when parsion the color in syntax file" << e.what ();
67
+ continue ;
68
+ }
69
+
70
+
53
71
// Create a QTextCharFormat for the rule
54
72
QTextCharFormat format;
55
73
format.setForeground (color);
You can’t perform that action at this time.
0 commit comments