// Parses a given struct and returns slice of strings that can be used with os/exec. Will panic if
// an error occurs.
967558
func MustParse(v interface{}) []string {
	if command, err := Parse(v); err == nil {
		return command
	} else {
		panic(err.Error())
	}
}
635837
func (p *Parser) Parse(src []byte) (model.Stmts, error) {
	cctx, cancel := context.WithCancel(context.TODO())
	defer cancel()

	ctx := newParseCtx(cctx)
	ctx.input = src
	ctx.lexsrc = lex(cctx, src)

	var stmts model.Stmts
LOOP:
	for {
		ctx.skipWhiteSpaces()
		switch t := ctx.peek(); t.Type {
		case CREATE:
			stmt, err := p.parseCreate(ctx)
			if err != nil {
				if errors.IsIgnorable(err) {
					// this is ignorable.
					continue
				}
				if pe, ok := err.(ParseError); ok {
					return nil, pe
				}
				return nil, errors.Wrap(err, `failed to parse create`)
			}
			stmts = append(stmts, stmt)
		case COMMENT_IDENT:
			ctx.advance()
		case DROP, SET, USE:
			// We don't do anything about these
		S1:
			for {
				switch t := ctx.peek(); t.Type {
				case SEMICOLON:
					ctx.advance()
					fallthrough
				case EOF:
					break S1
				default:
					ctx.advance()
				}
			}
		case SEMICOLON:
			// you could have statements where it's just empty, followed by a
			// semicolon. These are just empty lines, so we just skip and go
			// process the next statement
			ctx.advance()
			continue
		case EOF:
			ctx.advance()
			break LOOP
		default:
			return nil, newParseError(ctx, t, "expected CREATE, COMMENT_IDENT, SEMICOLON or EOF")
		}
	}

	return stmts, nil
}
952492
func (p *Parser) Parse() (*parser.Node, error) {
	sdata := string(p.data)
	rn := parser.Node{P: p, Name: p.l.ScopeName}
	defer rn.UpdateRange()
	defer func() {
		if r := recover(); r != nil {
			log.Error("Panic during parse: %v\n", r)
			log.Debug("%v", rn)
		}
	}()
	iter := maxiter
	for i := 0; i < len(sdata) && iter > 0; iter-- {
		pat, ret := p.l.RootPattern.Cache(sdata, i)
		if ret == nil {
			break
		}
		nl := strings.IndexAny(sdata[i:], "\n\r")
		// if the match object is not in this line we will move the
		// position to beginning of the next line then we will look for
		// a match again
		if nl += i; nl != i-1 && nl <= ret[0] {
			i = nl
			for i < len(sdata) && (sdata[i] == '\n' || sdata[i] == '\r') {
				i++
			}
			continue
		}
		n := pat.CreateNode(sdata, i, p, ret)
		rn.Append(n)
		i = n.Range.B
	}
	// handling unicode characters different length
	if len(sdata) != 0 {
		lut := make([]int, len(sdata)+1)
		j := 0
		for i := range sdata {
			lut[i] = j
			j++
		}
		lut[len(sdata)] = len(p.data)
		p.patch(lut, &rn)
	}
	if iter == 0 {
		panic("reached maximum number of iterations")
	}
	return &rn, nil
}
1167811
func (v *StructA) String() string {
	if v == nil {
		return "<nil>"
	}

	var fields [1]string
	i := 0
	fields[i] = fmt.Sprintf("S: %v", v.S)
	i++

	return fmt.Sprintf("StructA{%v}", strings.Join(fields[:i], ", "))
}
401354
func (v *StructB) String() string {
	if v == nil {
		return "<nil>"
	}

	var fields [2]string
	i := 0
	if v.Aa != nil {
		fields[i] = fmt.Sprintf("Aa: %v", v.Aa)
		i++
	}
	fields[i] = fmt.Sprintf("Ab: %v", v.Ab)
	i++

	return fmt.Sprintf("StructB{%v}", strings.Join(fields[:i], ", "))
}
51448
func (b *unboundBuilder) Parse(s string) (*Literal, error) {
	raw := strings.TrimSpace(s)
	if len(raw) == 0 {
		return nil, fmt.Errorf("literal.Parse: cannot parse and empty string into a literal; provided string %q", s)
	}
	if raw[0] != '"' {
		return nil, fmt.Errorf("literal.Parse: text encoded literals must start with \", missing in %s", raw)
	}
	idx := strings.Index(raw, "\"^^type:")
	if idx < 0 {
		return nil, fmt.Errorf("literal.Parse: text encoded literals must have a type; missing in %s", raw)
	}
	v := raw[1:idx]
	t := raw[idx+len("\"^^type:"):]
	switch t {
	case "bool":
		pv, err := strconv.ParseBool(v)
		if err != nil {
			return nil, fmt.Errorf("literal.Parse: could not convert value %q to bool", v)
		}
		return b.Build(Bool, pv)
	case "int64":
		pv, err := strconv.ParseInt(v, 10, 64)
		if err != nil {
			return nil, fmt.Errorf("literal.Parse: could not convert value %q to int64", v)
		}
		return b.Build(Int64, int64(pv))
	case "float64":
		pv, err := strconv.ParseFloat(v, 64)
		if err != nil {
			return nil, fmt.Errorf("literal.Parse: could not convert value %q to float64", v)
		}
		return b.Build(Float64, float64(pv))
	case "text":
		return b.Build(Text, v)
	case "blob":
		values := v[1 : len(v)-1]
		if values == "" {
			return b.Build(Blob, []byte{})
		}
		bs := []byte{}
		for _, s := range strings.Split(values, " ") {
			b, err := strconv.ParseUint(s, 10, 8)
			if err != nil {
				return nil, fmt.Errorf("literal.Parse: failed to decode byte array on %q with error %v", s, err)
			}
			bs = append(bs, byte(b))
		}
		return b.Build(Blob, bs)
	default:
		return nil, nil
	}
}
287325
func (t *typeParser) parseParamNodes() (params []typeParserParamNode, ok bool) {
	t.skipWhitespace()

	// the params are optional
	if t.index == len(t.input) || t.input[t.index] != '(' {
		return nil, true
	}

	params = []typeParserParamNode{}

	// consume the '('
	t.index++

	t.skipWhitespace()

	for t.input[t.index] != ')' {
		// look for a named param, but if no colon, then we want to backup
		backupIndex := t.index

		// name will be a hex encoded version of a utf-8 string
		name, ok := t.nextIdentifier()
		if !ok {
			return nil, false
		}
		hasName := true

		// TODO handle '=>' used for DynamicCompositeType

		t.skipWhitespace()

		if t.input[t.index] == ':' {
			// there is a name for this parameter

			// consume the ':'
			t.index++

			t.skipWhitespace()
		} else {
			// no name, backup
			hasName = false
			t.index = backupIndex
		}

		// parse the next full parameter
		classNode, ok := t.parseClassNode()
		if !ok {
			return nil, false
		}

		if hasName {
			params = append(
				params,
				typeParserParamNode{name: &name, class: *classNode},
			)
		} else {
			params = append(
				params,
				typeParserParamNode{class: *classNode},
			)
		}

		t.skipWhitespace()

		if t.input[t.index] == ',' {
			// consume the comma
			t.index++

			t.skipWhitespace()
		}
	}

	// consume the ')'
	t.index++

	return params, true
}
1120272
func (self *StructTypeDef) UnmarshalJSON(b []byte) error {
	var m rawStructTypeDef
	err := json.Unmarshal(b, &m)
	if err == nil {
		o := StructTypeDef(m)
		*self = *((&o).Init())
		err = self.Validate()
	}
	return err
}
393985
func Parse(data []byte) (*Config, error) {
	v := struct {
		Image     string
		Build     *Build
		Workspace *Workspace
		Services  containerList
		Pipeline  containerList
		Networks  networkList
		Volumes   volumeList
	}{}

	err := yaml.Unmarshal(data, &v)
	if err != nil {
		return nil, err
	}

	for _, c := range v.Services.containers {
		c.Detached = true
	}

	return &Config{
		Image:     v.Image,
		Build:     v.Build,
		Workspace: v.Workspace,
		Services:  v.Services.containers,
		Pipeline:  v.Pipeline.containers,
		Networks:  v.Networks.networks,
		Volumes:   v.Volumes.volumes,
	}, nil
}
224565
func ParseStructTags(tag string) (StructTags, error) {
	tags := StructTags{}
	for tag != "" {
		// Skip leading space.
		i := 0
		for i < len(tag) && tag[i] == ' ' {
			i++
		}
		tag = tag[i:]
		if tag == "" {
			break
		}

		// Scan to colon. A space, a quote or a control character is a syntax error.
		// Strictly speaking, control chars include the range [0x7f, 0x9f], not just
		// [0x00, 0x1f], but in practice, we ignore the multi-byte control characters
		// as it is simpler to inspect the tag's bytes than the tag's runes.
		i = 0
		for i < len(tag) && tag[i] > ' ' && tag[i] != ':' && tag[i] != '"' && tag[i] != 0x7f {
			i++
		}
		if i == 0 || i+1 >= len(tag) || tag[i] != ':' || tag[i+1] != '"' {
			break
		}
		name := string(tag[:i])
		tag = tag[i+1:]

		// Scan quoted string to find value.
		i = 1
		for i < len(tag) && tag[i] != '"' {
			if tag[i] == '\\' {
				i++
			}
			i++
		}
		if i >= len(tag) {
			break
		}
		qvalue := string(tag[:i+1])
		tag = tag[i+1:]

		value, err := strconv.Unquote(qvalue)
		if err != nil {
			return nil, err
		}
		tags = append(tags, StructTag{Name: name, Value: value})
	}
	return tags, nil
}
456061
func parse(desc string) (chain []*term) {
	origDesc := desc
	for len(desc) != 0 {
		t := parseTerm(desc)
		if t == nil {
			fmt.Printf("failed to parse %q past %q\n", origDesc, desc)
			return nil
		}
		desc = desc[len(t.desc):]
		chain = append(chain, t)
		if len(desc) >= 2 {
			if !strings.HasPrefix(desc, "->") {
				fmt.Printf("failed to parse %q past %q, expected \"->\"\n", origDesc, desc)
				return nil
			}
			desc = desc[2:]
		}
	}
	return chain
}
1267159
func (r *Rows) StructScan(dest interface{}) error {
	v := reflect.ValueOf(dest)
	if v.Kind() != reflect.Ptr {
		return fmt.Errorf("dest must be a pointer: %T", dest)
	}
	v = v.Elem()

	t := v.Type()
	if r.structT != t {
		r.structT = t
		if err := r.initScan(t); err != nil {
			return err
		}
	}

	if err := r.scanValue(); err != nil {
		return err
	}
	v.Set(r.value)
	return nil
}
487478
func (v *Var) Parse(field reflect.StructField) error {
	v.SetName(field.Name)
	v.SetType(field.Type)
	v.SetKey(v.Name)

	tag := field.Tag.Get("env")

	if tag == "" {
		return nil
	}

	tagParams := strings.Split(tag, " ")
	for _, tagParam := range tagParams {
		var key, value string

		option := strings.Split(tagParam, "=")
		key = option[0]
		if len(option) > 1 {
			value = option[1]
		}

		switch key {
		case "key":
			// override the default key if one is specified
			v.SetKey(value)
		case "required":
			// val, _ := strconv.ParseBool(value)
			// if val != false {
			v.SetRequired(true)
			// }
		case "default":
			d, err := convert(v.Type, value)
			if err != nil {
				return err
			}
			v.SetDefault(d)
		case "options":
			in := strings.Split(value, ",")
			// var values []reflect.Value
			values := make([]reflect.Value, len(in))
			for k, val := range in {
				v1, err := convert(v.Type, val)
				if err != nil {
					return err
				}
				values[k] = v1
			}
			v.SetOptions(values)
		}
	}

	return nil
}
984963
func FromStringDict(constructor skylark.Value, d skylark.StringDict) *Struct {
	if constructor == nil {
		panic("nil constructor")
	}
	s := &Struct{
		constructor: constructor,
		entries:     make(entries, 0, len(d)),
	}
	for k, v := range d {
		s.entries = append(s.entries, entry{k, v})
	}
	sort.Sort(s.entries)
	return s
}
1240321
func Parse(buf string) (*Tree, error) {
	t := new(Tree)
	t.scanner = new(scanner)
	return t.Parse(buf)
}
1221937
func Parse(v interface{}) ([]string, error) {
	if command, _, err := generateCommand(v, true); err == nil {
		return command, err
	} else {
		return nil, err
	}
}
1166407
func (s *StructStruct) string(n int) string {
	sname := s.Name()
	pad := strings.Repeat(" ", n)

	var res string
	res += fmt.Sprintf("%s%s {\n", pad, sname)

	var fn int
	for _, field := range s.data {
		var n int
		if emb := field.Embedded(); emb != nil {
			n = len(emb.Name())
		} else {
			n = len(field.Name())
		}
		if n > fn {
			fn = n
		}
	}

	f := fmt.Sprintf("%s%%%ds %%T\n", pad, fn+1)
	for _, field := range s.data {
		if emb := field.Embedded(); emb != nil {
			res += emb.string(n + fn)
			continue
		}
		res += fmt.Sprintf(f, field.Name(), field.value.Interface())
	}

	res += fmt.Sprintf("%s}\n", pad)
	return res
}