// parseMacro evaluates whole input string and replaces keywords with appropriate
// values from
328038
func parseMacro(p *parser, input string) (string, error) {
	m := newMacro(input)
	var err error
	for m.state = scanText; m.state != nil; {
		m.state, err = m.state(m, p)
		if err != nil {
			// log error
			return "", err
		}

	}
	return strings.Join(m.output, ""), nil
}
380049
func (t *tree) parseAutoescape(attrs map[string]string) ast.AutoescapeType {
	switch val := attrs["autoescape"]; val {
	case "":
		return ast.AutoescapeUnspecified
	case "contextual":
		return ast.AutoescapeContextual
	case "deprecated-contextual":
		return ast.AutoescapeContextual
	case "true":
		return ast.AutoescapeOn
	case "false":
		return ast.AutoescapeOff
	default:
		t.errorf(`expected "true", "false", or "contextual" for autoescape, got %q`, val)
	}
	panic("unreachable")
}
757490
func (p *Parser) PeekOne(typ TokenType, vals ...string) *Token {
	for _, v := range vals {
		t := p.PeekN(0, typ, v)
		if t != nil {
			return t
		}
	}
	return nil
}
951357
func ParseMAC(s string) (MACAddress, error) {
	hw, err := net.ParseMAC(s)
	return (MACAddress)(hw), err
}
515628
func (p *parser) parseObj() (string, objType, string) {
	p.skipWhitespace()
	c := p.c()
	if c[0] == '"' || c[0] == '\'' {
		i := 1
	For:
		for ; i < len(c); i++ {
			switch c[i] {
			case '\\':
				i++
			case c[0]:
				break For
			}
		}
		p.i += i + 1

		s := "\"" + string(c[1:i]) + "\""
		json.Unmarshal([]byte(s), &s)
		lang := ""
		if c[i+1] == '@' {
			c = p.c()
			i := bytes.IndexAny(c, stopRunes)
			if c[i-1] == '.' {
				i--
			}
			p.i += i
			lang = string(c[1:i])
		} else if bytes.Equal(c[i+1:i+3], []byte("^^")) {
			// TODO(d4l3k): Implement RDF types.
		}
		return s, typeString, lang
	} else if bytes.HasPrefix(c, []byte("<")) {
		i := bytes.IndexRune(c, '>')
		p.i += i + 1
		url := string(c[1:i])
		if !strings.Contains(url, "://") {
			url = p.base + url
		}
		return url, typeIRI, ""
	} else if bytes.HasPrefix(c, []byte(".")) {
		p.i += 1
		return ".", typeEnd, ""
	} else if bytes.HasPrefix(c, []byte(";")) {
		p.i += 1
		return ";", typePred, ""
	} else if bytes.HasPrefix(c, []byte(",")) {
		p.i += 1
		return ",", typeObj, ""
	} else {
		i := bytes.IndexAny(c, stopRunes)
		if c[i-1] == '.' {
			i--
		}
		p.i += i
		obj := string(c[:i])
		psym := strings.IndexRune(obj, ':')
		if psym != -1 {
			if psym == len(obj)-1 {
				return obj, typePrefix, ""
			}
			prefix := obj[:psym+1]
			if expand, ok := p.prefix[prefix]; ok {
				return expand + obj[psym+1:], typeIRI, ""
			}
		}
		return obj, typeUnknown, ""
	}
}
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},
	}
}
224340
func (p *Parser) ParseString(src string) (model.Stmts, error) {
	return p.Parse([]byte(src))
}
167928
func parseOptions(options string) (int, string) {
	var (
		flag int
		data []string
	)

	flags := map[string]struct {
		clear bool
		flag  int
	}{
		"defaults":      {false, 0},
		"ro":            {false, RDONLY},
		"rw":            {true, RDONLY},
		"suid":          {true, NOSUID},
		"nosuid":        {false, NOSUID},
		"dev":           {true, NODEV},
		"nodev":         {false, NODEV},
		"exec":          {true, NOEXEC},
		"noexec":        {false, NOEXEC},
		"sync":          {false, SYNCHRONOUS},
		"async":         {true, SYNCHRONOUS},
		"dirsync":       {false, DIRSYNC},
		"remount":       {false, REMOUNT},
		"mand":          {false, MANDLOCK},
		"nomand":        {true, MANDLOCK},
		"atime":         {true, NOATIME},
		"noatime":       {false, NOATIME},
		"diratime":      {true, NODIRATIME},
		"nodiratime":    {false, NODIRATIME},
		"bind":          {false, BIND},
		"rbind":         {false, RBIND},
		"unbindable":    {false, UNBINDABLE},
		"runbindable":   {false, RUNBINDABLE},
		"private":       {false, PRIVATE},
		"rprivate":      {false, RPRIVATE},
		"shared":        {false, SHARED},
		"rshared":       {false, RSHARED},
		"slave":         {false, SLAVE},
		"rslave":        {false, RSLAVE},
		"relatime":      {false, RELATIME},
		"norelatime":    {true, RELATIME},
		"strictatime":   {false, STRICTATIME},
		"nostrictatime": {true, STRICTATIME},
	}

	for _, o := range strings.Split(options, ",") {
		// If the option does not exist in the flags table or the flag
		// is not supported on the platform,
		// then it is a data value for a specific fs type
		if f, exists := flags[o]; exists && f.flag != 0 {
			if f.clear {
				flag &= ^f.flag
			} else {
				flag |= f.flag
			}
		} else {
			data = append(data, o)
		}
	}
	return flag, strings.Join(data, ",")
}
662356
func parseObjectField(parser *Parser, isConst bool) (*ast.ObjectField, error) {
	var (
		name  *ast.Name
		value ast.Value
		err   error
	)
	start := parser.Token.Start
	if name, err = parseName(parser); err != nil {
		return nil, err
	}
	if _, err = expect(parser, lexer.COLON); err != nil {
		return nil, err
	}
	if value, err = parseValueLiteral(parser, isConst); err != nil {
		return nil, err
	}
	return ast.NewObjectField(&ast.ObjectField{
		Name:  name,
		Value: value,
		Loc:   loc(parser, start),
	}), nil
}
300458
func (p *Parser) parseValues() (sets.String, error) {
	tok, lit := p.consume(Values)
	if tok != OpenParToken {
		return nil, fmt.Errorf("found '%s' expected: '('", lit)
	}
	tok, lit = p.lookahead(Values)
	switch tok {
	case IdentifierToken, CommaToken:
		s, err := p.parseIdentifiersList() // handles general cases
		if err != nil {
			return s, err
		}
		if tok, _ = p.consume(Values); tok != ClosedParToken {
			return nil, fmt.Errorf("found '%s', expected: ')'", lit)
		}
		return s, nil
	case ClosedParToken: // handles "()"
		p.consume(Values)
		return sets.NewString(""), nil
	default:
		return nil, fmt.Errorf("found '%s', expected: ',', ')' or identifier", lit)
	}
}
420121
func parseBSON(done <-chan struct{}, r io.Reader) (<-chan map[string]interface{}, <-chan error) {
	c := make(chan map[string]interface{})
	errc := make(chan error, 1)

	go func() {
		defer close(c)
		scanner := bsonScanner.New(r)
	scan:
		for scanner.Scan() {
			op := map[string]interface{}{}
			if err := bson.Unmarshal(scanner.Bytes(), &op); err != nil {
				errc <- err
				return
			}
			select {
			case c <- op:
			case <-done:
				break scan
			}
		}
		if err := scanner.Err(); err != nil {
			fmt.Println(err)
			errc <- err
		}
		errc <- nil
	}()
	return c, errc
}
1227151
func parseDictHeader(value string) map[string]string {
	pairs := strings.Split(value, ",")
	res := make(map[string]string, len(pairs))
	for _, pair := range pairs {
		parts := strings.SplitN(strings.TrimSpace(pair), "=", 2)
		key := strings.TrimSpace(parts[0])
		if len(key) == 0 {
			continue
		}
		val := ""
		if len(parts) > 1 {
			val = strings.TrimSpace(parts[1])
			if strings.HasPrefix(val, `"`) && strings.HasSuffix(val, `"`) {
				val = val[1 : len(val)-1]
			}
		}
		res[key] = val
	}
	return res
}
367650
func parseOpts(name string, o values) error {
	s := newScanner(name)

	for {
		var (
			keyRunes, valRunes []rune
			r                  rune
			ok                 bool
		)

		if r, ok = s.SkipSpaces(); !ok {
			break
		}

		// Scan the key
		for !unicode.IsSpace(r) && r != '=' {
			keyRunes = append(keyRunes, r)
			if r, ok = s.Next(); !ok {
				break
			}
		}

		// Skip any whitespace if we're not at the = yet
		if r != '=' {
			r, ok = s.SkipSpaces()
		}

		// The current character should be =
		if r != '=' || !ok {
			return fmt.Errorf(`missing "=" after %q in connection info string"`, string(keyRunes))
		}

		// Skip any whitespace after the =
		if r, ok = s.SkipSpaces(); !ok {
			// If we reach the end here, the last value is just an empty string as per libpq.
			o[string(keyRunes)] = ""
			break
		}

		if r != '\'' {
			for !unicode.IsSpace(r) {
				if r == '\\' {
					if r, ok = s.Next(); !ok {
						return fmt.Errorf(`missing character after backslash`)
					}
				}
				valRunes = append(valRunes, r)

				if r, ok = s.Next(); !ok {
					break
				}
			}
		} else {
		quote:
			for {
				if r, ok = s.Next(); !ok {
					return fmt.Errorf(`unterminated quoted string literal in connection string`)
				}
				switch r {
				case '\'':
					break quote
				case '\\':
					r, _ = s.Next()
					fallthrough
				default:
					valRunes = append(valRunes, r)
				}
			}
		}

		o[string(keyRunes)] = string(valRunes)
	}

	return nil
}
718054
func parseKeyValue(keyvalue string) (string, string) {
	var key, val string

	split := strings.Split(keyvalue, "=")
	// Must be exactly 2 to get anything meaningful out of them
	if len(split) == 2 {
		key = split[0]
		val = split[1]
	} else if len(split) == 1 {
		val = split[0]
	}

	return key, val
}
396524
func ParseURL(urlStr string) (result *url.URL, err error) {
	result, err = url.Parse(urlStr)
	if result != nil && result.Scheme == "" {
		result = nil
		err = fmt.Errorf("invalid URL <%s>", urlStr)
	}
	return
}
1175108
func (p *Parser) parseOperator() (op selection.Operator, err error) {
	tok, lit := p.consume(KeyAndOperator)
	switch tok {
	// DoesNotExistToken shouldn't be here because it's a unary operator, not a binary operator
	case InToken:
		op = selection.In
	case EqualsToken:
		op = selection.Equals
	case DoubleEqualsToken:
		op = selection.DoubleEquals
	case GreaterThanToken:
		op = selection.GreaterThan
	case LessThanToken:
		op = selection.LessThan
	case NotInToken:
		op = selection.NotIn
	case NotEqualsToken:
		op = selection.NotEquals
	default:
		return "", fmt.Errorf("found '%s', expected: '=', '!=', '==', 'in', notin'", lit)
	}
	return op, nil
}
126826
func (s TypedString) ParseValue() (Value, error) {
	fnc := knownConversions[s.Type.Full()]
	if fnc == nil {
		return s, nil
	}
	return fnc(string(s.Value))
}