blob: 15268ce8468d2ba63a29a5a9bc76838aab86aa87 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
grammar ApplicabilityGrammar;
options {
ASTLabelType=CommonTree;
output=AST;
}
// START:members
@header {
import java.util.HashMap;
import java.util.Arrays;
import java.util.Collections;
}
@members {
private String applicabilityType = null;
private String id = null;
private HashMap<String, List<String>> id_values_map = new HashMap<>();
private ArrayList<String> operators = new ArrayList<>();
public ArrayList<String> getOperators() {
return operators;
}
public HashMap<String, List<String>> getIdValuesMap() {
return id_values_map;
}
public String getApplicabilityType() {
return applicabilityType;
}
}
start : applicability EOF! { operators.removeAll(Collections.singleton(null)); };
applicability : config_applicability { applicabilityType="Config"; }
| feature_applicability { applicabilityType="Feature"; } ;
config_applicability : 'CONFIGURATION[' expressions+ ']';
feature_applicability : 'FEATURE[' expressions+ ']' ;
expressions : (operator? expression) { operators.add($operator.text); };
expression : ID { id = $ID.text.trim();
id_values_map.put(id, new ArrayList<String>());
}
('=' temp=val)? { if($temp.text == null) {
id_values_map.put(id, Arrays.asList("Default"));
}
};
val : value | start_compound ;
start_compound : '(' { id_values_map.get(id).add("("); }
compound_value
')' { id_values_map.get(id).add(")"); };
compound_value : value+ | multiple_compounds;
multiple_compounds : start_compound
operator { id_values_map.get(id).add($operator.text); }
compound_value;
value : temp=operator? ID {
if($temp.text != null)
id_values_map.get(id).add($temp.text);
id_values_map.get(id).add($ID.text.trim());
};
operator : AND | OR;
OR : '|';
AND : '&';
ID : ('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'-'|' ')* ;
WS : (' '|'\r'|'\t'|'\n')+ {$channel=HIDDEN;};
|