-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
52 lines (46 loc) · 937 Bytes
/
helper.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
package main
import (
"fmt"
"go/format"
"log"
"strings"
"go.nickng.io/asyncpi"
"golang.org/x/tools/imports"
)
func mustParse(s string) asyncpi.Process {
proc, err := asyncpi.Parse(strings.NewReader(s))
if err != nil {
log.Fatal("parse failed:", err)
}
return proc
}
func reduceAll(proc asyncpi.Process) asyncpi.Process {
for {
changed, err := asyncpi.Reduce1(proc)
if err != nil {
log.Fatal("reduction error", err) // handle errors
break
}
if !changed {
break
}
proc, _ = asyncpi.SimplifyBySC(proc)
fmt.Println("→ Reduces to:", proc.Calculi())
}
return proc
}
func fixImports(src []byte) []byte {
opts := &imports.Options{TabIndent: true, Fragment: false}
imported, err := imports.Process("/tmp/main.go", src, opts)
if err != nil {
log.Fatal(err)
}
return imported
}
func goFmt(src []byte) []byte {
fmtd, err := format.Source(src)
if err != nil {
log.Fatal(err)
}
return fmtd
}