MCPcopy Create free account
hub / github.com/brimdata/super / matchPrimitive

Method matchPrimitive

sup/parser-values.go:162–216  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

160}
161
162func (p *Parser) matchPrimitive() (*ast.Primitive, error) {
163 if val, err := p.matchStringPrimitive(); val != nil || err != nil {
164 return val, noEOF(err)
165 }
166 l := p.lexer
167 if err := l.skipSpace(); err != nil {
168 return nil, noEOF(err)
169 }
170 s, err := l.peekPrimitive()
171 if err != nil {
172 return nil, noEOF(err)
173 }
174 if s == "" {
175 return nil, nil
176 }
177 // Try to parse the string different ways. This is not intended
178 // to be performant. CSUP/BSUP provides performance for the Super data model.
179 var typ string
180 if s == "true" || s == "false" {
181 typ = "bool"
182 } else if s == "null" {
183 typ = "null"
184 } else if _, err := strconv.ParseInt(s, 10, 64); err == nil {
185 typ = "int64"
186 } else if _, err := strconv.ParseUint(s, 10, 64); err == nil {
187 typ = "uint64"
188 } else if _, err := strconv.ParseFloat(s, 64); err == nil {
189 typ = "float64"
190 } else if _, err := time.Parse(time.RFC3339Nano, s); err == nil {
191 typ = "time"
192 } else if _, err := nano.ParseDuration(s); err == nil {
193 typ = "duration"
194 } else if _, err := netip.ParsePrefix(s); err == nil {
195 typ = "net"
196 } else if _, err := netip.ParseAddr(s); err == nil {
197 typ = "ip"
198 } else if len(s) >= 2 && s[0:2] == "0x" {
199 if len(s) == 2 {
200 typ = "bytes"
201 } else if _, err := hex.DecodeString(s[2:]); err == nil {
202 typ = "bytes"
203 } else {
204 return nil, err
205 }
206 } else {
207 // no match
208 return nil, nil
209 }
210 l.skip(len(s))
211 return &ast.Primitive{
212 Kind: "Primitive",
213 Type: typ,
214 Text: s,
215 }, nil
216}
217
218func (p *Parser) matchStringPrimitive() (*ast.Primitive, error) {
219 s, ok, err := p.matchString()

Callers 1

matchValueMethod · 0.95

Calls 7

matchStringPrimitiveMethod · 0.95
ParseDurationFunction · 0.92
skipSpaceMethod · 0.80
peekPrimitiveMethod · 0.80
ParseMethod · 0.80
noEOFFunction · 0.70
skipMethod · 0.45

Tested by

no test coverage detected