MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / parseField

Method parseField

pkg/filter/ql/parser.go:428–465  ·  view source on GitHub ↗

parseField parses the field and its argument. This method assumes the field name has been consumed.

(name string)

Source from the content-addressed store, hash-verified

426// parseField parses the field and its argument. This method
427// assumes the field name has been consumed.
428func (p *Parser) parseField(name string) (*FieldLiteral, error) {
429 argument := fields.ArgumentOf(name)
430
431 // parse field argument
432 tok, pos, lit := p.scan()
433 if tok == LBracket {
434 arg, pos, lit := p.scan()
435 if arg != Ident && arg != Integer {
436 return nil, newParseError(tokstr(arg, lit), []string{"ident", "integer"}, pos, p.expr)
437 }
438
439 // field argument given, but the field doesn't require one
440 if argument == nil {
441 return nil, newParseError(tokstr(tok, lit), []string{"field without argument"}, pos, p.expr)
442 }
443
444 // validate argument
445 if argument != nil && !argument.Validate(lit) {
446 exp := fmt.Sprintf("a valid field argument matching the pattern %s", argument.Pattern)
447 return nil, newParseError(tokstr(arg, lit), []string{exp}, pos, p.expr)
448 }
449
450 if tok, pos, lit := p.scan(); tok != RBracket {
451 return nil, newParseError(tokstr(tok, lit), []string{"]"}, pos, p.expr)
452 }
453
454 return &FieldLiteral{Value: name, Field: fields.Field(name), Arg: lit}, nil
455 } else {
456 // unscan lbracket
457 p.unscan()
458 // field argument not given, but it is required
459 if argument != nil && !argument.Optional {
460 return nil, newParseError(tokstr(tok, lit), []string{"field argument"}, pos, p.expr)
461 }
462
463 return &FieldLiteral{Value: name, Field: fields.Field(name)}, nil
464 }
465}
466
467// parseList parses the list of strings. This method assumes the
468// LPAREN token has been consumed.

Callers 2

ParseSequenceMethod · 0.95
parseUnaryExprMethod · 0.95

Calls 7

scanMethod · 0.95
unscanMethod · 0.95
ArgumentOfFunction · 0.92
FieldTypeAlias · 0.92
newParseErrorFunction · 0.85
tokstrFunction · 0.85
ValidateMethod · 0.45

Tested by

no test coverage detected