This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bind.go
1137 lines (949 loc) · 30 KB
/
bind.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package aci
/*
bind.go contains bind rule(s) types, functions and methods.
*/
var (
badBindRule BindRule
badBindRules BindRules
)
/*
BindRuleMethods contains one (1) or more instances of [BindRuleMethod], representing a particular [BindRule] "builder" method for execution by the caller.
See the Operators method extended through all eligible types for further details.
*/
type BindRuleMethods struct {
*bindRuleFuncMap
}
/*
newBindRuleMethods populates an instance of *bindRuleFuncMap, which
is embedded within the return instance of BindRuleMethods.
*/
func newBindRuleMethods(m bindRuleFuncMap) BindRuleMethods {
M := make(bindRuleFuncMap, len(m))
for k, v := range m {
M[k] = v
}
return BindRuleMethods{&M}
}
/*
Index calls the input index (idx) within the internal structure of the receiver instance. If found, an instance of [ComparisonOperator] and its accompanying [BindRuleMethod] instance are returned.
Valid input index types are integer (int), [ComparisonOperator] constant or string identifier. In the case of a string identifier, valid values are as follows:
- For Eq (1): `=`, `Eq`, `Equal To`
- For Ne (2): `=`, `Ne`, `Not Equal To`
- For Lt (3): `=`, `Lt`, `Less Than`
- For Le (4): `=`, `Le`, `Less Than Or Equal`
- For Gt (5): `=`, `Gt`, `Greater Than`
- For Ge (6): `=`, `Ge`, `Greater Than Or Equal`
Case is not significant in the string matching process.
Please note that use of this method by way of integer or [ComparisonOperator] values utilizes fewer resources than a string lookup.
See the [ComparisonOperator.Context], [ComparisonOperator.String] and [ComparisonOperator.Description] methods for accessing the above string values easily.
If the index was not matched, an invalid [ComparisonOperator] is returned alongside a nil [BindRuleMethod]. This will also apply to situations in which the type instance which crafted the receiver is uninitialized, or is in an otherwise aberrant state.
*/
func (r BindRuleMethods) Index(idx any) (ComparisonOperator, BindRuleMethod) {
return r.index(idx)
}
/*
index is a private method called by BindRuleMethods.Index.
*/
func (r BindRuleMethods) index(idx any) (cop ComparisonOperator, meth BindRuleMethod) {
if r.IsZero() {
return
}
cop = badCop
// perform a type switch upon the input
// index type
switch tv := idx.(type) {
case ComparisonOperator:
// cast cop as an int, and make recursive
// call to this function.
return r.Index(int(tv))
case int:
// there are only six (6) valid
// operators, numbered one (1)
// through six (6).
//
// this is an unnecessary cyclomatic
// complexity factor.
//if !isValidCopNumeral(tv) {
// return
//}
var found bool
if meth, found = (*r.bindRuleFuncMap)[ComparisonOperator(tv)]; found {
cop = ComparisonOperator(tv)
return
}
case string:
cop, meth = rangeBindRuleFuncMap(tv, r.bindRuleFuncMap)
}
return
}
func rangeBindRuleFuncMap(candidate string, fm *bindRuleFuncMap) (cop ComparisonOperator, meth BindRuleMethod) {
// iterate all map entries, and see if
// input string value matches the value
// returned by these three (3) methods:
for k, v := range *fm {
if strInSliceFold(candidate, []string{
k.String(), // e.g.: "="
k.Context(), // e.g.: "Eq"
k.Description(), // e.g.: "Equal To"
}) {
cop = k
meth = v
break
}
}
return
}
/*
BR wraps the [stackage.Cond] package-level function. In this context, it is wrapped here to assemble and return a [BindRule] instance using the so-called "one-shot" procedure. This is an option only when ALL information necessary for the process is in-hand and ready for user input: the [BindKeyword], [ComparisonOperator] and the appropriate value(s) expression.
Use of this function shall not require a subsequent call of [BindRule]'s Init method, which is needed only for so-called "piecemeal" [BindRule] assembly.
Use of this function is totally optional. Users may, instead, opt to populate the specific value instance(s) needed and execute the type's own Eq, Ne, Ge, Gt, Le and Lt methods (when applicable) to produce an identical return instance. Generally speaking, those methods may prove to be more convenient -- and far safer -- than use of this function.
*/
func BR(kw, op, ex any) BindRule {
return newBindRule(kw, op, ex)
}
/*
newBindRule is a private package-level function called by the BR
package-level function.
*/
func newBindRule(kw, op, ex any) (b BindRule) {
b.Init()
b.SetKeyword(kw).
SetOperator(op).
SetExpression(ex)
b.cast().
Encap(`"`).
SetID(bindRuleID).
NoPadding(!RulePadding)
return
}
/*
Init wraps stackage.Condition's Init method. This is a required method for situations involving the piecemeal (step-by-step) assembly of an instance of [BindRule] as opposed to a one-shot creation using the [BR] package-level function. It is also an ideal means for the creation of a [BindRule] instance when one does not immediately possess all of the needed pieces of information (i.e.: uncertain which keyword to use, or when an expression value has not yet been determined, etc).
Call this method after a variable declaration but before your first change, e.g.:
var br BindRule
... do other things ...
... we're ready to set something now ...
br.Init()
br.SetKeyword("blarg")
br.SetSomethingElse(...)
...
Init need only be executed once within the lifespan of a [BindRule] instance. Its execution shall result in a completely new embedded pointer instance supplanting the previous one.
One may choose, however, to re-execute this method IF this instance shall be reused (perhaps in a repetative or looped manner), and if it would be desirable to 'wipe the slate clean' for some reason.
*/
func (r *BindRule) Init() BindRule {
_r := r.cast()
if _r.IsZero() || !_r.IsInit() {
_r.Init()
}
*r = BindRule(_r)
return *r
}
/*
Contains returns a Boolean value indicative of whether the specified [ComparisonOperator], which may be expressed as a string, int or native [ComparisonOperator], is allowed for use by the type instance that created the receiver instance. This method offers a convenient alternative to the use of the Index method combined with an assertion value (such as Eq, Ne, "=", "Greater Than", et al).
In other words, if one uses the [FQDN]'s BRM method to create an instance of [BindRuleMethods], feeding Gt (Greater Than) to this method shall return false, as mathematical comparison does not apply to instances of the [FQDN] type.
*/
func (r BindRuleMethods) Contains(cop any) bool {
c, _ := r.index(cop)
return c.Valid() == nil
}
/*
IsZero returns a Boolean value indicative of whether the receiver is nil, or unset.
*/
func (r BindRuleMethods) IsZero() bool {
return r.bindRuleFuncMap == nil
}
/*
Valid returns the first encountered error returned as a result of execution of the first available [BindRuleMethod] instance. This is useful in cases where a user wants to see if the desired instance(s) of [BindRuleMethod] will produce a usable result.
*/
func (r BindRuleMethods) Valid() (err error) {
if r.IsZero() {
err = nilInstanceErr(r)
return
}
// Eq is always available for all eligible
// types, so let's use that unconditionally.
// If any one method works, then all of them
// will work.
_, meth := r.Index(Eq)
err = meth().Valid()
return
}
/*
Len returns the integer length of the receiver. Note that the return value will NEVER be less than zero (0) nor greater than six (6).
*/
func (r BindRuleMethods) Len() int {
if r.IsZero() {
return 0
}
return len((*r.bindRuleFuncMap))
}
/*
BindRuleMethod is the closure signature for methods used to build new instances of [BindRule].
The signature is qualified by the following methods extended through all eligible types defined in this package:
- Eq
- Ne
- Lt
- Le
- Gt
- Ge
Note that certain types only support a subset of the above list. Very few types support all of the above.
*/
type BindRuleMethod func() BindRule
/*
bindRuleFuncMap is a private type intended to be used within instances of [BindRuleMethods].
*/
type bindRuleFuncMap map[ComparisonOperator]BindRuleMethod
func (r BindRule) isBindContextQualifier() {}
/*
Traverse returns the receiver instance. This method only exists to satisfy Go's interface signature requirements for the [BindContext] interface. See [BindRules] Traverse method instead.
*/
func (r BindRule) Traverse(indices ...int) BindContext {
return r
}
/*
Index returns the receiver instance. This method only exists to satisfy Go's interface signature requirements for the [BindContext] interface. See [BindRules] Index method instead.
*/
func (r BindRule) Index(_ int) BindContext {
return r
}
/*
Compare returns a Boolean value indicative of a SHA-1 comparison between the receiver (r) and input value x.
*/
func (r BindRule) Compare(x any) bool {
return compareHashInstance(r, x)
}
/*
Kind returns the string literal `condition` to identify the receiver as a [stackage.Condition] type alias.
*/
func (r BindRule) Kind() string {
return `condition`
}
/*
Len does not perform any useful task, and exists only to satisfy Go's interface signature requirements and to convey this message.
A value of zero (0) is returned if the receiver instance is nil. A value of one (1) otherwise.
*/
func (r BindRule) Len() int {
if r.IsZero() {
return 0
}
return 1
}
/*
IsNesting does not perform any useful task, and exists only to satisfy Go's interface signature requirements and to convey this message.
A Boolean value of false is returned in any scenario.
*/
func (r BindRule) IsNesting() bool {
return false
}
/*
Paren wraps the [stackage.Condition.Paren] method.
*/
func (r BindRule) Paren(state ...bool) BindRule {
r.cast().Paren(state...)
return r
}
/*
IsParen wraps the [stackage.Condition.IsParen] method.
*/
func (r BindRule) IsParen() bool {
return r.cast().IsParen()
}
/*
Valid wraps the [stackage.Condition.Valid] method.
*/
func (r BindRule) Valid() (err error) {
if r.IsZero() {
err = nilInstanceErr(r)
return
}
err = r.cast().Valid()
return
}
/*
ID wraps the [stackage.Stack.ID] method.
*/
func (r BindRule) ID() string {
if r.IsZero() {
return bindRuleID
}
return r.cast().ID()
}
/*
Category wraps the [stackage.Stack.Category] method.
*/
func (r BindRule) Category() string {
if r.IsZero() {
return ``
}
return r.Keyword().String()
}
/*
String is a stringer method that returns the string representation of the receiver instance.
This method wraps the [stackage.Condition.String] method.
*/
func (r BindRule) String() string {
if r.IsZero() {
return ``
}
return r.cast().String()
}
/*
NoPadding wraps the [stackage.Condition.NoPadding] method.
*/
func (r BindRule) NoPadding(state ...bool) BindRule {
if r.IsZero() {
return r
}
r.cast().NoPadding(state...)
return r
}
/*
Keyword wraps the [stackage.Condition.Keyword] method and resolves the raw value into a [BindKeyword]. Failure to do so will return a bogus [Keyword].
*/
func (r BindRule) Keyword() Keyword {
k := r.cast().Keyword()
var kw any = matchBKW(k)
return kw.(BindKeyword)
}
/*
Operator wraps the [stackage.Condition.Operator] method and casts the [stackage.ComparisonOperator] to the local package [ComparisonOperator].
*/
func (r BindRule) Operator() ComparisonOperator {
return castCop(r.cast().Operator())
}
/*
Expression wraps the [stackage.Condition.Expression] method.
*/
func (r BindRule) Expression() any {
return r.cast().Expression()
}
/*
IsZero wraps the [stackage.Condition.IsZero] method.
*/
func (r BindRule) IsZero() bool {
return r.cast().IsZero()
}
func (r BindRules) isBindContextQualifier() {}
/*
Compare returns a Boolean value indicative of a SHA-1 comparison between the receiver (r) and input value x.
*/
func (r BindRules) Compare(x any) bool {
return compareHashInstance(r, x)
}
/*
Kind returns the string literal `stack` to identify the receiver as a [stackage.Stack] type alias.
*/
func (r BindRules) Kind() string {
return `stack`
}
/*
And returns an instance of [BindRule] configured to express Boolean AND logical operations. Instances of this design contain [BindContext] instances, which are qualified through instances of the following types:
- [BindRule]
- [BindRules]
Optionally, the caller may choose to submit one (1) or more (valid) instances of these types during initialization. This is merely a more convenient alternative to separate initialization and push procedures.
The embedded type within the return is [stackage.Stack] via the [stackage.And] package-level function.
*/
func And(x ...any) (b BindRules) {
// create a native stackage.Stack
// and configure before typecast.
_b := stackAnd().
SetID(bindRuleID).
SetCategory(`and`).
NoPadding(!StackPadding)
// cast _a as a proper BindRules instance
// (b). We do it this way to gain access
// to the method for the *specific instance*
// being created (b), thus allowing things
// like uniqueness checks, etc., to occur
// during push attempts, providing helpful
// and non-generalized feedback.
b = BindRules(_b)
_b.SetPushPolicy(b.pushPolicy)
// Assuming one (1) or more items were
// submitted during the call, (try to)
// push them into our initialized stack.
// Note that any failed push(es) will
// have no impact on the validity of
// the return instance.
_b.Push(x...)
return
}
/*
Or returns an instance of [BindRule] configured to express Boolean OR logical operations. Instances of this design contain [BindContext] instances, which are qualified through instances of the following types:
- [BindRule]
- [BindRules]
Optionally, the caller may choose to submit one (1) or more (valid) instances of these types during initialization. This is merely a more convenient alternative to separate initialization and push procedures.
The embedded type within the return is [stackage.Stack] via the [stackage.Or] package-level function.
*/
func Or(x ...any) (b BindRules) {
// create a native stackage.Stack
// and configure before typecast.
_b := stackOr().
SetID(bindRuleID).
SetCategory(`or`).
NoPadding(!StackPadding)
// cast _a as a proper BindRules instance
// (b). We do it this way to gain access
// to the method for the *specific instance*
// being created (b), thus allowing things
// like uniqueness checks, etc., to occur
// during push attempts, providing helpful
// and non-generalized feedback.
b = BindRules(_b)
_b.SetPushPolicy(b.pushPolicy)
// Assuming one (1) or more items were
// submitted during the call, (try to)
// push them into our initialized stack.
// Note that any failed push(es) will
// have no impact on the validity of
// the return instance.
_b.Push(x...)
return
}
/*
Not returns an instance of [BindRule] configured to express Boolean NOT logical operations. Instances of this design contain [BindContext] instances, which are qualified through instances of the following types:
- [BindRule]
- [BindRules]
Optionally, the caller may choose to submit one (1) or more (valid) instances of these types during initialization. This is merely a more convenient alternative to separate initialization and push procedures.
The embedded type within the return is [stackage.Stack] via the [stackage.Not] package-level function.
*/
func Not(x ...any) (b BindRules) {
// create a native stackage.Stack
// and configure before typecast.
_b := stackNot().
SetID(bindRuleID).
SetCategory(`not`).
NoPadding(!StackPadding)
// cast _a as a proper BindRules instance
// (b). We do it this way to gain access
// to the method for the *specific instance*
// being created (b), thus allowing things
// like uniqueness checks, etc., to occur
// during push attempts, providing helpful
// and non-generalized feedback.
b = BindRules(_b)
_b.SetPushPolicy(b.pushPolicy)
// Assuming one (1) or more items were
// submitted during the call, (try to)
// push them into our initialized stack.
// Note that any failed push(es) will
// have no impact on the validity of
// the return instance.
_b.Push(x...)
return
}
/*
convertBindRulesHierarchy processes the orig input instance and casts
its contents in the following manner:
stackage.Stack --> BindRules
\ \
+- ... + ...
| |
+- stackage.Condition --> +- BindRule
The hierarchy is traversed thoroughly and will handle nested contexts
seamlessly.
This function is called following an apparently successful BindRules
parsing request through the [parser] package.
*/
func convertBindRulesHierarchy(stack any) (BindContext, bool) {
orig, _ := castAsStack(stack)
/*
if orig.Len() == 0 {
return badBindRules, false
}
*/
var clean BindRules
var err error
// Obtain the kind string from the
// original stack.
clean, ok := wordToStack(orig.Kind())
// Iterate the newly-populated clean
// instance, performing type-casting
// as needed, possibly in recursion.
for i := 0; i < orig.Len() && ok && err == nil; i++ {
slice, _ := orig.Index(i)
// perform a type switch upon the
// slice member @ index i. There
// are two (2) valid types we may
// encounter ...
switch {
// slice is a stackage.Condition.
// We want to cast to a BindRule
// instance, and update the string
// value(s) to be housed within a
// value-appropriate type defined
// by the aci package.
case isStackageCondition(slice):
deref := derefC(slice)
ntv := BindRule(deref).
Paren(deref.IsParen())
// Extract individual expression value
// from BindRule (ntv), and recreate it
// using the proper type, replacing the
// original. For example, a User DN Bind
// [BindRule] with an expression value of:
//
// []string{<dn1>,<dn2>,<dn3>}
//
// ... shall be replaced with:
//
// <stack alias type>-idx#------val-
// DistinguishedNames[<N1>] -> <dn1>
// [<N2>] -> <dn2>
// [<N3>] -> <dn3>
if err = ntv.assertExpressionValue(); err == nil {
clean.Push(ntv)
}
// slice is a stackage.Stack instance.
// We want to cast to a BindRules type
// instance, but in order to do that,
// we'll recurse into this same function
// using this slice as the subordinate
// 'orig' input value.
case isStackageStack(slice):
stk, _ := castAsStack(slice)
paren := stk.IsParen()
if sub, subok := convertBindRulesHierarchy(slice); subok {
if _, ok := sub.(BindRules); ok {
sub.(BindRules).Paren(paren)
uncloakBindRules(sub.(BindRules))
}
clean.Push(sub)
continue
}
return badBindRules, false
}
}
// A cheap and easy means of ensuring
// the content really did transfer and
// [re]cast properly, and that nothing
// was missed.
//ok = orig.String() == clean.String()
ok = len(clean.String()) > 0
// uncloak any hidden stacks
uncloakBindRules(clean)
return clean, ok
}
func uncloakBindRules(ctx BindRules) {
for i := 0; i < ctx.Len(); i++ {
if slice := ctx.Index(i); isCloaked(slice) {
stack := uncloak(slice.(BindRules))
ctx.Replace(stack, i)
}
}
}
/*
BUG: testing cornercase for [parser]. Temporary, do not remove yet.
*/
func uncloak(ctx BindRules) BindRules {
stack := ctx.Index(0)
if isCloaked(stack) {
stack = uncloak(stack.(BindRules))
}
return stack.(BindRules)
}
/*
BUG: testing cornercase for [parser]. Temporary, do not remove yet.
*/
func isCloaked(x BindContext) bool {
switch tv := x.(type) {
case BindRules:
if hasSfx(tv.Category(), `not`) || tv.Len() != 1 {
break
}
if tv.Index(0).Kind() == `stack` {
return !tv.IsParen()
}
}
return false
}
func wordToStack(k string) (BindRules, bool) {
// Perform an anonymous switch, allowing
// the evaluation of the Boolean logical
// "disposition" of the (outer) Bind Rules
// instance "kind".
switch {
// Negated (NOT, AND NOT) operator
case hasSfx(uc(k), `NOT`):
return Not(), true
// ANDed operator
case eq(k, `AND`):
return And(), true
// ORed operator
case eq(k, `OR`):
return Or(), true
}
// unsupported operator
return badBindRules, false
}
/*
SetKeyword wraps the [stackage.Condition.SetKeyword] method.
*/
func (r BindRule) SetKeyword(kw any) BindRule {
cac := r.cast()
if !cac.IsInit() {
r.Init()
}
cac.SetKeyword(kw)
return r
}
/*
SetOperator wraps the [stackage.Condition.SetOperator] method.
*/
func (r BindRule) SetOperator(op any) BindRule {
var cop ComparisonOperator
switch tv := op.(type) {
case string:
cop = matchCOP(tv)
case ComparisonOperator:
cop = tv
}
// ALL Target and Bind rules accept Eq,
// so only scrutinize the operator if
// it is something *other than* that.
if cop != Eq {
if !keywordAllowsComparisonOperator(r.Keyword(), op) {
return r
}
}
// operator not known? bail out
if cop == ComparisonOperator(0) {
return r
}
// not initialized? bail out
if !r.cast().IsInit() {
return r
}
// cast to stackage.Condition and
// set operator value.
r.cast().SetOperator(cop)
return r
}
/*
SetExpression wraps the [stackage.Condition.SetExpression] method.
*/
func (r BindRule) SetExpression(expr any) BindRule {
cac := r.cast()
if !cac.IsInit() {
cac.Init()
}
cac.SetExpression(expr)
return r
}
/*
SetQuoteStyle allows the election of a particular multivalued quotation style offered by the various adopters of the ACIv3 syntax. In the context of a [BindRule], this will only have a meaningful impact if the keyword for the receiver is one (1) of the following:
- [BindUDN] (userdn)
- [BindRDN] (roledn)
- [BindGDN] (groupdn)
Additionally, the underlying type set as the expression value within the receiver MUST be a [BindDistinguishedNames] instance with two (2) or more distinguished names within.
See the const definitions for [MultivalOuterQuotes] (default) and [MultivalSliceQuotes] for details.
*/
func (r BindRule) SetQuoteStyle(style int) BindRule {
key := r.Keyword()
switch tv := r.Expression().(type) {
case BindDistinguishedNames:
switch key {
case BindUDN, BindGDN, BindRDN:
tv.setQuoteStyle(style)
}
default:
r.cast().Encap(`"`)
return r
}
// Toggle the individual value quotation scheme
// to the INVERSE of the Stack quotation scheme
// set above.
//
// If MultivalSliceQuotes equals the style set
// by the user, this implies that that no outer
// encapsulation shall be used, thus _r.Encap()
// is called for the receiver.
//
// But the above type instances (TDNs, OIDs, ATs)
// will have the opposite setting imposed, which
// enables quotation for the individual values.
if style == MultivalSliceQuotes {
r.cast().Encap()
} else {
r.cast().Encap(`"`)
}
return r
}
/*
String is a stringer method that returns the string representation of the receiver instance.
This method wraps the [stackage.Stack.String] method.
*/
func (r BindRules) String() string {
return r.cast().String()
}
/*
IsZero wraps the [stackage.Stack.IsZero] method.
*/
func (r BindRules) IsZero() bool {
return r.cast().IsZero()
}
/*
reset wraps the [stackage.Stack.Reset method. This is a private] method in aci.
*/
func (r BindRules) reset() {
r.cast().Reset()
}
/*
ID wraps the [stackage.Stack.ID] method.
*/
func (r BindRules) ID() string {
return bindRuleID
}
/*
Category wraps the [stackage.Stack.Category] method.
*/
func (r BindRules) Category() string {
if r.IsZero() {
return `<uninitialized_bindrules>`
}
return r.cast().Category()
}
/*
Len wraps the [stackage.Stack.Len] method.
*/
func (r BindRules) Len() int {
if r.IsZero() {
return 0
}
return r.cast().Len()
}
/*
IsNesting wraps the [stackage.Stack.IsNesting] method.
*/
func (r BindRules) IsNesting() bool {
if r.IsZero() {
return false
}
return r.cast().IsNesting()
}
/*
Keyword wraps the [stackage.Stack.Category] method and resolves the raw value into a [BindKeyword]. Failure to do so will return a bogus [Keyword].
*/
func (r BindRules) Keyword() Keyword {
var kw any = matchBKW(r.cast().Category())
return kw.(BindKeyword)
}
/*
Push wraps the [stackage.Stack.Push] method.
*/
func (r BindRules) Push(x ...any) BindRules {
r.cast().Push(x...)
return r
}
/*
Pop wraps the [stackage.Stack.Pop] method. An instance of [BindContext], which may or may not be nil, is returned following a call of this method.
Within the context of the receiver type, a [BindContext], if non-nil, can represent any of the following instance types:
- [BindRule]
- [BindRules]
*/
func (r BindRules) Pop() BindContext {
return r.pop()
}
func (r BindRules) pop() (popped BindContext) {
if r.IsZero() {
return nil
}
_popped, _ := r.cast().Pop()
switch tv := _popped.(type) {
case BindRule:
popped = tv
case BindRules:
popped = tv
}
return
}
/*
remove wraps the [stackage.Stack.Remove] method.
*/
func (r BindRules) remove(idx int) (ok bool) {
_, ok = r.cast().Remove(idx)
return
}
/*
Replace wraps the [stackage.Stack.Replace] method.
*/
func (r BindRules) Replace(x any, idx int) BindRules {
return r.replace(x, idx)
}
/*
replace is a private method called by BindRules.Replace as well as certain ANTLR->ACI parsing procedures.
*/
func (r BindRules) replace(x any, idx int) BindRules {
if !r.IsZero() {
r.cast().Replace(x, idx)
}
return r
}
/*
Index wraps the [stackage.Stack.Index] method.
*/
func (r BindRules) Index(idx int) (ctx BindContext) {
y, _ := r.cast().Index(idx)
switch tv := y.(type) {
case BindRule:
ctx = tv
case BindRules:
ctx = tv
}
return
}
/*
ReadOnly wraps the [stackage.Stack.ReadOnly] method.
*/
func (r BindRules) ReadOnly(state ...bool) BindRules {
r.cast().ReadOnly(state...)
return r
}
/*
Paren wraps the [stackage.Stack.Paren] method.
*/
func (r BindRules) Paren(state ...bool) BindRules {
r.cast().Paren(state...)
return r
}
/*
IsParen wraps the [stackage.Stack.IsParen] method.
*/
func (r BindRules) IsParen() bool {
return r.cast().IsParen()
}
/*
Fold wraps the [stackage.Stack.Fold] method to allow the case folding of logical Boolean 'AND', 'OR' and 'AND NOT' WORD operators to 'and', 'or' and 'and not' respectively, or vice versa.
*/
func (r BindRules) Fold(state ...bool) BindRules {
r.cast().Fold(state...)
return r
}
/*
insert wraps the [stackage.Stack.Insert] method.
*/
func (r BindRules) insert(x any, left int) (ok bool) {
switch tv := x.(type) {
case BindRule, BindRules:
ok = r.cast().Insert(tv, left)
}
return
}
/*
NoPadding wraps the [stackage.Stack.NoPadding] method.
*/
func (r BindRules) NoPadding(state ...bool) BindRules {
r.cast().NoPadding(state...)
return r
}