@@ -9,9 +9,10 @@ use async_lsp::lsp_types::{
99use dashmap:: mapref:: one:: Ref ;
1010use serde:: { Deserialize , Serialize } ;
1111
12- use crate :: configuration:: MetadataValidationRule ;
1312use chrono:: NaiveDate ;
13+ use regex:: Regex ;
1414
15+ use crate :: configuration:: MetadataValidationRule ;
1516#[ cfg( feature = "full-compiler" ) ]
1617use crate :: documents:: document:: Document ;
1718use crate :: documents:: storage:: DocumentStorage ;
@@ -95,18 +96,37 @@ pub fn compiler_diagnostics(
9596 if let Some ( ty) = & validation_rule. ty {
9697 match ty. as_str ( ) {
9798 "string" => {
98- compiler. add_linter ( linter. validator (
99- |meta| {
100- matches ! (
101- meta. value,
102- yara_x_parser:: ast:: MetaValue :: String ( _)
103- )
104- } ,
105- format ! (
106- "`{}` must be a `string`" ,
107- validation_rule. identifier
108- ) ,
109- ) ) ;
99+ if let Some ( pattern) = & validation_rule. regex {
100+ compiler. add_linter ( linter. validator (
101+ |meta| {
102+ if let yara_x_parser:: ast:: MetaValue :: String (
103+ value,
104+ ) = & meta. value
105+ {
106+ Regex :: new ( pattern) . unwrap ( ) . is_match ( value. 0 )
107+ } else {
108+ false
109+ }
110+ } ,
111+ format ! (
112+ "`{}` must be a string and match the pattern `{}`" ,
113+ validation_rule. identifier, pattern
114+ ) ,
115+ ) ) ;
116+ } else {
117+ compiler. add_linter ( linter. validator (
118+ |meta| {
119+ matches ! (
120+ meta. value,
121+ yara_x_parser:: ast:: MetaValue :: String ( _)
122+ )
123+ } ,
124+ format ! (
125+ "`{}` must be a `string`" ,
126+ validation_rule. identifier
127+ ) ,
128+ ) ) ;
129+ }
110130 }
111131 "integer" => {
112132 compiler. add_linter ( linter. validator (
0 commit comments