// Some helpers to read files
// ParseFile reads a file and return Queries or an error
960533
func ParseFile(path string) (Queries, error) {
	file, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	defer file.Close()

	return ParseReader(file)
}
1044743
func ParseFile(filePath string, root Root) error {
	workDir, fileName := filepath.Split(filePath)
	_, err := ParseReadFile(workDir, fileName, root)
	return err
}
1295341
func ParseFile(path string) (*Template, error) {
	var f *os.File
	var err error
	if path == "-" {
		// Create a temp file for stdin in case of errors
		f, err = tmp.File("parse")
		if err != nil {
			return nil, err
		}
		defer os.Remove(f.Name())
		defer f.Close()
		io.Copy(f, os.Stdin)
		f.Seek(0, os.SEEK_SET)
	} else {
		f, err = os.Open(path)
		if err != nil {
			return nil, err
		}
		defer f.Close()
	}
	tpl, err := Parse(f)
	if err != nil {
		syntaxErr, ok := err.(*json.SyntaxError)
		if !ok {
			return nil, err
		}
		// Rewind the file and get a better error
		f.Seek(0, os.SEEK_SET)
		// Grab the error location, and return a string to point to offending syntax error
		line, col, highlight := highlightPosition(f, syntaxErr.Offset)
		err = fmt.Errorf("Error parsing JSON: %s\nAt line %d, column %d (offset %d):\n%s", err, line, col, syntaxErr.Offset, highlight)
		return nil, err
	}

	if !filepath.IsAbs(path) {
		path, err = filepath.Abs(path)
		if err != nil {
			return nil, err
		}
	}

	tpl.Path = path
	return tpl, nil
}
606069
func ParseFile(filename string, opts ...Option) (i interface{}, err error) {
	f, err := os.Open(filename)
	if err != nil {
		return nil, err
	}
	defer func() {
		if closeErr := f.Close(); closeErr != nil {
			err = closeErr
		}
	}()
	return ParseReader(filename, f, opts...)
}
479827
func ReadConfigFile(filePath string) error {
	data, err := ioutil.ReadFile(filePath)
	if err != nil {
		return err
	}
	return ReadConfigBytes(data)
}
618117
func ParseFiles(fs []string) (*Source, error) {
	src := &Source{
		Funcs: make([]*Fn, 0),
		Files: make([]string, 0),
		StdLibImports: []string{
			"unsafe",
		},
		ExternalImports: make([]string, 0),
	}
	for _, file := range fs {
		if err := src.ParseFile(file); err != nil {
			return nil, err
		}
	}
	return src, nil
}
975430
func ParseFile(path string) (config Config, err error) {
	var file *os.File
	file, err = os.Open(path) //nolint:gosec
	if err != nil {
		return
	}
	defer file.Close() // nolint: errcheck
	return Parse(file)
}
897825
func ReadFile(path string) (map[string]string, error) {
	f, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	defer f.Close()
	return Read(f)
}
803576
func ReadFile(ctx context.Context, fs FileSystem, path string) ([]byte, error) {
	rc, err := fs.Open(ctx, path)
	if err != nil {
		return nil, err
	}
	defer rc.Close()
	return ioutil.ReadAll(rc)
}
472368
func (b *Builder) shouldParseFile(path string) bool {
	configFormat := b.stringVal(b.Flags.ConfigFormat)
	srcFormat := FormatFrom(path)

	// If config-format is not set, only read files with supported extensions
	if configFormat == "" && srcFormat != "hcl" && srcFormat != "json" {
		return false
	}
	return true
}
794479
func ParseClientDigestsFile(r io.Reader) (*ClientDigestsFile, error) {
	res := &ClientDigestsFile{}

	lineNo := 0
	makeError := func(fmtStr string, args ...interface{}) error {
		args = append([]interface{}{lineNo}, args...)
		return fmt.Errorf("failed to parse client digests file (line %d): "+fmtStr, args...)
	}

	scanner := bufio.NewScanner(r)
	for scanner.Scan() {
		lineNo++

		line := strings.TrimSpace(scanner.Text())
		if line == "" || line[0] == '#' {
			continue
		}

		tokens := strings.Fields(line)
		if len(tokens) != 3 {
			return nil, makeError("each line must have format \"<platform> <algo> <digest>\"")
		}

		algoIdx := api.HashAlgo_value[strings.ToUpper(tokens[1])]
		if algoIdx == 0 {
			continue // skip unknown algorithms
		}
		ref := &api.ObjectRef{
			HashAlgo:  api.HashAlgo(algoIdx),
			HexDigest: tokens[2],
		}
		if err := common.ValidateObjectRef(ref, common.KnownHash); err != nil {
			return nil, makeError("%s", err)
		}

		if err := res.AddClientRef(tokens[0], ref); err != nil {
			return nil, makeError("%s", err)
		}
	}

	if err := scanner.Err(); err != nil {
		return nil, err
	}
	return res, nil
}
300713
func ParseFile(file string) (*jwt.Token, error) {
	kiteKey, err := ioutil.ReadFile(file)
	if err != nil {
		return nil, err
	}

	return jwt.ParseWithClaims(string(bytes.TrimSpace(kiteKey)), &KiteClaims{}, GetKontrolKey)
}
565888
func parseFilters(v []string) ([]Filter, error) {
	fs := make([]Filter, 0, len(v))
	for _, s := range v {
		p := strings.Index(s, "(")
		if p < 0 {
			return nil, fmt.Errorf("Incorrect syntax in filter parameters, missing (")
		}

		if strings.Index(s, ")") != len(s)-1 {
			return nil, fmt.Errorf("Incorrect syntax in filter parameters, missing )")
		}

		t := Unknown.From(s[:p])
		if t == Unknown {
			return nil, fmt.Errorf("Unknown filter type")
		}

		command := s[p+1 : len(s)-1]

		switch t {
		case Label:
			proto := strings.SplitN(command, ":", 2)
			if len(proto) < 2 {
				return nil, fmt.Errorf("Missing : from label filter")
			}
			r, err := regexp.Compile(proto[1])
			if err != nil {
				return nil, err
			}
			fs = append(fs, labelFilter(proto[0], r))
			break
		case Name:
			r, err := regexp.Compile(command)
			if err != nil {
				return nil, err
			}
			fs = append(fs, nameFilter(r))
			break
		}
	}
	return fs, nil
}
1327069
func (f *FilterQLParser) ParseFilter() (*FilterSelect, error) {
	f.setLexer(f.statement)
	return f.parseSelectStart()
}
1317112
func ParseFile(filename string) (string, error) {
	bs, err := ioutil.ReadFile(filename)
	if err != nil {
		return "", err
	}
	return Parse(filepath.Base(filename), bs)
}
276396
func (c *Client) UploadFile(name string, contents io.Reader, contentType string) (*ParseFile, error) {
	uri := "/1/files/"+name
	resp, err := c.do("POST", uri, contentType, contents)
	c.trace("UploadFile", uri, contentType)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	var result *ParseFile
	err = json.NewDecoder(resp.Body).Decode(&result)
	return result, err
}
1199124
func Parse(filename string, b []byte, opts ...Option) (interface{}, error) {
	return newParser(filename, b, opts...).parse(g)
}