示例#1
0
func main() {
	flag.Parse()

	var filename string
	switch flag.NArg() {
	case 0:
		filename = "/dev/stdin"
	case 1:
		filename = flag.Arg(0)
	default:
		usage()
	}

	src, err := ioutil.ReadFile(filename)
	if err != nil {
		scanner.PrintError(os.Stderr, err)
	}

	if path.Ext(filename) == ".html" {
		src = extractEBNF(src)
	}

	grammar, err := ebnf.Parse(filename, src)
	if err != nil {
		scanner.PrintError(os.Stderr, err)
	}

	if err = ebnf.Verify(grammar, *start); err != nil {
		scanner.PrintError(os.Stderr, err)
	}
}
示例#2
0
文件: ebnflint.go 项目: WXB506/golang
func main() {
	flag.Parse()

	var (
		filename string
		src      []byte
		err      os.Error
	)
	switch flag.NArg() {
	case 0:
		filename = "<stdin>"
		src, err = ioutil.ReadAll(os.Stdin)
	case 1:
		filename = flag.Arg(0)
		src, err = ioutil.ReadFile(filename)
	default:
		usage()
	}
	if err != nil {
		report(err)
	}

	if filepath.Ext(filename) == ".html" || bytes.Index(src, open) >= 0 {
		src = extractEBNF(src)
	}

	grammar, err := ebnf.Parse(fset, filename, src)
	if err != nil {
		report(err)
	}

	if err = ebnf.Verify(fset, grammar, *start); err != nil {
		report(err)
	}
}
示例#3
0
func main() {
	file, err := os.Open("full_irc.ebnf.go", os.O_RDONLY, 0666)
	if err != nil {
		log.Exit("Error: ", err)
	}
	reader := bufio.NewReader(file)
	src, err := reader.ReadBytes('\x00')
	if err != nil {
		log.Stdout("Reading stopped: ", err)
	}
	// Read in the grammar
	//log.Stdoutf("%s", src);
	grammar, err := ebnf.Parse("", src)
	if err != nil {
		log.Exit("Parse Error: ", err)
	}
	// Verify the grammar
	err = ebnf.Verify(grammar, "message")
	if err != nil {
		log.Exit("Verification Error: ", err)
	}
	log.Stdout("Success")
}