// parsePositionalArguments tries to parse the given args to an array of values with the
// given types. It returns the parsed values or an error when the args could not be
// parsed. Missing optional arguments are returned as reflect.Zero values.
1515
func parsePositionalArguments(rawArgs json.RawMessage, types []reflect.Type) ([]reflect.Value, error) {
	dec := json.NewDecoder(bytes.NewReader(rawArgs))
	var args []reflect.Value
	tok, err := dec.Token()
	switch {
	case err == io.EOF || tok == nil && err == nil:
		// "params" is optional and may be empty. Also allow "params":null even though it's
		// not in the spec because our own client used to send it.
	case err != nil:
		return nil, err
	case tok == json.Delim('['):
		// Read argument array.
		if args, err = parseArgumentArray(dec, types); err != nil {
			return nil, err
		}
	default:
		return nil, errors.New("non-array args")
	}
	// Set any missing args to nil.
	for i := len(args); i < len(types); i++ {
		if types[i].Kind() != reflect.Ptr {
			return nil, fmt.Errorf("missing value for required argument %d", i)
		}
		args = append(args, reflect.Zero(types[i]))
	}
	return args, nil
}
509353
func (p *Parser) ParseArgs(doc string, argv []string, version string) (Opts, error) {
	return p.parse(doc, argv, version)
}
507625
func ParseFlagsWithArgs(cmd string) []string {
	flag.Parse()

	if *Version {
		AppVersion.Print()
		os.Exit(0)
	}

	args := flag.Args()
	if len(args) == 0 {
		log.Exitf("%s expected at least one positional argument", cmd)
	}

	return args
}
246552
func (p *parser) parseParameters(elementKind string) (*ast.Parameters, bool, error) {
	_, args, trailingComma, err := p.parseArguments(elementKind)
	if err != nil {
		return nil, false, err
	}
	var params ast.Parameters
	for _, arg := range args.Positional {
		id, ok := astVarToIdentifier(arg)
		if !ok {
			return nil, false, MakeStaticError(fmt.Sprintf("Expected simple identifier but got a complex expression."), *arg.Loc())
		}
		params.Required = append(params.Required, *id)
	}
	for _, arg := range args.Named {
		params.Optional = append(params.Optional, ast.NamedParameter{Name: arg.Name, DefaultArg: arg.Arg})
	}
	return &params, trailingComma, nil
}
9285
func ArgsFrom(conf string, positions ...string) ([]string, error) {
	if _, err := os.Stat(conf); err != nil {
		return nil, err
	}
	return parse(conf, positions...)
}
239156
func (c *Command) ParseFlags(args []string) error {
	if c.DisableFlagParsing {
		return nil
	}

	if c.flagErrorBuf == nil {
		c.flagErrorBuf = new(bytes.Buffer)
	}
	beforeErrorBufLen := c.flagErrorBuf.Len()
	c.mergePersistentFlags()

	//do it here after merging all flags and just before parse
	c.Flags().ParseErrorsWhitelist = flag.ParseErrorsWhitelist(c.FParseErrWhitelist)

	err := c.Flags().Parse(args)
	// Print warnings if they occurred (e.g. deprecated flag messages).
	if c.flagErrorBuf.Len()-beforeErrorBufLen > 0 && err == nil {
		c.Print(c.flagErrorBuf.String())
	}

	return err
}
484561
func HandleAllPositions(m *vm.Machine, gens ...CodeGenerator) error {
	for _, x := range m.Positions {
		if err := HandlePosition(x, gens...); err != nil {
			return err
		}
	}
	return nil
}
1155815
func (s *TermvectorsService) Positions(positions bool) *TermvectorsService {
	s.positions = &positions
	return s
}
1331554
func (mariadbFlavor) setSlavePositionCommands(pos Position) []string {
	return []string{
		// RESET MASTER will clear out gtid_binlog_pos,
		// which then guarantees that gtid_current_pos = gtid_slave_pos,
		// since gtid_current_pos = MAX(gtid_binlog_pos,gtid_slave_pos).
		// This also emptys the binlogs, which allows us to set
		// gtid_binlog_state.
		"RESET MASTER",
		// Set gtid_slave_pos to tell the slave where to start
		// replicating.
		fmt.Sprintf("SET GLOBAL gtid_slave_pos = '%s'", pos),
		// Set gtid_binlog_state so that if this server later becomes a
		// master, it will know that it has seen everything up to and
		// including 'pos'. Otherwise, if another slave asks this
		// server to replicate starting at exactly 'pos', this server
		// will throw an error when in gtid_strict_mode, since it
		// doesn't see 'pos' in its binlog - it only has everything
		// AFTER.
		fmt.Sprintf("SET GLOBAL gtid_binlog_state = '%s'", pos),
	}
}
1184383
func (b *Builtin) IsTargetPos(i int) bool {
	return len(b.Decl.Args()) == i
}
519611
func (p *parser) parseArguments(elementKind string) (*token, *ast.Arguments, bool, error) {
	args := &ast.Arguments{}
	gotComma := false
	namedArgumentAdded := false
	first := true
	for {
		next := p.peek()

		if next.kind == tokenParenR {
			// gotComma can be true or false here.
			return p.pop(), args, gotComma, nil
		}

		if !first && !gotComma {
			return nil, nil, false, MakeStaticError(fmt.Sprintf("Expected a comma before next %s, got %s.", elementKind, next), next.loc)
		}

		id, expr, err := p.parseArgument()
		if err != nil {
			return nil, nil, false, err
		}
		if id == nil {
			if namedArgumentAdded {
				return nil, nil, false, MakeStaticError("Positional argument after a named argument is not allowed", next.loc)
			}
			args.Positional = append(args.Positional, expr)
		} else {
			namedArgumentAdded = true
			args.Named = append(args.Named, ast.NamedArgument{Name: *id, Arg: expr})
		}

		if p.peek().kind == tokenComma {
			p.pop()
			gotComma = true
		} else {
			gotComma = false
		}

		first = false
	}
}
649621
func (g *Genie) ParseContents(onComp CompositionListener) error {
	patchWire := g.PatchWire

	// for each file, the patch contains a SyncHeader followed by a series of
	// operations, always ending in HEY_YOU_DID_IT
	sh := &pwr.SyncHeader{}
	for fileIndex, f := range g.SourceContainer.Files {
		sh.Reset()
		err := patchWire.ReadMessage(sh)
		if err != nil {
			return errors.WithStack(err)
		}

		if sh.FileIndex != int64(fileIndex) {
			fmt.Printf("expected fileIndex = %d, got fileIndex %d\n", fileIndex, sh.FileIndex)
			return errors.WithStack(pwr.ErrMalformedPatch)
		}

		err = g.analyzeFile(patchWire, int64(fileIndex), f.Size, onComp)
		if err != nil {
			return errors.WithStack(err)
		}
	}

	return nil
}
1367160
func ParseFeatureArgs(featureGates string) (map[string]bool, string, error) {
	kubeadmFeatureArgs := map[string]bool{}
	componentFeatureArgs := ""
	for _, s := range strings.Split(featureGates, ",") {
		if len(s) == 0 {
			continue
		}

		fg := strings.SplitN(s, "=", 2)
		if len(fg) != 2 {
			return nil, "", fmt.Errorf("missing value for key \"%v\"", s)
		}

		k := strings.TrimSpace(fg[0])
		v := strings.TrimSpace(fg[1])

		if !Supports(k) {
			componentFeatureArgs = fmt.Sprintf("%s%s,", componentFeatureArgs, s)
			continue
		}

		boolValue, err := strconv.ParseBool(v)
		if err != nil {
			return nil, "", errors.Wrapf(err, "failed to convert bool value \"%v\"", v)
		}
		kubeadmFeatureArgs[k] = boolValue
	}
	componentFeatureArgs = strings.TrimRight(componentFeatureArgs, ",")
	return kubeadmFeatureArgs, componentFeatureArgs, nil
}
1040097
func parseAnnotations(flagAnnotations *kvMap) map[types.ACIdentifier]string {
	if flagAnnotations.IsEmpty() {
		return nil
	}
	annotations := make(map[types.ACIdentifier]string)
	for k, v := range flagAnnotations.mapping {
		annotations[types.ACIdentifier(k)] = v
	}
	return annotations
}
459833
func parseArgs(c *Command, args []string) (path Path, positional []string, err error) {
	path = Path{c}
	positional = make([]string, 0) // positional args should never be nil

	seen := make(map[*Option]bool)
	parseCmd, parseOpt := true, true
	for i := 0; i < len(args); i++ {
		a := args[i]
		if parseCmd {
			subcmd := path.Last().Subcommand(a)
			if subcmd != nil {
				path = append(path, subcmd)
				continue
			}
		}

		if parseOpt && strings.HasPrefix(a, "-") {
			if a == "-" {
				positional = append(positional, a)
				parseCmd = false
				continue
			}
			if a == "--" {
				parseOpt = false
				parseCmd = false
				continue
			}

			var opt *Option
			opt, args, err = processOption(path, args, i)
			if err != nil {
				return
			}
			_, present := seen[opt]
			if present && !opt.Plural {
				err = fmt.Errorf("option %q specified too many times", args[i])
				return
			}
			seen[opt] = true
			continue
		}

		// Unmatched positional arg
		parseCmd = false
		positional = append(positional, a)
	}
	return
}
779989
func parseExtends(t *Tree, start Pos) (Node, error) {
	if t.Root().Parent != nil {
		return nil, newMultipleExtendsError(start)
	}
	tplRef, err := t.parseExpr()
	if err != nil {
		return nil, err
	}
	_, err = t.expect(tokenTagClose)
	if err != nil {
		return nil, err
	}
	n := NewExtendsNode(tplRef, start)
	t.Root().Parent = n
	return n, nil
}
775032
func PosFromPositionExpr(ctx sessionctx.Context, v *ast.PositionExpr) (int, bool, error) {
	if v.P == nil {
		return v.N, false, nil
	}
	value, err := GetParamExpression(ctx, v.P.(*driver.ParamMarkerExpr))
	if err != nil {
		return 0, true, err
	}
	pos, isNull, err := GetIntFromConstant(ctx, value)
	if err != nil || isNull {
		return 0, true, err
	}
	return pos, false, nil
}