-
-
Save dennwc/8d6a69db88cf89438541a49a26e81ad6 to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"github.com/bblfsh/sdk/protocol" | |
"google.golang.org/grpc" | |
"context" | |
"os" | |
"flag" | |
"io/ioutil" | |
"log" | |
"time" | |
"fmt" | |
) | |
func checkErr(err error) { | |
if err != nil { | |
panic(err) | |
} | |
} | |
var ( | |
f_lang = flag.String("lang", "", "programming language") | |
) | |
func main() { | |
flag.Parse() | |
if flag.NArg() == 0 { | |
log.Println("no files specified") | |
os.Exit(1) | |
} | |
cc, err := grpc.Dial("localhost:9432", grpc.WithInsecure()) | |
checkErr(err) | |
defer cc.Close() | |
cli := protocol.NewProtocolServiceClient(cc) | |
ctx := context.TODO() | |
for _, arg := range flag.Args() { | |
log.Println("processing", arg) | |
data, err := ioutil.ReadFile(arg) | |
checkErr(err) | |
cctx, cancel := context.WithTimeout(ctx, time.Second*10) | |
res, err := cli.ParseUAST(cctx, &protocol.ParseUASTRequest{ | |
Filename:arg, | |
Language: *f_lang, | |
Content: string(data), | |
}) | |
select { | |
case <-cctx.Done(): | |
log.Println("timeout on", arg) | |
continue | |
default: | |
cancel() | |
checkErr(err) | |
if res.Status != protocol.Ok { | |
checkErr(fmt.Errorf("status: %v: %v", res.Status, res.Errors)) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment