13
13
pp .ParserElement .enablePackrat ()
14
14
15
15
16
+ class UnsupportedFilteringFeatureError (ValueError ):
17
+ def __init__ (self ):
18
+ super ().__init__ (
19
+ f"Unsupported filtering feature: { self .feature } . Please see "
20
+ f"https://github.com/sgkit-dev/vcztools/issues/{ self .issue } "
21
+ "for details and let us know if this is important to you."
22
+ )
23
+
24
+
25
+ class UnsupportedRegexError (UnsupportedFilteringFeatureError ):
26
+ issue = "174"
27
+ feature = "Regular expressions"
28
+
29
+
16
30
# The parser and evaluation model here are based on the eval_arith example
17
31
# in the pyparsing docs:
18
32
# https://github.com/pyparsing/pyparsing/blob/master/examples/eval_arith.py
@@ -27,18 +41,18 @@ class EvaluationNode:
27
41
def __init__ (self , tokens ):
28
42
self .tokens = tokens [0 ]
29
43
30
-
31
- class Constant (EvaluationNode ):
32
- def eval (self , data ):
33
- return self .tokens
34
-
35
44
def __repr__ (self ):
36
45
return repr (self .tokens )
37
46
38
47
def referenced_fields (self ):
39
48
return frozenset ()
40
49
41
50
51
+ class Constant (EvaluationNode ):
52
+ def eval (self , data ):
53
+ return self .tokens
54
+
55
+
42
56
class Identifier (EvaluationNode ):
43
57
def __init__ (self , mapper , tokens ):
44
58
self .field_name = mapper (tokens [0 ])
@@ -55,6 +69,11 @@ def referenced_fields(self):
55
69
return frozenset ([self .field_name ])
56
70
57
71
72
+ class RegexOperator (EvaluationNode ):
73
+ def __init__ (self , tokens ):
74
+ raise UnsupportedRegexError ()
75
+
76
+
58
77
# NOTE we should perhaps add a Operator superclass of UnaryMinus,
59
78
# BinaryOperator and ComparisonOperator to reduce duplication
60
79
# when doing things like referenced_fields. We should probably
@@ -175,6 +194,9 @@ def make_bcftools_filter_parser(all_fields=None, map_vcf_identifiers=True):
175
194
(pp .Keyword ("&&" ), 2 , pp .OpAssoc .LEFT , BinaryOperator ),
176
195
(pp .Keyword ("|" ), 2 , pp .OpAssoc .LEFT , BinaryOperator ),
177
196
(pp .Keyword ("||" ), 2 , pp .OpAssoc .LEFT , BinaryOperator ),
197
+ # NOTE Putting the Regex operator at the end for now as
198
+ # I haven't figured out what the actual precedence is.
199
+ (pp .one_of ("~ !~" ), 2 , pp .OpAssoc .LEFT , RegexOperator ),
178
200
],
179
201
)
180
202
return filter_expression
0 commit comments