MCPcopy
hub / github.com/kashav/fsql / parseCondition

Method parseCondition

parser/condition.go:102–174  ·  view source on GitHub ↗

parseCondition parses and returns the next condition.

()

Source from the content-addressed store, hash-verified

100
101// parseCondition parses and returns the next condition.
102func (p *parser) parseCondition() (*query.Condition, error) {
103 cond := &query.Condition{}
104
105 // If we find a NOT, negate the condition.
106 if p.expect(tokenizer.Not) != nil {
107 cond.Negate = true
108 }
109
110 ident := p.expect(tokenizer.Identifier)
111 if ident == nil {
112 return nil, p.currentError()
113 }
114 p.current = ident
115
116 var modifiers []query.Modifier
117 attr, err := p.parseAttr(&modifiers)
118 if err != nil {
119 return nil, err
120 }
121 cond.Attribute = attr.Raw
122 cond.AttributeModifiers = modifiers
123
124 // If this condition has modifiers, then p.current was unset while parsing
125 // the modifier, se we set the current token manually.
126 if len(modifiers) > 0 {
127 p.current = p.tokenizer.Next()
128 }
129 if p.current == nil {
130 return nil, p.currentError()
131 }
132 cond.Operator = p.current.Type
133 p.current = nil
134
135 // Parse subquery of format `(...)`.
136 if p.expect(tokenizer.OpenParen) != nil {
137 token := p.expect(tokenizer.Subquery)
138 if token == nil {
139 return nil, p.currentError()
140 }
141 cond.IsSubquery = true
142 cond.Value = token.Raw
143 if p.expect(tokenizer.CloseParen) == nil {
144 return nil, p.currentError()
145 }
146 return cond, nil
147 }
148
149 // Parse list of values of format `[...]`.
150 if p.expect(tokenizer.OpenBracket) != nil {
151 values := make([]string, 0)
152 for {
153 if token := p.expect(tokenizer.Identifier); token != nil {
154 values = append(values, token.Raw)
155 }
156 if p.expect(tokenizer.Comma) != nil {
157 continue
158 }
159 if p.expect(tokenizer.CloseBracket) != nil {

Calls 4

expectMethod · 0.95
currentErrorMethod · 0.95
parseAttrMethod · 0.95
NextMethod · 0.80