// Compile validates a prepared query template and returns an opaque compiled
// object that can be used later to render the template.
429331
func Compile(query *structs.PreparedQuery) (*CompiledTemplate, error) {
	// Make sure it's a type we understand.
	if query.Template.Type != structs.QueryTemplateTypeNamePrefixMatch {
		return nil, fmt.Errorf("Bad Template.Type '%s'", query.Template.Type)
	}

	// Start compile.
	ct := &CompiledTemplate{
		trees:           make(map[string]ast.Node),
		removeEmptyTags: query.Template.RemoveEmptyTags,
	}

	// Make a copy of the query to use as the basis for rendering later.
	dup, err := copystructure.Copy(query)
	if err != nil {
		return nil, err
	}
	var ok bool
	ct.query, ok = dup.(*structs.PreparedQuery)
	if !ok {
		return nil, fmt.Errorf("Failed to copy query")
	}

	// Walk over all the string fields in the Service sub-structure and
	// parse them as HIL.
	parse := func(path string, v reflect.Value) error {
		tree, err := hil.Parse(v.String())
		if err != nil {
			return fmt.Errorf("Bad format '%s' in Service%s: %s", v.String(), path, err)
		}

		ct.trees[path] = tree
		return nil
	}
	if err := walk(&ct.query.Service, parse); err != nil {
		return nil, err
	}

	// If they supplied a regexp then compile it.
	if ct.query.Template.Regexp != "" {
		var err error
		ct.re, err = regexp.Compile(ct.query.Template.Regexp)
		if err != nil {
			return nil, fmt.Errorf("Bad Regexp: %s", err)
		}
	}

	// Finally do a test render with the supplied name prefix. This will
	// help catch errors before run time, and this is the most minimal
	// prefix it will be expected to run with. The results might not make
	// sense and create a valid service to lookup, but it should render
	// without any errors.
	if _, err = ct.Render(ct.query.Name, structs.QuerySource{}); err != nil {
		return nil, err
	}

	return ct, nil
}
765753
func (stmt DeleteStmt) Compile(d Dialect, params *Parameters) (string, error) {
	if err := stmt.Error(); err != nil {
		return "", err
	}
	compiled := fmt.Sprintf(`DELETE FROM "%s"`, stmt.table.Name())

	if stmt.cond != nil {
		cc, err := stmt.cond.Compile(d, params)
		if err != nil {
			return "", err
		}
		compiled += fmt.Sprintf(" WHERE %s", cc)
	}
	return compiled, nil
}
947457
func (m *MockCompiler) Compile(arg0 pkg.Compilable) (pkg0.CompiledPackageRecord, bool, error) {
	ret := m.ctrl.Call(m, "Compile", arg0)
	ret0, _ := ret[0].(pkg0.CompiledPackageRecord)
	ret1, _ := ret[1].(bool)
	ret2, _ := ret[2].(error)
	return ret0, ret1, ret2
}
216885
func (ctx *compctx) compile(out io.Writer, in io.Reader) error {

	defer ctx.Reset()
	var (
		bs  []byte
		err error
	)

	// libSass will fail on Sass syntax given as non-file input
	// convert the input on its behalf
	if ctx.compiler.Syntax() == SassSyntax {
		// this is memory intensive
		var buf bytes.Buffer
		err := ToScss(in, &buf)
		if err != nil {
			return err
		}
		bs = buf.Bytes()
	} else {
		// ScssSyntax
		bs, err = ioutil.ReadAll(in)
		if err != nil {
			return err
		}
	}

	if len(bs) == 0 {
		return errors.New("No input provided")
	}

	godc := libs.SassMakeDataContext(string(bs))
	goopts := libs.SassDataContextGetOptions(godc)
	libs.SassOptionSetSourceComments(goopts, true)

	ctx.Init(goopts)

	libs.SassDataContextSetOptions(godc, goopts)
	goctx := libs.SassDataContextGetContext(godc)
	ctx.context = goctx
	gocompiler := libs.SassMakeDataCompiler(godc)
	libs.SassCompilerParse(gocompiler)
	libs.SassCompilerExecute(gocompiler)
	defer libs.SassDeleteCompiler(gocompiler)

	goout := libs.SassContextGetOutputString(goctx)
	io.WriteString(out, goout)

	ctx.Status = libs.SassContextGetErrorStatus(goctx)
	errJSON := libs.SassContextGetErrorJSON(goctx)
	err = ctx.ProcessSassError([]byte(errJSON))
	if err != nil {
		return err
	}

	if ctx.Error() != "" {
		lines := bytes.Split(bs, []byte("\n"))
		var out string
		for i := -7; i < 7; i++ {
			if i+ctx.err.Line >= 0 && i+ctx.err.Line < len(lines) {
				out += fmt.Sprintf("%s\n", string(lines[i+ctx.err.Line]))
			}
		}
		// TODO: this is weird, make something more idiomatic
		return errors.New(ctx.Error() + "\n" + out)
	}

	return nil
}
1276657
func Compile(sel string) (Selector, error) {
	p := &parser{s: sel}
	compiled, err := p.parseSelectorGroup()
	if err != nil {
		return nil, err
	}

	if p.i < len(sel) {
		return nil, fmt.Errorf("parsing %q: %d bytes left over", sel, len(sel)-p.i)
	}

	return compiled, nil
}
1065601
func (mr *MockCompilerMockRecorder) Compile(arg0 interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Compile", reflect.TypeOf((*MockCompiler)(nil).Compile), arg0)
}
343495
func Compile(expr string) (*Regexp, error) {
	re, err := syntax.Parse(expr, syntax.Perl)
	if err != nil {
		return nil, err
	}
	sre := re.Simplify()
	prog, err := syntax.Compile(sre)
	if err != nil {
		return nil, err
	}
	if err := toByteProg(prog); err != nil {
		return nil, err
	}
	r := &Regexp{
		Syntax: re,
		expr:   expr,
	}
	if err := r.m.init(prog); err != nil {
		return nil, err
	}
	return r, nil
}
250278
func (t *Tool) Compile(path string, stop <-chan bool) (response Response) {
	var out bytes.Buffer
	var stderr bytes.Buffer
	done := make(chan error)
	args := append(t.cmd, t.Args...)
	cmd := exec.Command(args[0], args[1:]...)
	if t.Dir != "" {
		cmd.Dir, _ = filepath.Abs(t.Dir)
	} else {
		cmd.Dir = path
	}
	cmd.Stdout = &out
	cmd.Stderr = &stderr
	// Start command
	cmd.Start()
	go func() { done <- cmd.Wait() }()
	// Wait a result
	response.Name = t.name
	select {
	case <-stop:
		// Stop running command
		cmd.Process.Kill()
	case err := <-done:
		// Command completed
		if err != nil {
			response.Err = errors.New(stderr.String() + err.Error())
		}
	}
	return
}
524323
func Compile(expr string) (*Expr, error) {
	if expr == "" {
		return nil, errors.New("expr expression is nil")
	}
	qy, err := build(expr)
	if err != nil {
		return nil, err
	}
	return &Expr{s: expr, q: qy}, nil
}
404645
func (c *Compiler) Compile() (*module.Module, error) {

	for _, stage := range c.stages {
		if err := stage(); err != nil {
			return nil, err
		}
	}

	return c.module, nil
}
608403
func MustCompile(expr string) *Expr {
	exp, err := Compile(expr)
	if err != nil {
		return nil
	}
	return exp
}
1325362
func MustCompile(input string, options Options) *template.Template {
	t, err := Compile(input, options)
	if err != nil {
		panic(err)
	}
	return t
}
995636
func (c *Client) PrepareTemplate(p *PrepareTemplateParameter) (*Template, error) {
	obj, err := c.Request("prepareTemplate", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*Template), err
}
391005
func (c ColumnElem) Compile(d Dialect, params *Parameters) (string, error) {
	var compiled string
	var err error
	if c.inner == nil {
		// Old behavior
		compiled, err = fmt.Sprintf(`"%s"."%s"`, c.table.name, c.name), nil
	} else {
		compiled, err = c.inner.Compile(d, params)
	}
	if err != nil {
		return compiled, err
	}
	if c.alias != "" {
		compiled += fmt.Sprintf(` AS "%s"`, c.alias)
	}
	return compiled, nil
}
124870
func CompileFilter(s string) (*types.Filter, error) {

	es, err := url.QueryUnescape(s)
	if err != nil {
		return nil, err
	}
	s = es

	if len(s) == 0 || s[0] != '(' {
		return nil, errCharZeroNotLParen
	}

	f, pos, err := compileFilter(s, 1)
	if err != nil {
		return nil, err
	}

	if pos != len(s) {
		return nil, goof.WithField(
			"extra", s[pos:],
			"finished compiling filter with extra at end")
	}

	return f, nil
}
801989
func CompileOrDie(filters ...string) []*regexp.Regexp {
	var compiled []*regexp.Regexp
	for _, re := range filters {
		compiled = append(compiled, regexp.MustCompile(re))
	}
	return compiled
}
784002
func (m *MockDependencyCompiler) Compile(arg0 []job.Job, arg1 ui.Stage) ([]job0.CompiledPackageRef, error) {
	ret := m.ctrl.Call(m, "Compile", arg0, arg1)
	ret0, _ := ret[0].([]job0.CompiledPackageRef)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}