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

Method matchTypeUnion

sup/parser-types.go:320–353  ·  view source on GitHub ↗
(first ast.Type)

Source from the content-addressed store, hash-verified

318}
319
320func (p *Parser) matchTypeUnion(first ast.Type) (*ast.TypeUnion, error) {
321 l := p.lexer
322 var types []ast.Type
323 if first != nil {
324 types = append(types, first)
325 }
326 for {
327 typ, err := p.matchTypeComponent()
328 if err != nil {
329 return nil, err
330 }
331 if typ == nil {
332 break
333 }
334 types = append(types, typ)
335 ok, err := l.match('|')
336 if noEOF(err) != nil {
337 return nil, err
338 }
339 if !ok {
340 break
341 }
342 }
343 if len(types) < 2 {
344 if ok, _ := l.match(','); ok {
345 return nil, errors.New("union components are separated by pipe symbol (|) not comma")
346 }
347 return nil, errors.New("union type must include two or more types")
348 }
349 return &ast.TypeUnion{
350 Kind: "TypeUnion",
351 Types: types,
352 }, nil
353}
354
355func (p *Parser) matchTypeEnumBody() (*ast.TypeEnum, error) {
356 l := p.lexer

Callers 1

matchTypeMethod · 0.95

Calls 4

matchTypeComponentMethod · 0.95
NewMethod · 0.80
noEOFFunction · 0.70
matchMethod · 0.45

Tested by

no test coverage detected