MCPcopy Create free account
hub / github.com/dolthub/doltgresql / Or

Method Or

testing/generation/utils/generator_stack.go:66–104  ·  view source on GitHub ↗

Or will take all items from the current depth and add them to a parent OrGen. Either the previous depth is an OrGen, or the stack will increment the sub depth to insert an OrGen.

()

Source from the content-addressed store, hash-verified

64// Or will take all items from the current depth and add them to a parent OrGen. Either the previous depth is an OrGen,
65// or the stack will increment the sub depth to insert an OrGen.
66func (sgs *StatementGeneratorStack) Or() error {
67 if sgs.stack.Empty() {
68 return errors.Errorf("cannot apply Or to an empty stack")
69 }
70 parentElement := sgs.stack.PeekDepth(1)
71 current := sgs.aggregate(sgs.stack.Pop().generators)
72 if parentElement == nil {
73 // We're the root, so we put an OrGen as the root, and make the current a child of the new OrGen
74 sgs.stack.Push(NewStatementGeneratorStackElement(sgs.depth, Or(current)))
75 sgs.stack.Push(NewStatementGeneratorStackElement(sgs.depth))
76 } else if len(parentElement.generators) == 0 {
77 if parentElement.depth == sgs.depth {
78 // We're still at the same depth, so it's safe to append an OrGen
79 parentElement.Append(Or(current))
80 } else {
81 // We should retain the depth, so we need to create a new element since there's a depth boundary
82 sgs.stack.Push(NewStatementGeneratorStackElement(sgs.depth, Or(current)))
83 }
84 sgs.stack.Push(NewStatementGeneratorStackElement(sgs.depth))
85 } else {
86 if parentElement.depth == sgs.depth {
87 // We're still at the same depth, so we need to check if the parent is an OrGen or not
88 if orGen, ok := parentElement.LastGenerator().(*OrGen); ok {
89 // The parent is an OrGen, so we can simply add this as another option
90 if err := orGen.AddChildren(current); err != nil {
91 return err
92 }
93 } else {
94 // The parent is not an OrGen, so we need to add to the depth
95 sgs.stack.Push(NewStatementGeneratorStackElement(sgs.depth, Or(current)))
96 }
97 } else {
98 // We should retain the depth, so we need to create a new element since there's a depth boundary
99 sgs.stack.Push(NewStatementGeneratorStackElement(sgs.depth, Or(current)))
100 }
101 sgs.stack.Push(NewStatementGeneratorStackElement(sgs.depth))
102 }
103 return nil
104}
105
106// NewScope increases the depth.
107func (sgs *StatementGeneratorStack) NewScope() {

Callers 1

ParseTokensFunction · 0.95

Calls 11

aggregateMethod · 0.95
PeekDepthMethod · 0.80
PopMethod · 0.80
PushMethod · 0.80
LastGeneratorMethod · 0.80
OrFunction · 0.70
ErrorfMethod · 0.65
AddChildrenMethod · 0.65
EmptyMethod · 0.45
AppendMethod · 0.45

Tested by

no test coverage detected