-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
980 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,7 @@ gpeg | |
*.svg | ||
*.dat | ||
*.so | ||
/benchmarks/apply | ||
/benchmarks/apply_gpeg | ||
/benchmarks/fullparse | ||
/benchmarks/reparse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"io/fs" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
var dir = flag.String("dir", "", "dir to apply command to") | ||
var suffix = flag.String("suffix", "", "file suffix") | ||
|
||
const cutoff = 100000 | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
target := flag.Args()[0] | ||
|
||
err := filepath.Walk(*dir, func(path string, info fs.FileInfo, err error) error { | ||
if err != nil { | ||
fmt.Printf("prevent panic by handling failure accessing a path %q: %v\n", path, err) | ||
return err | ||
} | ||
if !info.IsDir() && strings.HasSuffix(info.Name(), *suffix) && info.Size() >= cutoff { | ||
args := []string{path} | ||
cmd := exec.Command(target, args...) | ||
cmd.Stdout = os.Stdout | ||
cmd.Run() | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"flag" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"math/rand" | ||
"time" | ||
|
||
"github.com/zyedidia/gpeg/memo" | ||
"github.com/zyedidia/gpeg/pattern" | ||
"github.com/zyedidia/gpeg/re" | ||
"github.com/zyedidia/gpeg/vm" | ||
) | ||
|
||
var grammar = flag.String("grammar", "../grammars/json_memo.peg", "grammar to use") | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
inputs := flag.Args() | ||
|
||
peg, err := ioutil.ReadFile(*grammar) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
p := re.MustCompilePatt(string(peg)) | ||
prog := pattern.MustCompile(p) | ||
code := vm.Encode(prog) | ||
|
||
for _, input := range inputs { | ||
data, err := ioutil.ReadFile(input) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
in := bytes.NewReader(data) | ||
|
||
tbl := memo.NewTreeTable(512) | ||
for i := 0; i < 1; i++ { | ||
code.Exec(in, tbl) | ||
loc := rand.Intn(len(data)) | ||
edit := memo.Edit{ | ||
Start: loc, | ||
End: loc + 1, | ||
Len: 1, | ||
} | ||
in.Reset(data) | ||
|
||
tstart := time.Now() | ||
tbl.ApplyEdit(edit) | ||
code.Exec(in, tbl) | ||
fmt.Println(len(data), time.Since(tstart).Microseconds()) | ||
} | ||
// f, err := os.Create("out.svg") | ||
// if err != nil { | ||
// log.Fatal(err) | ||
// } | ||
// defer f.Close() | ||
// viz.DrawMemo(tbl, len(data), f, 1000, 2000) | ||
} | ||
// fmt.Println("elapsed:", time.Since(tstart)) | ||
// fmt.Printf("match: %t, n: %d, len(ast): %d\n", match, n, len(ast)) | ||
// fmt.Printf("table entries: %d\n", tbl.Size()) | ||
} |
Oops, something went wrong.