Skip to content

Commit 66e1475

Browse files
committed
Initial obsolete conformance
1 parent 24a253a commit 66e1475

5 files changed

Lines changed: 795 additions & 731 deletions

File tree

matter/conformance/conformance_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,18 @@ var conformanceTests = []conformanceTestSuite{
456456
Conformance: "AA | [BB]",
457457
InvalidConformance: true,
458458
},
459+
{
460+
Conformance: "AA, P",
461+
InvalidConformance: true,
462+
},
463+
{
464+
Conformance: "D",
465+
InvalidConformance: true,
466+
},
467+
{
468+
Conformance: "AA, D, [BB]",
469+
InvalidConformance: true,
470+
},
459471
{
460472
Conformance: "AA, [BB]",
461473
Tests: []conformanceTest{

matter/conformance/grammar/conformance.peg

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,31 @@ Input <- conf:Conformance+ EOF {
2020
cs := conf.([]interface{})
2121

2222
var set Set
23-
for _, i := range cs {
24-
con := i.(Conformance)
23+
for i, e := range cs {
24+
con := e.(Conformance)
25+
switch con.(type) {
26+
case *Provisional:
27+
if i != 0 {
28+
return nil, fmt.Errorf("provisionality set at index %d; provisional annotations must be the first element of conformance", i)
29+
}
30+
case *Deprecated:
31+
if i == 0 || i != len(cs) - 1 {
32+
return nil, fmt.Errorf("deprecation set at index %d; deprecation annotations must be the last element in a set of conformances", i)
33+
}
34+
case *Obsolete:
35+
if i != len(cs) - 1 {
36+
return nil, fmt.Errorf("obsolete set at index %d; obsolete annotations must appear alone, or be the last element in a set of conformances", i)
37+
}
38+
39+
}
2540
set = append(set, con)
2641
}
2742
return set, nil
2843
}
2944

3045
ConformanceSeparator <- (_ Comma _) / &EOF
3146

32-
Conformance <- '[' i:Expression ']' choice:Choice? ConformanceSeparator {
47+
Conformance <- '[' i:LogicalExpression ']' choice:Choice? ConformanceSeparator {
3348
exp := i.(Expression)
3449
o := &Optional{Expression:exp}
3550
if choice != nil {
@@ -51,14 +66,15 @@ Conformance <- '[' i:Expression ']' choice:Choice? ConformanceSeparator {
5166
return &Deprecated{}, nil
5267
} / 'X' ConformanceSeparator {
5368
return &Disallowed{}, nil
69+
} / 'Z' ConformanceSeparator {
70+
return &Obsolete{}, nil
71+
}
5472
} / "desc" ConformanceSeparator {
5573
return &Described{}, nil
56-
} / eq:Expression ConformanceSeparator {
74+
} / eq:LogicalExpression ConformanceSeparator {
5775
exp := eq.(Expression)
5876
return &Mandatory{Expression:exp}, nil
5977
}
6078

61-
Expression <- LogicalExpression
62-
6379

6480

matter/conformance/grammar/logical.peg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ AndOp <- _ "&" _ f:LogicalTerm {
5858
return fc, nil
5959
}
6060

61-
LogicalTerm <- not:'!'? '(' _ eq:Expression _ ')' {
61+
LogicalTerm <- not:'!'? '(' _ eq:LogicalExpression _ ')' {
6262
//debug("matched feature term %s\n", string(c.text))
6363
if not != nil {
6464
switch eq := eq.(type) {

matter/conformance/obsolete.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package conformance
2+
3+
type Obsolete struct {
4+
raw string
5+
}
6+
7+
func (d *Obsolete) Type() Type {
8+
return TypeDeprecated
9+
}
10+
11+
func (d *Obsolete) RawText() string {
12+
return d.raw
13+
}
14+
15+
func (d *Obsolete) ASCIIDocString() string {
16+
return "Z"
17+
}
18+
19+
func (d *Obsolete) Description() string {
20+
return "obsolete"
21+
}
22+
23+
func (d *Obsolete) Eval(context Context) (ConformanceState, error) {
24+
return ConformanceState{State: StateDeprecated, Confidence: ConfidenceDefinite}, nil
25+
}
26+
27+
func (d *Obsolete) Equal(c Conformance) bool {
28+
_, ok := c.(*Obsolete)
29+
return ok
30+
}
31+
32+
func (d *Obsolete) Clone() Conformance {
33+
return &Obsolete{raw: d.raw}
34+
}

0 commit comments

Comments
 (0)