This repository has been archived by the owner on Dec 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathls.go
88 lines (71 loc) · 1.79 KB
/
ls.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
package antlr4512
//import "fmt"
/*
LDAPSyntax implements RFC 4512 Section 4.1.5.
*/
type LDAPSyntax struct {
OID string
Macro []string
Desc string
Extensions map[string][]string
}
/*
LDAPSyntaxes is an instance of slices of [LDAPSyntax] instances.
*/
type LDAPSyntaxes []LDAPSyntax
func newLDAPSyntax() LDAPSyntax {
return LDAPSyntax{
Extensions: make(map[string][]string, 0),
}
}
/*
ParseLDAPSyntax processes raw into an instance of [LDAPSyntax],
which is returned alongside an error.
*/
func ParseLDAPSyntax(raw string) (ls LDAPSyntax, err error) {
var i Instance
if i, err = ParseInstance(raw); err != nil {
return
}
ls = newLDAPSyntax()
// Ensure what went in matches precisely what came out
x := i.P.LDAPSyntaxDescription()
if err = ls.process(x); err == nil {
ptext := x.GetText()
if raw != ptext {
err = errorf("Inconsistent %T parse results or bad content", ls)
}
}
return
}
func (r *LDAPSyntax) process(ctx ILDAPSyntaxDescriptionContext) (err error) {
if err = parenContext(ctx.OpenParen(), ctx.CloseParen()); err != nil {
return
}
for k, ct := 0, ctx.GetChildCount(); k < ct && err == nil; k++ {
switch tv := ctx.GetChild(k).(type) {
case *NumericOIDOrMacroContext:
r.OID, r.Macro, err = numOIDContext(tv)
case *ExtensionsContext,
*DescriptionContext:
err = r.setMisc(tv)
default:
err = isErrImpl(`ldapSyntax`, r.OID, tv)
}
}
if len(r.OID) == 0 && len(r.Macro) == 0 {
err = errorf("Neither OID nor Macro literals found in %T", r)
}
return
}
func (r *LDAPSyntax) setMisc(ctx any) (err error) {
switch tv := ctx.(type) {
case *DescriptionContext:
r.Desc, err = descContext(tv)
case *ExtensionsContext:
r.Extensions, err = extContext(tv)
default:
err = errorf("Unknown miscellaneous context '%T'", ctx)
}
return
}