-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnumscript.go
81 lines (61 loc) · 2.06 KB
/
numscript.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package numscript
import (
"context"
"github.com/formancehq/numscript/internal/interpreter"
"github.com/formancehq/numscript/internal/parser"
)
// This struct represents a parsed numscript source code
type ParseResult struct {
parseResult parser.ParseResult
}
// ---- TODO useful for the playground
// func (*ParseResult) GetNeededVariables() map[string]ValueType {}
// func (*ParseResult) GetDiagnostics() []Diagnostic {}
type ParserError = parser.ParserError
func Parse(code string) ParseResult {
return ParseResult{parseResult: parser.Parse(code)}
}
var ParseErrorsToString = parser.ParseErrorsToString
func (p ParseResult) GetParsingErrors() []ParserError {
return p.parseResult.Errors
}
type (
VariablesMap = interpreter.VariablesMap
Posting = interpreter.Posting
ExecutionResult = interpreter.ExecutionResult
// For each account, list of the needed assets
BalanceQuery = interpreter.BalanceQuery
MetadataQuery = interpreter.MetadataQuery
AccountBalance = interpreter.AccountBalance
Balances = interpreter.Balances
AccountMetadata = interpreter.AccountMetadata
// The newly defined account metadata after the execution
AccountsMetadata = interpreter.AccountsMetadata
// The transaction metadata, set by set_tx_meta()
Metadata = interpreter.Metadata
Store = interpreter.Store
StaticStore = interpreter.StaticStore
Value = interpreter.Value
InterpreterError = interpreter.InterpreterError
)
func (p ParseResult) Run(ctx context.Context, vars VariablesMap, store Store) (ExecutionResult, InterpreterError) {
return p.RunWithFeatureFlags(ctx, vars, store, nil)
}
func (p ParseResult) RunWithFeatureFlags(
ctx context.Context,
vars VariablesMap,
store Store,
featureFlags map[string]struct{},
) (ExecutionResult, InterpreterError) {
if featureFlags == nil {
featureFlags = make(map[string]struct{})
}
res, err := interpreter.RunProgram(ctx, p.parseResult.Value, vars, store, featureFlags)
if err != nil {
return ExecutionResult{}, err
}
return *res, nil
}
func (p ParseResult) GetSource() string {
return p.parseResult.Source
}