forked from sleepinggenius2/gosmi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompliance.go
97 lines (77 loc) · 3.84 KB
/
compliance.go
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package parser
import (
"github.com/alecthomas/participle/lexer"
"github.com/sleepinggenius2/gosmi/types"
)
type AgentCapabilityVariation struct {
Pos lexer.Position
Name types.SmiIdentifier `parser:"\"VARIATION\" @Ident"` // Required
Syntax *Syntax `parser:"( \"SYNTAX\" @@ )?"`
WriteSyntax *Syntax `parser:"( \"WRITE-SYNTAX\" @@ )?"`
Access *Access `parser:"( \"ACCESS\" @( \"write-only\" | \"not-implemented\" | \"accessible-for-notify\" | \"read-only\" | \"read-write\" | \"read-create\" ) )?"`
Creation []types.SmiIdentifier `parser:"( \"CREATION-REQUIRES\" \"{\" @Ident ( \",\" @Ident )* \",\"? \"}\" )?"`
Defval *string `parser:"( \"DEFVAL\" \"{\" @( \"-\"? Int | BinString | HexString | Text | Ident | ( \"{\" ( Int+ | ( Ident ( \",\" Ident )* \",\"? )? ) \"}\" ) ) \"}\" )?"`
Description string `parser:"\"DESCRIPTION\" @Text"` // Required
}
type AgentCapabilityModule struct {
Pos lexer.Position
Module types.SmiIdentifier `parser:"\"SUPPORTS\" @Ident"` // Required
Includes []types.SmiIdentifier `parser:"\"INCLUDES\" \"{\" @Ident ( \",\" @Ident )* \",\"? \"}\""` // Required
Variations []AgentCapabilityVariation `parser:"@@*"`
}
type AgentCapabilities struct {
Pos lexer.Position
ProductRelease string `parser:"\"PRODUCT-RELEASE\" @Text"` // Required
Status Status `parser:"\"STATUS\" @( \"current\" | \"deprecated\" | \"obsolete\" )"` // Required - RFC1444 Section 5.2 defines "deprecated" value
Description string `parser:"\"DESCRIPTION\" @Text"` // Required
Reference string `parser:"( \"REFERENCE\" @Text )?"`
Modules []AgentCapabilityModule `parser:"@@*"`
}
type ComplianceGroup struct {
Pos lexer.Position
Name types.SmiIdentifier `parser:"\"GROUP\" @Ident"`
Description string `parser:"\"DESCRIPTION\" @Text"`
}
type ComplianceObject struct {
Pos lexer.Position
Name types.SmiIdentifier `parser:"\"OBJECT\" @Ident"`
Syntax *Syntax `parser:"( \"SYNTAX\" @@ )?"`
WriteSyntax *Syntax `parser:"( \"WRITE-SYNTAX\" @@ )?"`
MinAccess *Access `parser:"( \"MIN-ACCESS\" @( \"not-accessible\" | \"accessible-for-notify\" | \"read-only\" | \"read-write\" | \"read-create\" ) )?"`
Description string `parser:"\"DESCRIPTION\" @Text"`
}
type Compliance struct {
Pos lexer.Position
Group *ComplianceGroup `parser:"@@"`
Object *ComplianceObject `parser:"| @@"`
}
type ComplianceModuleName string
func (n *ComplianceModuleName) Parse(lex *lexer.PeekingLexer) error {
token, err := lex.Peek(0)
if err != nil {
return err
}
if token.Type == smiLexer.Symbols()["Assign"] || token.Value == "MANDATORY-GROUPS" || token.Value == "GROUP" || token.Value == "OBJECT" {
*n = ""
return nil
}
token, err = lex.Next()
if err != nil {
return err
}
*n = ComplianceModuleName(token.Value)
return nil
}
type ModuleComplianceModule struct {
Pos lexer.Position
Name ComplianceModuleName `parser:"@@"`
MandatoryGroups []types.SmiIdentifier `parser:"( \"MANDATORY-GROUPS\" \"{\" @Ident ( \",\" @Ident )* \",\"? \"}\" )?"`
Compliances []Compliance `parser:"@@*"`
}
type ModuleCompliance struct {
Pos lexer.Position
Status Status `parser:"\"STATUS\" @( \"current\" | \"deprecated\" | \"obsolete\" )"` // Required - RFC1444 Section 4.1 defines "deprecated" value
Description string `parser:"\"DESCRIPTION\" @Text"` // Required
Reference string `parser:"( \"REFERENCE\" @Text )?"`
Modules []ModuleComplianceModule `parser:"( \"MODULE\" @@ )+"`
}