-
Notifications
You must be signed in to change notification settings - Fork 33
/
interpreter.go
69 lines (58 loc) · 1.31 KB
/
interpreter.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
package main
import (
"sync"
"github.com/hashicorp/go-multierror"
"github.com/nokia/ntt/interpreter"
"github.com/nokia/ntt/runtime"
"github.com/nokia/ntt/ttcn3"
)
func interpret(args []string) error {
files, err := parse(args...)
if err != nil {
return err
}
if err := check(files...); err != nil {
return err
}
env := runtime.NewEnv(nil)
if err := load(env, files...); err != nil {
return err
}
// TODO(5nord) execute all control parts
return nil
}
// parse TTCN-3 files and return a list of syntax trees.
func parse(files ...string) ([]*ttcn3.Tree, error) {
result := make([]*ttcn3.Tree, len(files))
var wg sync.WaitGroup
wg.Add(len(files))
for i, file := range files {
go func(i int, file string) {
defer wg.Done()
result[i] = ttcn3.ParseFile(file)
}(i, file)
}
wg.Wait()
// collect all syntax errors
var err error
for _, file := range result {
if file.Err != nil {
err = multierror.Append(err, file.Err)
}
}
return result, err
}
func check(files ...*ttcn3.Tree) error {
return nil
}
// load TTCN-3 files by executing them.
func load(env *runtime.Env, files ...*ttcn3.Tree) error {
var err error
for _, file := range files {
result := interpreter.Eval(file.Root, env)
if rerr, ok := result.(*runtime.Error); ok {
err = multierror.Append(err, rerr)
}
}
return err
}