File tree Expand file tree Collapse file tree 1 file changed +32
-2
lines changed Expand file tree Collapse file tree 1 file changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -46,10 +46,40 @@ void Syntax::loadSyntaxRules(const YAML::Node &config)
4646 // Iterate through each rule in the category
4747 for (const auto &rule : rules)
4848 {
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+ {
53+ std::string regexStr = rule[" regex" ].as <std::string>(); // will throw exception if the key does not exist
54+ regex = QString::fromStdString (regexStr);
55+ }
56+ catch (const YAML::Exception e)
57+ {
58+ qWarning () << " YAML exception when parsion the regex in syntax file" << e.what ();
59+ continue ;
60+ }
61+
5162 qDebug () << " regex: " << regex;
5263
64+ QColor color;
65+ try
66+ {
67+ std::string colorStr = rule[" color" ].as <std::string>();
68+ color = QColor (QString::fromStdString (colorStr));
69+ }
70+ catch (const YAML::Exception e)
71+ {
72+ qWarning () << " YAML exception when parsion the color in syntax file" << e.what ();
73+ continue ;
74+ }
75+
76+ // checks if the color is a valid color
77+ if (!color.isValid ())
78+ {
79+ qWarning () << " Invalid COlor : Skipping..." ;
80+ continue ;
81+ }
82+
5383 // Create a QTextCharFormat for the rule
5484 QTextCharFormat format;
5585 format.setForeground (color);
You can’t perform that action at this time.
0 commit comments