// parseFields parses a block of lines that define fields.
//
// It looks like this:
//
//    arg1: blah-blah,
//       maybe more-blah-blah.
//    arg2: shorter blah-blah.
//
//    arg3:
3997
func parseFields(lines []string) []Field {
	var fields []Field

	for len(lines) > 0 {
		// Grab the name of the field from the first line.
		name, firstLine, ok := parseFieldLine(lines[0])
		if !ok {
			break
		}
		lines = lines[1:]

		// All other lines of the field description (if any) are intended.
		var block []string
		block, lines = readUntil(lines, func(_ *string, l string) bool {
			return l != "" && !hasLeadingSpace(l)
		})

		// Combine the first line with the rest of the block.
		all := trimEmptyLines(append([]string{firstLine}, deindent(block)...))

		// Join lines by space. We assume argument descriptions do not use newlines
		// in a syntax-significant way.
		fields = append(fields, Field{
			Name: name,
			Desc: strings.Join(all, " "),
		})
	}

	return fields
}
1012724
func GetFields(body []byte) ([]string, error) {
	query, err := pql.ParseString(string(body))
	if err != nil {
		return nil, fmt.Errorf("parsing query: %v", err.Error())
	}

	fields := make([]string, len(query.Calls))

	for i, call := range query.Calls {
		if field, ok := call.Args["field"].(string); ok {
			fields[i] = field
		} else if field, ok := call.Args["_field"].(string); ok {
			fields[i] = field
		} else {
			fields[i] = ""
		}
	}
	return fields, nil
}
592486
func (p *Parser) parseSortField() (*SortField, error) {
	field := &SortField{}

	// Parse sort field name.
	ident, err := p.ParseIdent()
	if err != nil {
		return nil, err
	}
	field.Name = ident

	// Check for optional ASC or DESC clause. Default is ASC.
	tok, _, _ := p.ScanIgnoreWhitespace()
	if tok != ASC && tok != DESC {
		p.Unscan()
		tok = ASC
	}
	field.Ascending = (tok == ASC)

	return field, nil
}
940850
func Fields(obj interface{}) ([]reflect.StructField, error) {
	if !hasValidType(obj, []reflect.Kind{reflect.Struct, reflect.Ptr}) {
		return nil, errors.New("Cannot use GetField on a non-struct interface")
	}

	objValue := reflectValue(obj)
	objType := objValue.Type()
	fieldsCount := objType.NumField()

	var fields []reflect.StructField
	for i := 0; i < fieldsCount; i++ {
		field := objType.Field(i)
		if !isExportableField(field) {
			continue
		}

		fields = append(fields, field)
		if k := objValue.Field(i).Kind(); k == reflect.Struct || k == reflect.Ptr {
			nestedFields, _ := Fields(objValue.Field(i).Interface())
			fields = append(fields, nestedFields...)
		}
	}

	return fields, nil
}
940166
func ParseFlags() (*flag.FlagSet, []string) {
	flag.Parse()
	args := flag.Args()
	previousFlags := flag.CommandLine
	flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
	return previousFlags, args
}
1001034
func (p *gc_parser) parse_field() *ast.Field {
	var tag string
	name, _ := p.parse_name()
	typ := p.parse_type()
	if p.tok == scanner.String {
		tag = p.expect(scanner.String)
	}

	var names []*ast.Ident
	if name != "?" {
		names = []*ast.Ident{ast.NewIdent(name)}
	}

	return &ast.Field{
		Names: names,
		Type:  typ,
		Tag:   &ast.BasicLit{Kind: token.STRING, Value: tag},
	}
}
332311
func (self *Collection) AddFields(fields ...Field) *Collection {
	self.Fields = append(self.Fields, fields...)
	return self
}
1161557
func (p *point) Fields() (Fields, error) {
	if p.cachedFields != nil {
		return p.cachedFields, nil
	}
	cf, err := p.unmarshalBinary()
	if err != nil {
		return nil, err
	}
	p.cachedFields = cf
	return p.cachedFields, nil
}
11518
func (dt *DbfTable) FieldNames() []string {
	names := make([]string, 0)

	for _, field := range dt.Fields() {
		names = append(names, field.name)
	}

	return names
}
21269
func (p *Parsed) FieldsBlock(title string) FieldsBlock {
	for _, b := range p.Fields {
		if b.Title == title {
			return b
		}
	}
	return FieldsBlock{}
}
946629
func AddServiceFields(rw http.ResponseWriter, req *http.Request, next http.Handler, data *LogData) {
	data.Core[ServiceURL] = req.URL // note that this is *not* the original incoming URL
	data.Core[ServiceAddr] = req.URL.Host

	next.ServeHTTP(rw, req)

}
999362
func (p *Parser) parseSortFields() (SortFields, error) {
	var fields SortFields

	tok, pos, lit := p.ScanIgnoreWhitespace()

	switch tok {
	// The first field after an order by may not have a field name (e.g. ORDER BY ASC)
	case ASC, DESC:
		fields = append(fields, &SortField{Ascending: (tok == ASC)})
	// If it's a token, parse it as a sort field.  At least one is required.
	case IDENT:
		p.Unscan()
		field, err := p.parseSortField()
		if err != nil {
			return nil, err
		}

		if lit != "time" {
			return nil, errors.New("only ORDER BY time supported at this time")
		}

		fields = append(fields, field)
	// Parse error...
	default:
		return nil, newParseError(tokstr(tok, lit), []string{"identifier", "ASC", "DESC"}, pos)
	}

	// Parse additional fields.
	for {
		tok, _, _ := p.ScanIgnoreWhitespace()

		if tok != COMMA {
			p.Unscan()
			break
		}

		field, err := p.parseSortField()
		if err != nil {
			return nil, err
		}

		fields = append(fields, field)
	}

	if len(fields) > 1 {
		return nil, errors.New("only ORDER BY time supported at this time")
	}

	return fields, nil
}
294215
func (s *Span) LogFields(fields ...log.Field) {
	s.Lock()
	defer s.Unlock()
	if !s.context.IsSampled() {
		return
	}
	s.logFieldsNoLocking(fields...)
}
1083139
func (p FloatParser) Parse(field string) (result interface{}, err error) {
	return strconv.ParseFloat(field, 64)
}
1272989
func (*DatabaseSettings) Fields(c context.Context) ([]portal.Field, error) {
	fields := []portal.Field{
		{
			ID:    "Server",
			Title: "Server",
			Type:  portal.FieldText,
			Help:  "<p>Server to use (for Cloud SQL should be of the form project:region:database)</p>",
		},
		{
			ID:    "Username",
			Title: "Username",
			Type:  portal.FieldText,
			Help:  "<p>Username to authenticate to the SQL database with</p>",
		},
		{
			ID:    "Password",
			Title: "Password",
			Type:  portal.FieldPassword,
			Help:  "<p>Password to authenticate to the SQL database with</p>",
		},
		{
			ID:    "Database",
			Title: "Database",
			Type:  portal.FieldText,
			Help:  "<p>SQL database to use</p>",
		},
	}
	return fields, nil
}
177313
func (cmd *CLI) parseFlags(args []string) []string {
	cmd.defineHelp()
	cmd.defineVersion()
	cmd.initFlagValues()

	// Set all the flags to defaults before setting
	cmd.setFlagDefaults()

	// copy propogating flags
	cmd.copyPropogatingFlags()

	// Set inherited values
	cmd.setFlagValuesFromParent()

	var paramIndex int
	var nonFlags []string

	// Set each flag by its set value
	for {
		// Break if no arguments remain
		if len(args) == 0 {
			cmd.flagsTerminated = true
			break
		}
		arg := args[0]

		if arg[0] != '-' { // Parse Param

			if paramIndex == len(cmd.params) && len(cmd.subCommands) > 0 {
				break
			}
			nonFlags = append(nonFlags, arg)
			paramIndex++
			args = args[1:]

		} else { // Parse Flags

			isAlias, flags := cmd.flagFromArg(arg)

			// Break if the flags have been terminated
			if cmd.flagsTerminated {
				// Remove the flag terminator if it exists
				if arg == "--" {
					args = args[1:]
				}
				break
			}

			// Set flag values
			if isAlias {
				args = cmd.setAliasValues(flags, args)
			} else {
				args = cmd.setFlagValue(flags[0], args)
			}
		}
	}

	// reposition the Args so that they may still be parsed
	args = append(nonFlags, args...)

	// return the remaining unused args
	return args
}
839503
func fields(s string) ([]string, error) {
	var args []string

	for s = strings.TrimSpace(s); len(s) > 0; s = strings.TrimSpace(s) {
		if s[0] == '/' {
			sep := nextSlash(s[1:])
			if sep < 0 {
				return nil, errors.New("unbalanced /")
			}
			args, s = append(args, s[:sep+2]), s[sep+2:]
		} else {
			sep := strings.IndexByte(s[1:], ' ')
			if sep < 0 {
				return append(args, s), nil
			}
			args, s = append(args, s[:sep+1]), s[sep+1:]
		}
	}

	return args, nil
}