Ai
3 Star 0 Fork 0

mirrors_go-python/gpython

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
testparser.go 1.52 KB
一键复制 编辑 原始数据 按行查看 历史
Nick Craig-Wood 提交于 2018-08-22 03:56 +08:00 . Add copyright headers to all files
// Copyright 2018 The go-python Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"github.com/go-python/gpython/compile"
"github.com/go-python/gpython/parser"
)
var (
lexFile = flag.Bool("l", false, "Lex the file only")
compileFile = flag.Bool("c", false, "Lex, Parse and compile the file")
debugLevel = flag.Int("d", 0, "Debug level 0-4")
)
func main() {
flag.Parse()
parser.SetDebug(*debugLevel)
if len(flag.Args()) == 0 {
log.Printf("Need files to parse")
os.Exit(1)
}
for _, path := range flag.Args() {
if *lexFile {
fmt.Printf("Lexing %q\n", path)
} else if *compileFile {
fmt.Printf("Compiling %q\n", path)
} else {
fmt.Printf("Parsing %q\n", path)
}
in, err := os.Open(path)
if err != nil {
log.Fatal(err)
}
if *debugLevel > 0 {
fmt.Printf("-----------------\n")
}
if *lexFile {
_, err = parser.Lex(in, path, "exec")
} else if *compileFile {
var input []byte
input, err = ioutil.ReadAll(in)
if err != nil {
log.Fatalf("Failed to read %q: %v", path, err)
}
_, err = compile.Compile(string(input), path, "exec", 0, false)
} else {
_, err = parser.Parse(in, path, "exec")
}
if *debugLevel > 0 {
fmt.Printf("-----------------\n")
}
closeErr := in.Close()
if err != nil {
log.Fatalf("Failed on %q: %v", path, err)
}
if closeErr != nil {
log.Fatalf("Failed to close %q: %v", path, closeErr)
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_go-python/gpython.git
git@gitee.com:mirrors_go-python/gpython.git
mirrors_go-python
gpython
gpython
v0.0.2

搜索帮助