forked from influxdata/flux
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcompiler.go
40 lines (32 loc) · 871 Bytes
/
compiler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package repl
import (
"context"
"github.com/InfluxCommunity/flux"
"github.com/InfluxCommunity/flux/internal/operation"
"github.com/InfluxCommunity/flux/lang"
"github.com/InfluxCommunity/flux/plan"
)
// CompilerType specific to the Flux REPL
const CompilerType = "REPL"
// Compiler specific to the Flux REPL
type Compiler struct {
Spec *operation.Spec `json:"spec"`
}
func (c Compiler) Compile(ctx context.Context, runtime flux.Runtime) (flux.Program, error) {
planner := plan.PlannerBuilder{}.Build()
ps, err := planner.Plan(ctx, c.Spec)
if err != nil {
return nil, err
}
return &lang.Program{
PlanSpec: ps,
}, err
}
func (c Compiler) CompilerType() flux.CompilerType {
return CompilerType
}
func AddCompilerToMappings(mappings flux.CompilerMappings) error {
return mappings.Add(CompilerType, func() flux.Compiler {
return new(Compiler)
})
}