// L7RuleParser parses protobuf L7 rules to and array of Rule
// May panic
357405
func L7RuleParser(rule *cilium.PortNetworkPolicyRule) []proxylib.L7NetworkPolicyRule {
	var rules []proxylib.L7NetworkPolicyRule
	l7Rules := rule.GetL7Rules()
	if l7Rules == nil {
		return rules
	}
	for _, l7Rule := range l7Rules.GetL7Rules() {
		var br Rule
		var commandFound = false
		for k, v := range l7Rule.Rule {
			switch k {
			case "command":
				br.commands, commandFound = MemcacheOpCodeMap[v]
			case "keyExact":
				br.keyExact = []byte(v)
			case "keyPrefix":
				br.keyPrefix = []byte(v)
			case "keyRegex":
				br.regex = regexp.MustCompile(v)
			default:
				proxylib.ParseError(fmt.Sprintf("Unsupported key: %s", k), rule)
			}
		}
		if !commandFound {
			if len(br.keyExact) > 0 || len(br.keyPrefix) > 0 || br.regex != nil {
				proxylib.ParseError("command not specified but key was provided", rule)
			} else {
				br.empty = true
			}
		}
		log.Debugf("Parsed Rule pair: %v", br)
		rules = append(rules, &br)
	}
	return rules
}
340622
func NewRule() *Rule {
	return &Rule{
		SuppressIfgroup:   -1,
		SuppressPrefixlen: -1,
		Priority:          -1,
		Mark:              -1,
		Mask:              -1,
		Goto:              -1,
		Flow:              -1,
	}
}
1237088
func ParseLevel(lvl string) (Level, error) {
	switch strings.ToLower(lvl) {
	case "panic":
		return PanicLevel, nil
	case "fatal":
		return FatalLevel, nil
	case "error":
		return ErrorLevel, nil
	case "warn", "warning":
		return WarnLevel, nil
	case "info":
		return InfoLevel, nil
	case "debug":
		return DebugLevel, nil
	case "trace":
		return TraceLevel, nil
	}

	var l Level
	return l, fmt.Errorf("not a valid logrus Level: %q", lvl)
}
517470
func ParseFile(file string) (*Rules, error) {
	f, err := os.Open(file)
	if err != nil {
		return nil, err
	}
	defer f.Close()
	return Parse(f)
}
617963
func ParsePager(pager TokenPager) (Node, error) {
	t := newTree(pager)
	// Parser panics on unexpected syntax, convert this into an err
	return t.parse()
}
308415
func NewParser(raw []string) (p *Parser, sub string) {
	if len(raw) < 1 {
		panic("Must use a subcommand")
	}
	p = &Parser{make(map[string]Flag), make([]string, 0)}
	sub = raw[0]
	i := 1
	for i < len(raw) {
		switch {
		case strings.HasPrefix(raw[i], "--"):
			pieces := strings.Split(raw[i], "=")
			if len(pieces) == 1 {
				p.flags[strings.TrimPrefix(pieces[0], "--")] = Flag{Long, ""}
			} else {
				p.flags[strings.TrimPrefix(pieces[0], "--")] = Flag{Long, pieces[1]}
			}
			i++
		case strings.HasPrefix(raw[i], "-"):
			pieces := strings.Split(raw[i], "=")
			if len(pieces) == 1 {
				p.flags[strings.TrimPrefix(pieces[0], "-")] = Flag{Short, ""}
			} else {
				p.flags[strings.TrimPrefix(pieces[0], "-")] = Flag{Short, pieces[1]}
			}
			i++
		default:
			goto END
		}
	}
END:
	if i < len(raw) {
		p.args = append(p.args, raw[i:]...)
	}
	return
}
1198377
func ParseIngressRules(r io.Reader) ([]network.IngressRule, error) {
	var rules []network.IngressRule
	scanner := bufio.NewScanner(r)
	for scanner.Scan() {
		line := scanner.Text()
		rule, ok, err := parseIngressRule(strings.TrimSpace(line))
		if err != nil {
			logger.Warningf("failed to parse iptables line %q: %v", line, err)
			continue
		}
		if !ok {
			continue
		}
		rules = append(rules, rule)
	}
	if err := scanner.Err(); err != nil {
		return nil, errors.Annotate(err, "reading iptables output")
	}
	return rules, nil
}
1353328
func ParseRemovalRule(rule string) (RemovalRule, error) {
	rule = strings.TrimSpace(rule)
	tokens := strings.Split(rule, "=")

	// Simple little language:
	//   port=N matches rules that filter (only) by port=N
	//
	// Note this language is internal, so isn't required to be stable

	if len(tokens) == 2 {
		if tokens[0] == "port" {
			port, err := strconv.Atoi(tokens[1])
			if err != nil {
				return nil, fmt.Errorf("cannot parse rule %q", rule)
			}

			return &PortRemovalRule{Port: port}, nil
		} else {
			return nil, fmt.Errorf("cannot parse rule %q", rule)
		}
	}
	return nil, fmt.Errorf("cannot parse rule %q", rule)
}
1204358
func (s *Statsd) parser() error {
	for {
		select {
		case <-s.done:
			return nil
		case buf := <-s.in:
			lines := strings.Split(buf.String(), "\n")
			s.bufPool.Put(buf)
			for _, line := range lines {
				line = strings.TrimSpace(line)
				if line != "" {
					s.parseStatsdLine(line)
				}
			}
		}
	}
}
1326935
func (p *parser) parsePredicate(n node) node {
	p.skipItem(itemLBracket)
	opnd := p.parseExpression(n)
	p.skipItem(itemRBracket)
	return opnd
}
249072
func (parser *Parser) ParseRules() ([]*css.Rule, error) {
	result := []*css.Rule{}

	inBlock := false
	if parser.tokenChar("{") {
		// parsing a block of rules
		inBlock = true
		parser.embedLevel++

		parser.shiftToken()
	}

	for parser.tokenParsable() {
		if parser.tokenIgnorable() {
			parser.shiftToken()
		} else if parser.tokenChar("}") {
			if !inBlock {
				errMsg := fmt.Sprintf("Unexpected } character: %s", parser.nextToken().String())
				return result, errors.New(errMsg)
			}

			parser.shiftToken()
			parser.embedLevel--

			// finished
			break
		} else {
			rule, err := parser.ParseRule()
			if err != nil {
				return result, err
			}

			rule.EmbedLevel = parser.embedLevel
			result = append(result, rule)
		}
	}

	return result, parser.err()
}
1130929
func (l4 *L4Filter) HasL3DependentL7Rules() bool {
	switch len(l4.L7RulesPerEp) {
	case 0:
		// No L7 rules.
		return false
	case 1:
		// If L3 is wildcarded, this filter corresponds to L4-only rule(s).
		_, ok := l4.L7RulesPerEp[api.WildcardEndpointSelector]
		return !ok
	default:
		return true
	}
}
845482
func buildParser(name string, tbl *ast.Table) (parsers.Parser, error) {
	config, err := getParserConfig(name, tbl)
	if err != nil {
		return nil, err
	}
	return parsers.NewParser(config)
}
1164775
func (parser *Parser) parseAtRule() (*css.Rule, error) {
	// parse rule name (eg: "@import")
	token := parser.shiftToken()

	result := css.NewRule(css.AtRule)
	result.Name = token.Value

	for parser.tokenParsable() {
		if parser.tokenChar(";") {
			parser.shiftToken()

			// finished
			break
		} else if parser.tokenChar("{") {
			if result.EmbedsRules() {
				// parse rules block
				rules, err := parser.ParseRules()
				if err != nil {
					return result, err
				}

				result.Rules = rules
			} else {
				// parse declarations block
				declarations, err := parser.ParseDeclarations()
				if err != nil {
					return result, err
				}

				result.Declarations = declarations
			}

			// finished
			break
		} else {
			// parse prelude
			prelude, err := parser.parsePrelude()
			if err != nil {
				return result, err
			}

			result.Prelude = prelude
		}
	}

	// log.Printf("[parsed] Rule: %s", result.String())

	return result, parser.err()
}
682476
func NewRule(resource string, verbs []string) Rule {
	return Rule{
		Resources: []string{resource},
		Verbs:     verbs,
	}
}
440273
func ParseLogLevel(configuration *viper.Viper, defaultLevel logrus.Level) (
	logrus.Level, error) {

	logStr := configuration.GetString("logging.level")
	if logStr == "" {
		return defaultLevel, nil
	}
	return logrus.ParseLevel(logStr)
}
1121358
func xMessageSliceParser(rd *proto.Reader, n int64) (interface{}, error) {
	msgs := make([]XMessage, 0, n)
	for i := int64(0); i < n; i++ {
		_, err := rd.ReadArrayReply(func(rd *proto.Reader, n int64) (interface{}, error) {
			id, err := rd.ReadString()
			if err != nil {
				return nil, err
			}

			v, err := rd.ReadArrayReply(stringInterfaceMapParser)
			if err != nil {
				return nil, err
			}

			msgs = append(msgs, XMessage{
				ID:     id,
				Values: v.(map[string]interface{}),
			})
			return nil, nil
		})
		if err != nil {
			return nil, err
		}
	}
	return msgs, nil
}