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)
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+ 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+
5159 qDebug () << " regex: " << regex;
5260
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+
5371 // Create a QTextCharFormat for the rule
5472 QTextCharFormat format;
5573 format.setForeground (color);
You can’t perform that action at this time.
0 commit comments